Skip to content

Commit

Permalink
chore(cli): Minor improvements in argument parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
sasa-tomic committed Jan 4, 2024
1 parent 159ce4f commit 74c85ef
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
23 changes: 4 additions & 19 deletions rs/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub(crate) mod subnet {
optimize: Option<usize>,

/// Motivation for replacing custom nodes
#[clap(short, long)]
#[clap(short, long, aliases = ["summary"])]
motivation: Option<String>,

/// Minimum Nakamoto coefficients after the replacement
Expand All @@ -154,11 +154,6 @@ pub(crate) mod subnet {
/// regardless of the decentralization score
#[clap(long, num_args(1..))]
include: Vec<PrincipalId>,

/// More verbose execution. For instance, print logs from the
/// backend.
#[clap(long)]
verbose: bool,
},

/// Resize the subnet
Expand All @@ -185,13 +180,8 @@ pub(crate) mod subnet {
include: Vec<PrincipalId>,

/// Motivation for resing the subnet
#[clap(short, long)]
#[clap(short, long, aliases = ["summary"])]
motivation: Option<String>,

/// More verbose execution. For instance, print logs from the
/// backend.
#[clap(long)]
verbose: bool,
},

/// Create a new subnet
Expand All @@ -218,14 +208,9 @@ pub(crate) mod subnet {
include: Vec<PrincipalId>,

/// Motivation for creating the subnet
#[clap(short, long)]
#[clap(short, long, aliases = ["summary"])]
motivation: Option<String>,

/// More verbose execution. For instance, print logs from the
/// backend.
#[clap(long)]
verbose: bool,

#[clap(long)]
replica_version: Option<String>,
},
Expand Down Expand Up @@ -280,7 +265,7 @@ pub(crate) mod nodes {
exclude: Vec<String>,

/// Motivation for removing additional nodes
#[clap(long)]
#[clap(long, aliases = ["summary"])]
motivation: Option<String>,
},
}
Expand Down
16 changes: 16 additions & 0 deletions rs/cli/src/ic_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,22 @@ impl IcAdminWrapper {
args_with_fixed_prefix
};

// ic-admin expects --summary and not --motivation
// make sure the expected argument is provided
let args = if !args.contains(&String::from("--summary")) && args.contains(&String::from("--motivation")) {
args.iter()
.map(|arg| {
if arg == "--motivation" {
"--summary".to_string()
} else {
arg.clone()
}
})
.collect::<Vec<_>>()
} else {
args.to_vec()
};

let cmd = ProposeCommand::Raw {
command: args[0].clone(),
args: args.iter().skip(1).cloned().collect::<Vec<_>>(),
Expand Down
11 changes: 5 additions & 6 deletions rs/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ async fn main() -> Result<(), anyhow::Error> {
only,
include,
min_nakamoto_coefficients,
verbose,
} => {
let min_nakamoto_coefficients = parse_min_nakamoto_coefficients(&mut cmd, min_nakamoto_coefficients);
let runner = runner::Runner::new_with_network_url(cli::Cli::from_opts(&cli_opts, true).await?.into(), backend_port).await?;
Expand Down Expand Up @@ -142,10 +141,10 @@ async fn main() -> Result<(), anyhow::Error> {
only: only.clone(),
include: include.clone().into(),
min_nakamoto_coefficients,
}, *verbose, simulate)
}, cli_opts.verbose, simulate)
.await
}
cli::subnet::Commands::Resize { add, remove, include, only, exclude, motivation, verbose, } => {
cli::subnet::Commands::Resize { add, remove, include, only, exclude, motivation, } => {
if let Some(motivation) = motivation.clone() {
let runner = runner::Runner::new_with_network_url(cli::Cli::from_opts(&cli_opts, true).await?.into(), backend_port).await?;
runner.subnet_resize(ic_management_types::requests::SubnetResizeRequest {
Expand All @@ -155,7 +154,7 @@ async fn main() -> Result<(), anyhow::Error> {
only: only.clone().into(),
exclude: exclude.clone().into(),
include: include.clone().into(),
}, motivation, *verbose, simulate).await
}, motivation, cli_opts.verbose, simulate).await
} else {
cmd.error(
ErrorKind::MissingRequiredArgument,
Expand All @@ -164,7 +163,7 @@ async fn main() -> Result<(), anyhow::Error> {
.exit();
}
}
cli::subnet::Commands::Create { size, min_nakamoto_coefficients, exclude, only, include, motivation, verbose, replica_version } => {
cli::subnet::Commands::Create { size, min_nakamoto_coefficients, exclude, only, include, motivation, replica_version } => {
let min_nakamoto_coefficients = parse_min_nakamoto_coefficients(&mut cmd, min_nakamoto_coefficients);
if let Some(motivation) = motivation.clone() {
let runner = runner::Runner::new_with_network_url(cli::Cli::from_opts(&cli_opts, true).await?.into(), backend_port).await?;
Expand All @@ -174,7 +173,7 @@ async fn main() -> Result<(), anyhow::Error> {
only: only.clone().into(),
exclude: exclude.clone().into(),
include: include.clone().into(),
}, motivation, *verbose, simulate, replica_version.clone()).await
}, motivation, cli_opts.verbose, simulate, replica_version.clone()).await
} else {
cmd.error(
ErrorKind::MissingRequiredArgument,
Expand Down

0 comments on commit 74c85ef

Please sign in to comment.