use structopt::StructOpt;
use std::path::PathBuf;
use std::num::ParseFloatError;
use std::str::FromStr;
fn parse_measurement(input: &str) -> Result<f64, ParseFloatError> {
f64::from_str(input)
}
#[derive(StructOpt)]
pub enum Command {
#[structopt(name = "add")]
AddMeasurement {
#[structopt(short = "s", long = "series")]
series: String,
#[structopt(parse(try_from_str = "parse_measurement"))]
value: Option<f64>,
#[structopt(short = "c")]
create: bool
},
#[structopt(name = "bulk")]
AddBulk {
#[structopt(short = "c")]
create: bool
},
#[structopt(name = "add-series")]
AddSeries {
#[structopt(short = "n", long = "name")]
name: Option<String>,
#[structopt(short = "u", long = "unit")]
unit: Option<String>
},
#[structopt(name = "delete-series")]
DeleteSeries {
#[structopt(short = "s", long = "series")]
series: Option<String>
},
#[structopt(name = "plot")]
Plot {
#[structopt(short = "s", long = "series")]
series: Option<String>,
#[structopt(short = "p", default_value = "50")]
points: u8,
#[structopt(short = "t", long = "table")]
table: bool,
}
}
#[derive(StructOpt)]
#[structopt(name = "trk", about = "Simple CLI-based metric tracker and plotter")]
pub struct Config {
#[structopt(short = "d", long = "data-root", parse(from_os_str))]
pub data_root: Option<PathBuf>,
#[structopt(short = "f", long = "data-file", default_value = "default", parse(from_os_str))]
pub file: PathBuf,
#[structopt(short = "l", long = "log", parse(from_os_str))]
pub log_file: Option<PathBuf>,
#[structopt(subcommand)]
pub subcmd: Command
}
pub fn init() -> Config {
Config::from_args()
}