Skip to content

Commit

Permalink
Allow passing ALL as the last argument to a partial command to instal…
Browse files Browse the repository at this point in the history
…l all matching modules
  • Loading branch information
Pencilcaseman committed Oct 20, 2024
1 parent 1a04c04 commit 32cd496
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "sccmod"
authors = ["Toby Davis \"Pencilcaseman\""]
version = "0.6.0"
version = "0.6.1"
edition = "2021"
readme = "README.md"
license = "MIT OR Apache-2.0"
Expand Down
3 changes: 3 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use_small_heuristics = "Max"
max_width = 80

comment_width = 80
wrap_comments = true

unstable_features = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
11 changes: 10 additions & 1 deletion src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ pub fn resolver_boilerplate(
}
}

selection.clear(); // Clear the input buffer for the next iteration
selection.clear(); // Clear the input buffer for the next
// iteration
}

if all {
Expand All @@ -104,6 +105,14 @@ pub fn resolver_boilerplate(
module_resolver::ResolveMatch::None => {
log::error("No modules match the partials provided");
}

module_resolver::ResolveMatch::All(m) => {
for module in &m {
func(module)?;
}

Ok(())
}
}
}

Expand Down
15 changes: 14 additions & 1 deletion src/module_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
pub enum ResolveMatch {
Full(Module),
Partial(Vec<Module>),
All(Vec<Module>),
None,
}

Expand All @@ -16,6 +17,17 @@ pub enum ResolveMatch {
/// # Errors
/// Will error if the modules cannot be listed.
pub fn resolve(partials: &[&str]) -> Result<ResolveMatch, String> {
// Allow passing `ALL` as the last argument to install all matching
// modules

let mut partials = partials.to_vec();
let mut all = false;
if partials[partials.len() - 1] == "ALL" {
// Remove `--all` from the list of partials
partials.pop();
all = true;
}

let mut results: Vec<Module> = get_modules()?
.into_iter()
.filter(|module| {
Expand All @@ -34,6 +46,7 @@ pub fn resolve(partials: &[&str]) -> Result<ResolveMatch, String> {
|| log::error("An internal error has occurred"),
|x| x,
))),
_ => Ok(ResolveMatch::Partial(results)),
_ if !all => Ok(ResolveMatch::Partial(results)),
_ => Ok(ResolveMatch::All(results)),
}
}

0 comments on commit 32cd496

Please sign in to comment.