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::path::PathBuf;
|
||||||
|
use std::process;
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
|
|
@ -18,12 +19,21 @@ pub struct Opt {
|
||||||
/// File to load
|
/// File to load
|
||||||
#[structopt(short, long, parse(from_os_str))]
|
#[structopt(short, long, parse(from_os_str))]
|
||||||
file: Option<PathBuf>,
|
file: Option<PathBuf>,
|
||||||
/// Reformat the file
|
/// Number of the entry to view or edit
|
||||||
#[structopt(short, long)]
|
entry: Option<usize>,
|
||||||
reformat: bool,
|
#[structopt(subcommand)]
|
||||||
/// Reformat the file and all imports
|
command: Option<Command>,
|
||||||
#[structopt(short = "R", long)]
|
}
|
||||||
reformat_all: bool,
|
|
||||||
|
#[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 {
|
fn default_file() -> PathBuf {
|
||||||
|
|
@ -53,13 +63,23 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
let mut render = Render::new();
|
let mut render = Render::new();
|
||||||
render.render(&files, &entries, &layout);
|
render.render(&files, &entries, &layout);
|
||||||
print!("{}", render.display());
|
|
||||||
|
|
||||||
if opt.reformat_all {
|
match opt.command {
|
||||||
files.mark_all_dirty();
|
None | Some(Command::Show) => match opt.entry {
|
||||||
} else if opt.reformat {
|
None => print!("{}", render.display()),
|
||||||
files.mark_main_dirty();
|
// 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()?;
|
files.save()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -175,12 +175,6 @@ impl Files {
|
||||||
Ok(())
|
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) {
|
pub fn mark_all_dirty(&mut self) {
|
||||||
for file in self.files.iter_mut() {
|
for file in self.files.iter_mut() {
|
||||||
file.dirty = true;
|
file.dirty = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue