Make subcommand optional
This commit is contained in:
parent
64742a0e21
commit
bb87581ea5
@ -12,7 +12,7 @@ pub struct EnvOpt {
|
|||||||
)]
|
)]
|
||||||
pub config: PathBuf,
|
pub config: PathBuf,
|
||||||
#[argh(subcommand)]
|
#[argh(subcommand)]
|
||||||
pub subcommand: Subcommand,
|
pub subcommand: Option<Subcommand>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromArgs)]
|
#[derive(FromArgs)]
|
||||||
|
@ -6,7 +6,7 @@ use thingy_lib::chrono::NaiveDateTime;
|
|||||||
use thingy_lib::{try_get_datetime, Config, MessagedError};
|
use thingy_lib::{try_get_datetime, Config, MessagedError};
|
||||||
|
|
||||||
pub fn from_env(env: EnvOpt) -> Result<(), GenericError> {
|
pub fn from_env(env: EnvOpt) -> Result<(), GenericError> {
|
||||||
match env.subcommand {
|
match env.subcommand.unwrap() {
|
||||||
Subcommand::Between(opt) => {
|
Subcommand::Between(opt) => {
|
||||||
let config = Config::from_path(&env.config)?;
|
let config = Config::from_path(&env.config)?;
|
||||||
let mut api = API::new(config.clone());
|
let mut api = API::new(config.clone());
|
||||||
|
10
src/main.rs
10
src/main.rs
@ -12,8 +12,12 @@ use thingy_lib::Config;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let env: EnvOpt = argh::from_env();
|
let env: EnvOpt = argh::from_env();
|
||||||
if let Err(e) = cmd::from_env(env) {
|
if env.subcommand.is_some() {
|
||||||
eprintln!("Critical Error: {}", e);
|
if let Err(e) = cmd::from_env(env) {
|
||||||
std::process::exit(1);
|
eprintln!("Critical Error: {}", e);
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Open nwg UI instead");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user