added basic notifications, args cleanup

This commit is contained in:
əlemi 2022-03-14 23:12:41 +01:00
parent ea91973e5a
commit 4e49696dab
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E
2 changed files with 29 additions and 16 deletions

View file

@ -11,6 +11,7 @@ edition = "2021"
[dependencies]
regex = "1"
chrono = "0.4.19"
libnotify = "1.0.3"
clap = { version = "3.1.6", features = ["derive"] }
rusqlite = { version="0.27.0", features=["chrono"] }

View file

@ -1,7 +1,7 @@
mod storage;
mod utils;
use chrono::{DateTime, Utc};
use chrono::{DateTime, Utc, Local};
use clap::{Parser, Subcommand};
use regex::Regex;
pub use storage::{open_sqlite_storage, Memo, MemoStorage};
@ -9,16 +9,18 @@ use utils::{parse_human_duration, HumanDisplay};
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
#[clap(propagate_version = true, disable_colored_help = true)]
#[clap(disable_colored_help = true)]
#[clap(subcommand_required = false)]
#[clap(disable_help_subcommand = true)]
struct Cli {
#[clap(subcommand)]
command: Option<Commands>,
#[clap(short, long, help = "location for database file")]
db_path: Option<String>,
#[clap(short, long, help = "show memos in a notification")]
notify: bool,
#[clap(long, help = "show completed tasks")]
old: bool,
#[clap(short, long, help = "location for database file")]
db_path: Option<String>,
}
#[derive(Subcommand)]
@ -30,16 +32,13 @@ enum Commands {
#[clap(required = true)]
body: Vec<String>,
#[clap(short, long, help = "due time relative to now")]
due: Option<String>,
due: Option<String>, // TODO allow to pass date
},
Done {
search: String,
#[clap(long)]
#[clap(long, help = "delete more than one task if matched")]
many: bool,
},
Del {
id: u32,
},
}
}
fn main() {
@ -93,17 +92,30 @@ fn main() {
println!("[!] invalid regex");
}
}
Some(Commands::Del { id }) => {
storage.del(id).unwrap();
println!("[-] task #{} deleted", id);
}
None => {
let all = storage.all(args.old).unwrap();
let mut builder = String::new();
if args.old {
builder.push_str("Archived memos:\n");
}
if all.len() < 1 {
println!("[ ] nothing to remember");
builder.push_str("[ ] nothing to remember\n");
}
for m in all {
println!("{}", m.human());
builder.push_str(m.human().as_str());
builder.push('\n');
}
if args.notify {
libnotify::init("memo-cli").unwrap();
let n = libnotify::Notification::new(
format!("memo-cli | {}", Local::now().format("%a %d/%m, %H:%M")).as_str(),
Some(builder.as_str()),
None
);
n.show().unwrap();
libnotify::uninit();
} else {
print!("{}", builder);
}
}
}