handling of CLI flags
This commit is contained in:
37
src/main.rs
37
src/main.rs
@@ -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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user