From 9078856bf5854eea4e8a9cf99bd5f976ae05cc10 Mon Sep 17 00:00:00 2001 From: James Tomlinson Date: Fri, 18 Oct 2024 13:43:54 +0100 Subject: [PATCH] fix: CLI sub-command is not optional. (#272) --- pywr-cli/src/main.rs | 65 +++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/pywr-cli/src/main.rs b/pywr-cli/src/main.rs index ecdd25f8..a3eed48c 100644 --- a/pywr-cli/src/main.rs +++ b/pywr-cli/src/main.rs @@ -56,7 +56,7 @@ struct Cli { #[arg(long, default_value_t = false)] debug: bool, #[command(subcommand)] - command: Option, + command: Commands, } #[derive(Subcommand)] @@ -125,41 +125,38 @@ enum Commands { fn main() -> Result<()> { let cli = Cli::parse(); - setup_tracing(cli.debug).unwrap(); + setup_tracing(cli.debug)?; match &cli.command { - Some(command) => match command { - Commands::Convert { - input, - output, - stop_on_error, - network_only, - } => convert(input, output, *stop_on_error, *network_only)?, - Commands::Run { - model, - solver, - data_path, - output_path, - parallel: _, - threads: _, - } => run(model, solver, data_path.as_deref(), output_path.as_deref()), - Commands::RunMulti { - model, - solver, - data_path, - output_path, - parallel: _, - threads: _, - } => run_multi(model, solver, data_path.as_deref(), output_path.as_deref()), - Commands::RunRandom { - num_systems, - density, - num_scenarios, - solver, - } => run_random(*num_systems, *density, *num_scenarios, solver), - Commands::ExportSchema { out } => export_schema(out)?, - }, - None => {} + Commands::Convert { + input, + output, + stop_on_error, + network_only, + } => convert(input, output, *stop_on_error, *network_only)?, + Commands::Run { + model, + solver, + data_path, + output_path, + parallel: _, + threads: _, + } => run(model, solver, data_path.as_deref(), output_path.as_deref()), + Commands::RunMulti { + model, + solver, + data_path, + output_path, + parallel: _, + threads: _, + } => run_multi(model, solver, data_path.as_deref(), output_path.as_deref()), + Commands::RunRandom { + num_systems, + density, + num_scenarios, + solver, + } => run_random(*num_systems, *density, *num_scenarios, solver), + Commands::ExportSchema { out } => export_schema(out)?, } Ok(())