Skip to content

Commit

Permalink
fix: CLI sub-command is not optional. (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
jetuk authored Oct 18, 2024
1 parent 0c16cd0 commit 9078856
Showing 1 changed file with 31 additions and 34 deletions.
65 changes: 31 additions & 34 deletions pywr-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct Cli {
#[arg(long, default_value_t = false)]
debug: bool,
#[command(subcommand)]
command: Option<Commands>,
command: Commands,
}

#[derive(Subcommand)]
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit 9078856

Please sign in to comment.