Skip to content

Commit

Permalink
Merge pull request #3751 from mulkieran/make-unsupported-cmds-invisib…
Browse files Browse the repository at this point in the history
…le-in-help

Show only officially supported commands in help text
  • Loading branch information
mulkieran authored Jan 31, 2025
2 parents fe19def + fecba7d commit 2fdcc07
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/bin/stratisd-tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,22 @@ fn main() {
Arg::new("executable")
.required(true)
.value_name("EXECUTABLE")
.value_parser(cmds().iter().map(|x| x.name()).collect::<Vec<_>>()),
.value_parser(cmds().iter().map(|x| x.name()).collect::<Vec<_>>())
.hide_possible_values(true),
)
.arg_required_else_help(true);
.arg_required_else_help(true)
.after_help(format!(
"Executables:\n{}",
cmds()
.iter()
.filter_map(|x| if x.show_in_after_help() {
Some(format!("* {}", x.name()))
} else {
None
})
.collect::<Vec<_>>()
.join("\n")
));

let truncated_args = if args.len() > 1 {
vec![argv1, &args[1]]
Expand Down
13 changes: 13 additions & 0 deletions src/bin/tools/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use stratisd::stratis::VERSION;
pub trait ToolCommand<'a> {
fn name(&self) -> &'a str;
fn run(&self, command_line_args: Vec<String>) -> Result<(), String>;
fn show_in_after_help(&self) -> bool;
}

struct StratisDumpMetadata;
Expand Down Expand Up @@ -68,6 +69,10 @@ impl<'a> ToolCommand<'a> for StratisDumpMetadata {
.unwrap_or(false),
)
}

fn show_in_after_help(&self) -> bool {
true
}
}

struct StratisCheckMetadata;
Expand Down Expand Up @@ -100,6 +105,10 @@ impl<'a> ToolCommand<'a> for StratisCheckMetadata {

check_metadata::run(infile, false)
}

fn show_in_after_help(&self) -> bool {
false
}
}

struct StratisPrintMetadata;
Expand Down Expand Up @@ -132,6 +141,10 @@ impl<'a> ToolCommand<'a> for StratisPrintMetadata {

check_metadata::run(infile, true)
}

fn show_in_after_help(&self) -> bool {
false
}
}

pub fn cmds<'a>() -> Vec<Box<dyn ToolCommand<'a>>> {
Expand Down

0 comments on commit 2fdcc07

Please sign in to comment.