From 00fcdf1031a0ec0b1e5596489cd300429e2f6bde Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Mon, 22 Mar 2021 20:54:28 +0100 Subject: [PATCH] Replace StructOpt with argh for comp.time+space --- multigrid/Cargo.toml | 2 +- multigrid/src/main.rs | 44 ++++++++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/multigrid/Cargo.toml b/multigrid/Cargo.toml index 7657769..238ad7c 100644 --- a/multigrid/Cargo.toml +++ b/multigrid/Cargo.toml @@ -12,8 +12,8 @@ hdf5 = "0.7.0" integrate = { path = "../utils/integrate" } rayon = "1.3.0" indicatif = "0.15.0" -structopt = "0.3.14" ndarray = { version = "0.14.0", features = ["serde"] } serde = { version = "1.0.115", features = ["derive"] } json5 = "0.3.0" indexmap = { version = "1.5.2", features = ["serde-1"] } +argh = "0.1.4" diff --git a/multigrid/src/main.rs b/multigrid/src/main.rs index f364dff..7ca25a3 100644 --- a/multigrid/src/main.rs +++ b/multigrid/src/main.rs @@ -1,5 +1,5 @@ +use argh::FromArgs; use rayon::prelude::*; -use structopt::StructOpt; use sbp::operators::SbpOperator2d; use sbp::*; @@ -180,30 +180,36 @@ impl System { } } -#[derive(Debug, StructOpt)] -struct Options { +#[derive(Debug, FromArgs)] +/// Options for configuring and running the solver +struct CliOptions { + #[argh(positional)] json: std::path::PathBuf, - /// Disable the progressbar - #[structopt(long)] - no_progressbar: bool, - /// Number of simultaneous threads - #[structopt(short, long)] + /// number of simultaneous threads + #[argh(option, short = 'j')] jobs: Option, - /// Name of output file - #[structopt(default_value = "output.hdf", long, short)] + /// name of output file + #[argh( + option, + short = 'o', + default = "std::path::PathBuf::from(\"output.hdf\")" + )] output: std::path::PathBuf, - /// Number of outputs to save - #[structopt(long, short)] + /// number of outputs to save + #[argh(option, short = 'n')] number_of_outputs: Option, - /// Print the time to complete, taken in the compute loop - #[structopt(long)] + /// print the time to complete, taken in the compute loop + #[argh(switch)] timings: bool, - /// Print error at the end of the run - #[structopt(long)] + /// print error at the end of the run + #[argh(switch)] error: bool, - /// Output information regarding time elapsed and error + /// disable the progressbar + #[argh(switch)] + no_progressbar: bool, + /// output information regarding time elapsed and error /// in json format - #[structopt(long)] + #[argh(switch)] output_json: bool, } @@ -217,7 +223,7 @@ struct OutputInformation { } fn main() { - let opt = Options::from_args(); + let opt: CliOptions = argh::from_env(); let filecontents = std::fs::read_to_string(&opt.json).unwrap(); let config: parsing::Configuration = match json5::from_str(&filecontents) {