diff --git a/src/args.rs b/src/args.rs index 4c82968..4a6dc5d 100644 --- a/src/args.rs +++ b/src/args.rs @@ -13,14 +13,22 @@ pub struct Cli { #[derive(Subcommand, Debug)] pub enum Commands { - //Task(Task) + /// Actions on tasks, default list your tasks Tasks(Tasks), + /// Actions on folders Folders(Folders), } -#[derive(Args, Debug)] +#[derive(Debug, Parser)] pub struct Tasks { - pub tasks_arg: Option, + /// Search tasks, matching words in title + #[arg(short, long)] + pub search: Option, + /// Filter searched tasks by status + #[arg(long)] + pub status: Option, + #[arg(short, long)] + pub me: bool, } #[derive(Args, Debug)] diff --git a/src/folders.rs b/src/folders.rs index 4d7e039..153170c 100644 --- a/src/folders.rs +++ b/src/folders.rs @@ -18,7 +18,7 @@ struct Folders { child_ids: Option>, } -pub fn get_folders<'a>(url: &'a str, path: &'a str, token: &'a str) -> Result<()> { +pub fn _get_folders<'a>(url: &'a str, path: &'a str, token: &'a str) -> Result<()> { let client = reqwest::blocking::Client::new(); let url: String = format!("{}{}", &url, &path); let res = client diff --git a/src/main.rs b/src/main.rs index a0def1c..5ab8067 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,30 +15,30 @@ fn main() -> Result<()> { let user: String = env::var("WRIKE_USER")?; let url: String = env::var("URL")?; let token: String = env::var("TOKEN")?; - let cli = Cli::parse(); match &cli.command { - Some(Commands::Tasks(name)) => match name.tasks_arg { - Some(ref _tasks_arg) => { - println!("No extra argument expected for , please see --help"); - } - None => { - let path: String = format!(r##"/tasks?responsibles=[{}]"##, user); - tasks::get_tasks(&url, &path, &token)?; - } - }, - Some(Commands::Folders(name)) => match name.folders_arg { - Some(ref _folders_arg) => { - println!("No extra argument expected for , please see --help"); - } - None => { - let path: &str = "/folders"; - folders::get_folders(&url, &path, &token)?; - } - }, + Some(Commands::Tasks(args)) => { + let null = String::from(""); + let status = match &args.status { + Some(status) => status, + None => "[Active, Completed, Deferred, Cancelled]", + }; + let search = match &args.search { + Some(search) => search, + None => "", + }; + + let user = if args.me { &user } else { &null }; + let path = format!( + r##"/tasks?responsibles=[{}]&title={}&status={}"##, + user, search, status + ); + tasks::get_tasks(&url, &path, &token)?; + } + + Some(Commands::Folders(_folders_arg)) => {} None => {} } - Ok(()) } diff --git a/src/tasks.rs b/src/tasks.rs index 755c564..b66bd5f 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -17,27 +17,28 @@ struct Tasks { id: String, status: String, importance: String, + permalink: String, } pub fn get_tasks<'a>(url: &'a str, path: &'a str, token: &'a str) -> Result<()> { let client = reqwest::blocking::Client::new(); let url: String = format!("{}{}", &url, &path); let res = client - .get(url) + .get(&url) .header(AUTHORIZATION, token) .header(CONTENT_TYPE, "application/json") .header(ACCEPT, "application/json") .send() .context("Failed to make get tasks")?; - let tasks: KindTask = res.json::().context("Could not decode json")?; let mut table = Table::new(); - table.add_row(row!["id", "name", "priority", "status"]); + table.add_row(row!["id", "name", "priority", "url", "status"]); for i in tasks.data.iter() { table.add_row(Row::new(vec![ Cell::new(&i.id), Cell::new(&i.title), Cell::new(&i.importance), + Cell::new(&i.permalink), Cell::new(&i.status), ])); }