Skip to content

Commit

Permalink
more proper arg design for import cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
jfding committed Sep 17, 2024
1 parent 1e8e7b2 commit 6e9b7a9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
},
}

Expand Down
6 changes: 5 additions & 1 deletion src/taskbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -358,7 +360,9 @@ impl TaskBox {
}

// specified markdown file -> cur
pub fn import(&mut self, mdfile: String) {
pub fn import(&mut self, file: Option<String>) {
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());
Expand Down
8 changes: 8 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ pub fn edit_box(inbox_path: &Path, diffwith: Option<String>) {
).expect("cannot launch cli editor(vi?)")
}
}

pub fn pick_file() -> String {
run_fun!(
ls | fzf;
).ok().unwrap_or_else(||
std::process::exit(1)
)
}

0 comments on commit 6e9b7a9

Please sign in to comment.