add optional command_name config option
This commit is contained in:
parent
9f9deb107e
commit
40467ce13d
|
@ -17,6 +17,7 @@ pub fn get_command(bin_name: &str) -> (&str, Vec<&str>) {
|
|||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct ModuleConfig {
|
||||
name: String,
|
||||
command_name: Option<String>,
|
||||
derivation_prefix: String,
|
||||
}
|
||||
|
||||
|
@ -42,9 +43,9 @@ pub fn do_cli_thing() {
|
|||
let mut icepick_command = command!();
|
||||
// NOTE: this needs to be .cloned(), since commands is leaked to be 'static
|
||||
// and coin_bin otherwise wouldn't live long enough
|
||||
for coin_bin in config.modules.iter().map(|m| &m.name).cloned() {
|
||||
// try to run the "help" operation on any bins.
|
||||
let bin = format!("icepick-{coin_bin}");
|
||||
for module in &config.modules {
|
||||
let module_name = &module.name;
|
||||
let bin = module.command_name.clone().unwrap_or_else(|| format!("icepick-{module_name}"));
|
||||
let (command, args) = get_command(&bin);
|
||||
let mut child = Command::new(command)
|
||||
.args(args)
|
||||
|
@ -62,12 +63,12 @@ pub fn do_cli_thing() {
|
|||
let output = child.wait_with_output().unwrap().stdout;
|
||||
let operations: Vec<Operation> = serde_json::from_slice::<Vec<Operation>>(&output)
|
||||
.expect("successful deserialization of operation");
|
||||
commands.push((coin_bin, operations));
|
||||
commands.push((module_name.clone(), bin, operations));
|
||||
}
|
||||
let commands = commands.leak();
|
||||
for command in commands.iter() {
|
||||
let mut subcommand = clap::Command::new(command.0.as_str());
|
||||
for op in &command.1 {
|
||||
for op in &command.2 {
|
||||
let mut op_command = clap::Command::new(&op.name).about(&op.description);
|
||||
for arg in &op.arguments {
|
||||
let mut op_arg = clap::Arg::new(&arg.name).help(arg.description.as_str());
|
||||
|
@ -97,8 +98,8 @@ pub fn do_cli_thing() {
|
|||
if let Some((subcommand, matches)) = matches.subcommand() {
|
||||
if let Some(operation) = commands
|
||||
.iter()
|
||||
.find(|(name, _)| *name == module)
|
||||
.and_then(|(_, operations)| operations.iter().find(|o| o.name == subcommand))
|
||||
.find(|(name, ..)| *name == module)
|
||||
.and_then(|(.., operations)| operations.iter().find(|o| o.name == subcommand))
|
||||
{
|
||||
let mut args = std::collections::HashMap::<&String, Option<&String>>::with_capacity(
|
||||
operation.arguments.len(),
|
||||
|
@ -112,8 +113,14 @@ pub fn do_cli_thing() {
|
|||
"derived-keys": [],
|
||||
"blob": blob,
|
||||
});
|
||||
let bin = format!("icepick-{module}");
|
||||
let (command, args) = get_command(&bin);
|
||||
let bin = commands.iter().find_map(|(fmodule, fcommand, _)| {
|
||||
if fmodule == module {
|
||||
Some(fcommand)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).expect("previously found module should exist in new search");
|
||||
let (command, args) = get_command(bin);
|
||||
let mut child = Command::new(command)
|
||||
.args(args)
|
||||
.stdin(Stdio::piped())
|
||||
|
|
Loading…
Reference in New Issue