From 494f1976c62193b44886aa07b6e98ef1d7620ae0 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 12 Dec 2021 22:00:24 +0000 Subject: [PATCH] Restructure command line args --- src/cli.rs | 42 +++++++++++++++++++++++++++++++----------- src/files.rs | 6 ------ 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 3e714eb..a4bd5b3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,4 +1,5 @@ use std::path::PathBuf; +use std::process; use chrono::NaiveDate; use directories::ProjectDirs; @@ -18,12 +19,21 @@ pub struct Opt { /// File to load #[structopt(short, long, parse(from_os_str))] file: Option, - /// Reformat the file - #[structopt(short, long)] - reformat: bool, - /// Reformat the file and all imports - #[structopt(short = "R", long)] - reformat_all: bool, + /// Number of the entry to view or edit + entry: Option, + #[structopt(subcommand)] + command: Option, +} + +#[derive(Debug, StructOpt)] +pub enum Command { + /// Shows entries in a range, or a single entry if one is specified + /// (default) + Show, + /// Marks an entry as done (requires entry) + Done, + /// Reformat all loaded files + Fmt, } fn default_file() -> PathBuf { @@ -53,13 +63,23 @@ pub fn run() -> anyhow::Result<()> { let mut render = Render::new(); render.render(&files, &entries, &layout); - print!("{}", render.display()); - if opt.reformat_all { - files.mark_all_dirty(); - } else if opt.reformat { - files.mark_main_dirty(); + match opt.command { + None | Some(Command::Show) => match opt.entry { + None => print!("{}", render.display()), + // Some(i) => print!("{}", render::render_entry(&files, &entries, &layout, i)), + Some(i) => todo!(), + }, + Some(Command::Done) => match opt.entry { + None => { + println!("Please specify an entry. See `today --help` for more details."); + process::exit(1); + } + Some(i) => todo!(), + }, + Some(Command::Fmt) => files.mark_all_dirty(), } + files.save()?; Ok(()) } diff --git a/src/files.rs b/src/files.rs index 86c3443..bea36a3 100644 --- a/src/files.rs +++ b/src/files.rs @@ -175,12 +175,6 @@ impl Files { Ok(()) } - pub fn mark_main_dirty(&mut self) { - if let Some(file) = self.files.get_mut(0) { - file.dirty = true; - } - } - pub fn mark_all_dirty(&mut self) { for file in self.files.iter_mut() { file.dirty = true;