From 6e9b7a9ee26741510f797d5d00671f577b809199 Mon Sep 17 00:00:00 2001 From: JF Ding Date: Wed, 18 Sep 2024 01:21:19 +0800 Subject: [PATCH] more proper arg design for import cmd --- src/cli.rs | 4 ++-- src/taskbox.rs | 6 +++++- src/util.rs | 8 ++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 92b5dcb..990f337 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -85,8 +85,8 @@ pub enum Commands { /// -> import uncompeleted task in any markdown file to current Import{ - #[arg(short, long)] - file: String, + #[arg(value_name = "markdown-file")] + file: Option, }, } diff --git a/src/taskbox.rs b/src/taskbox.rs index b695f58..da6ce28 100644 --- a/src/taskbox.rs +++ b/src/taskbox.rs @@ -7,6 +7,8 @@ use dirs; use chrono::*; use std::ops::*; +use crate::util; + const DATA_BASE : &str = ".local/share/todor"; const INBOX_NAME :&str = "INBOX"; @@ -358,7 +360,9 @@ impl TaskBox { } // specified markdown file -> cur - pub fn import(&mut self, mdfile: String) { + pub fn import(&mut self, file: Option) { + let mdfile= file.unwrap_or(util::pick_file()); + let fpath = Path::new(&mdfile); if ! fpath.is_file() { eprintln!("not a file or not exists: {}", mdfile.red()); diff --git a/src/util.rs b/src/util.rs index 02fa955..41cdfb7 100644 --- a/src/util.rs +++ b/src/util.rs @@ -37,3 +37,11 @@ pub fn edit_box(inbox_path: &Path, diffwith: Option) { ).expect("cannot launch cli editor(vi?)") } } + +pub fn pick_file() -> String { + run_fun!( + ls | fzf; + ).ok().unwrap_or_else(|| + std::process::exit(1) + ) +}