Replace StructOpt with argh for comp.time+space

This commit is contained in:
Magnus Ulimoen 2021-03-22 20:54:28 +01:00
parent ff9a477b67
commit 00fcdf1031
2 changed files with 26 additions and 20 deletions

View File

@ -12,8 +12,8 @@ hdf5 = "0.7.0"
integrate = { path = "../utils/integrate" } integrate = { path = "../utils/integrate" }
rayon = "1.3.0" rayon = "1.3.0"
indicatif = "0.15.0" indicatif = "0.15.0"
structopt = "0.3.14"
ndarray = { version = "0.14.0", features = ["serde"] } ndarray = { version = "0.14.0", features = ["serde"] }
serde = { version = "1.0.115", features = ["derive"] } serde = { version = "1.0.115", features = ["derive"] }
json5 = "0.3.0" json5 = "0.3.0"
indexmap = { version = "1.5.2", features = ["serde-1"] } indexmap = { version = "1.5.2", features = ["serde-1"] }
argh = "0.1.4"

View File

@ -1,5 +1,5 @@
use argh::FromArgs;
use rayon::prelude::*; use rayon::prelude::*;
use structopt::StructOpt;
use sbp::operators::SbpOperator2d; use sbp::operators::SbpOperator2d;
use sbp::*; use sbp::*;
@ -180,30 +180,36 @@ impl System {
} }
} }
#[derive(Debug, StructOpt)] #[derive(Debug, FromArgs)]
struct Options { /// Options for configuring and running the solver
struct CliOptions {
#[argh(positional)]
json: std::path::PathBuf, json: std::path::PathBuf,
/// Disable the progressbar /// number of simultaneous threads
#[structopt(long)] #[argh(option, short = 'j')]
no_progressbar: bool,
/// Number of simultaneous threads
#[structopt(short, long)]
jobs: Option<usize>, jobs: Option<usize>,
/// Name of output file /// name of output file
#[structopt(default_value = "output.hdf", long, short)] #[argh(
option,
short = 'o',
default = "std::path::PathBuf::from(\"output.hdf\")"
)]
output: std::path::PathBuf, output: std::path::PathBuf,
/// Number of outputs to save /// number of outputs to save
#[structopt(long, short)] #[argh(option, short = 'n')]
number_of_outputs: Option<u64>, number_of_outputs: Option<u64>,
/// Print the time to complete, taken in the compute loop /// print the time to complete, taken in the compute loop
#[structopt(long)] #[argh(switch)]
timings: bool, timings: bool,
/// Print error at the end of the run /// print error at the end of the run
#[structopt(long)] #[argh(switch)]
error: bool, 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 /// in json format
#[structopt(long)] #[argh(switch)]
output_json: bool, output_json: bool,
} }
@ -217,7 +223,7 @@ struct OutputInformation {
} }
fn main() { fn main() {
let opt = Options::from_args(); let opt: CliOptions = argh::from_env();
let filecontents = std::fs::read_to_string(&opt.json).unwrap(); let filecontents = std::fs::read_to_string(&opt.json).unwrap();
let config: parsing::Configuration = match json5::from_str(&filecontents) { let config: parsing::Configuration = match json5::from_str(&filecontents) {