Make subcommand optional

This commit is contained in:
Sofia 2020-08-29 02:58:17 +03:00
parent 64742a0e21
commit bb87581ea5
3 changed files with 9 additions and 5 deletions

View File

@ -12,7 +12,7 @@ pub struct EnvOpt {
)]
pub config: PathBuf,
#[argh(subcommand)]
pub subcommand: Subcommand,
pub subcommand: Option<Subcommand>,
}
#[derive(FromArgs)]

View File

@ -6,7 +6,7 @@ use thingy_lib::chrono::NaiveDateTime;
use thingy_lib::{try_get_datetime, Config, MessagedError};
pub fn from_env(env: EnvOpt) -> Result<(), GenericError> {
match env.subcommand {
match env.subcommand.unwrap() {
Subcommand::Between(opt) => {
let config = Config::from_path(&env.config)?;
let mut api = API::new(config.clone());

View File

@ -12,8 +12,12 @@ use thingy_lib::Config;
fn main() {
let env: EnvOpt = argh::from_env();
if let Err(e) = cmd::from_env(env) {
eprintln!("Critical Error: {}", e);
std::process::exit(1);
if env.subcommand.is_some() {
if let Err(e) = cmd::from_env(env) {
eprintln!("Critical Error: {}", e);
std::process::exit(1);
}
} else {
println!("Open nwg UI instead");
}
}