From ccea2ad0c8a6d9c4a20f5c8fa88dbbf848d20331 Mon Sep 17 00:00:00 2001 From: David Gilligan-Cook Date: Mon, 13 Jan 2025 15:26:02 -0800 Subject: [PATCH] Adds --no-src and --src options to spk ls and spk search. These options exclude, or include respectively, the /src builds when considering packages, versions, and builds for listings or searches. The --host option enables --no-src by default. This can be overridden by using --src. Signed-off-by: David Gilligan-Cook --- crates/spk-cli/group2/src/cmd_ls.rs | 38 ++++++++++++++++++++++++- crates/spk-cli/group4/src/cmd_search.rs | 29 ++++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/crates/spk-cli/group2/src/cmd_ls.rs b/crates/spk-cli/group2/src/cmd_ls.rs index 19ab258a0..bff5432ab 100644 --- a/crates/spk-cli/group2/src/cmd_ls.rs +++ b/crates/spk-cli/group2/src/cmd_ls.rs @@ -75,10 +75,22 @@ pub struct Ls { /// Enable filtering to only show items that have a build that /// matches the current host's host options. This option can be - /// configured as the default in spk's config file. + /// configured as the default in spk's config file. Enables + /// --no-src by default. #[clap(long)] host: bool, + /// Disable showing items that have any matching build and only + /// show items with a non-src build that matches the current + /// host's host options. Using --host will enable this by default. + #[clap(long, conflicts_with = "src")] + no_src: bool, + + /// Enable filtering to show items that have any build, including + /// src ones, that match the current host's host options. + #[clap(long)] + src: bool, + /// Given a name, list versions. Given a name/version list builds. /// /// If nothing is provided, list all available packages. @@ -106,6 +118,11 @@ impl Run for Ls { // Set the default filter to the all current host's host // options (--host). --no-host will disable this. let filter_by = if !self.no_host && self.host { + // Using --host enables --no-src by default. But using + // --src overrides that. + if !self.src { + self.no_src = true; + } get_host_options_filters() } else { None @@ -183,6 +200,10 @@ impl Run for Ls { let mut any_deprecated = false; let mut any_not_deprecated = false; while let Some(build) = builds.pop() { + if self.no_src && build.is_source() { + // Filter out source builds + continue; + } match repo.read_package(&build).await { Ok(spec) => { if !spec.matches_all_filters(&filter_by) { @@ -244,6 +265,11 @@ impl Run for Ls { let pkg = parse_ident(package)?; for (_, repo) in repos { for build in repo.list_package_builds(pkg.as_version_ident()).await? { + if self.no_src && build.is_source() { + // Filter out source builds + continue; + } + // Doing this here slows the listing down, but // the spec file is the only place that holds // the deprecation status. @@ -364,6 +390,11 @@ impl Ls { } } + if self.no_src && build.is_source() { + // Filter out source builds + continue; + } + // Doing this here slows the listing down, but // the spec file is the only place that holds // the deprecation status. @@ -432,6 +463,11 @@ impl Ls { for pkg in versions { let mut found_a_match = false; for build in repo.list_package_builds(pkg.as_version_ident()).await? { + if self.no_src && build.is_source() { + // Filter out source builds + continue; + } + let spec = match repo.read_package(&build).await { Ok(spec) => spec, Err(err) => { diff --git a/crates/spk-cli/group4/src/cmd_search.rs b/crates/spk-cli/group4/src/cmd_search.rs index fe4e69d32..bbaf2f45c 100644 --- a/crates/spk-cli/group4/src/cmd_search.rs +++ b/crates/spk-cli/group4/src/cmd_search.rs @@ -31,10 +31,22 @@ pub struct Search { /// Enable filtering to only show items that have a build that /// matches the current host's host options. This option can be - /// configured as the default in spk's config file. + /// configured as the default in spk's config file. Enables + /// --no-src by default. #[clap(long)] host: bool, + /// Disable showing items that have any matching build and only + /// show items with a non-src build that matches the current + /// host's host options. Using --host will enable this by default. + #[clap(long, conflicts_with = "src")] + no_src: bool, + + /// Enable filtering to show items that have any build, including + /// src ones, that match the current host's host options. + #[clap(long)] + src: bool, + /// The text/substring to search for in package names term: String, } @@ -56,6 +68,11 @@ impl Run for Search { // Set the default filter to the all current host's host // options (--host). --no-host will disable this. let filter_by = if !self.no_host && self.host { + // Using --host enables --no-src by default. But using + // --src overrides that. + if !self.src { + self.no_src = true; + } get_host_options_filters() } else { None @@ -98,6 +115,11 @@ impl Run for Search { // there's one that matches the filters let mut has_a_build_that_matches_the_filter = false; for build in builds { + if self.no_src && build.is_source() { + // Filter out source builds + continue; + } + if let Ok(spec) = repo.read_package(&build).await { if spec.matches_all_filters(&filter_by) { has_a_build_that_matches_the_filter = true; @@ -119,6 +141,11 @@ impl Run for Search { // that only exists as embedded builds. let mut all_builds_deprecated = true; for build in builds { + if self.no_src && build.is_source() { + // Filter out source builds + continue; + } + if let Ok(spec) = repo.read_package(&build).await { if !spec.is_deprecated() { if !spec.matches_all_filters(&filter_by) {