Skip to content

Commit

Permalink
feat(install): add flag to suppress install notes
Browse files Browse the repository at this point in the history
  • Loading branch information
QaidVoid committed Feb 8, 2025
1 parent 393df6a commit 8b4ae6f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
4 changes: 4 additions & 0 deletions soar-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ pub enum Commands {
/// Set portable config
#[arg(required = false, long, num_args = 0..=1, value_hint = ValueHint::AnyPath)]
portable_config: Option<Option<String>>,

/// Don't display notes
#[arg(required = false, long)]
no_notes: bool,
},

/// Search package
Expand Down
33 changes: 23 additions & 10 deletions soar-cli/src/install.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
collections::HashSet,
os::unix::fs,
path::PathBuf,
sync::{
Expand Down Expand Up @@ -49,6 +50,7 @@ pub struct InstallContext {
pub errors: Arc<Mutex<Vec<String>>>,
pub retrying: Arc<AtomicU64>,
pub failed: Arc<AtomicU64>,
pub installed_indices: Arc<Mutex<HashSet<usize>>>,
}

pub fn create_install_context(
Expand Down Expand Up @@ -76,6 +78,7 @@ pub fn create_install_context(
errors: Arc::new(Mutex::new(Vec::new())),
retrying: Arc::new(AtomicU64::new(0)),
failed: Arc::new(AtomicU64::new(0)),
installed_indices: Arc::new(Mutex::new(HashSet::new())),
}
}

Expand All @@ -86,6 +89,7 @@ pub async fn install_packages(
portable: Option<String>,
portable_home: Option<String>,
portable_config: Option<String>,
no_notes: bool,
) -> SoarResult<()> {
let state = AppState::new();
let repo_db = state.repo_db().await?;
Expand All @@ -101,7 +105,7 @@ pub async fn install_packages(
portable_config,
);

perform_installation(install_context, install_targets, core_db.clone()).await
perform_installation(install_context, install_targets, core_db.clone(), no_notes).await
}

fn resolve_packages(
Expand Down Expand Up @@ -249,6 +253,7 @@ pub async fn perform_installation(
ctx: InstallContext,
targets: Vec<InstallTarget>,
core_db: Arc<Mutex<Connection>>,
no_notes: bool,
) -> SoarResult<()> {
let mut handles = Vec::new();
let fixed_width = 40;
Expand Down Expand Up @@ -279,15 +284,21 @@ pub async fn perform_installation(
error!("{error}");
}

for target in targets {
let pkg = target.package;
let notes = pkg.notes.unwrap_or_default().join("\n ");
info!(
"\n* {}#{}\n {}\n",
pkg.pkg_name,
pkg.pkg_id,
if notes.is_empty() { "" } else { &notes }
);
if !no_notes {
let installed_indices = ctx.installed_indices.lock().unwrap();
for (idx, target) in targets.into_iter().enumerate() {
let pkg = target.package;
if !installed_indices.contains(&idx) || pkg.notes.is_none() {
continue;
}
let notes = pkg.notes.unwrap_or_default().join("\n ");
info!(
"\n* {}#{}\n {}\n",
pkg.pkg_name,
pkg.pkg_id,
if notes.is_empty() { "" } else { &notes }
);
}
}

info!(
Expand Down Expand Up @@ -323,6 +334,7 @@ async fn spawn_installation_task(

let total_pb = ctx.total_progress_bar.clone();
let installed_count = ctx.installed_count.clone();
let installed_indices = ctx.installed_indices.clone();
let ctx = ctx.clone();

tokio::spawn(async move {
Expand All @@ -341,6 +353,7 @@ async fn spawn_installation_task(
}
} else {
installed_count.fetch_add(1, Ordering::Relaxed);
installed_indices.lock().unwrap().insert(idx);
total_pb.inc(1);
}

Expand Down
2 changes: 2 additions & 0 deletions soar-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ async fn handle_cli() -> SoarResult<()> {
portable,
portable_home,
portable_config,
no_notes,
} => {
if portable.is_some() && (portable_home.is_some() || portable_config.is_some()) {
error!("--portable cannot be used with --portable-home or --portable-config");
Expand All @@ -97,6 +98,7 @@ async fn handle_cli() -> SoarResult<()> {
portable,
portable_home,
portable_config,
no_notes,
)
.await?;
}
Expand Down

0 comments on commit 8b4ae6f

Please sign in to comment.