Restructure command line args
This commit is contained in:
parent
cdf28edec6
commit
494f1976c6
2 changed files with 31 additions and 17 deletions
42
src/cli.rs
42
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<PathBuf>,
|
||||
/// 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<usize>,
|
||||
#[structopt(subcommand)]
|
||||
command: Option<Command>,
|
||||
}
|
||||
|
||||
#[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(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue