handling of CLI flags

This commit is contained in:
2020-11-19 18:10:12 +01:00
parent 9cd97a33ce
commit 10a50d305f

View File

@@ -1,21 +1,48 @@
use structopt::StructOpt; use structopt::StructOpt;
use chrono::{Local, NaiveTime};
use std::process;
use std::process::Command;
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
#[structopt( author, about)] #[structopt( author, about)]
struct Cli { struct Cli {
#[structopt(short = "k", help="output khal events")] #[structopt(short, long, help="output khal events")]
khal: bool, khal: bool,
#[structopt(short = "t", help="output todos")] #[structopt(short, long, help="output todos")]
todo: bool, todo: bool,
} }
fn main() { fn main() {
let args = Cli::from_args(); let args = Cli::from_args();
if args.khal && args.todo { if ( !args.khal && !args.todo ) ||
println!("khal"); ( args.khal && args.todo )
{
eprintln!("Please provide either khal or todo flag.");
Cli::clap().print_help();
println!();
process::exit(1);
}
let now = Local::now().time();
let from = now.format("%H:%M").to_string();
if args.khal {
let cmd = Command::new("khal")
.arg("list")
.arg("-df")
.arg("{name}")
.arg("-f")
.arg("{start-time}")
.arg("--notstarted")
.arg(&from)
.arg("23:59")
.output();
println!("khal output");
} else if args.todo {
println!("todo output");
} }
println!("{:?}", args);
} }