Add --reformat and --reformat-all flags
This commit is contained in:
parent
5d03f6098e
commit
cdf28edec6
2 changed files with 18 additions and 1 deletions
13
src/cli.rs
13
src/cli.rs
|
|
@ -18,6 +18,12 @@ 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,
|
||||
}
|
||||
|
||||
fn default_file() -> PathBuf {
|
||||
|
|
@ -31,7 +37,7 @@ pub fn run() -> anyhow::Result<()> {
|
|||
let opt = Opt::from_args();
|
||||
|
||||
let file = opt.file.unwrap_or_else(default_file);
|
||||
let files = Files::load(&file)?;
|
||||
let mut files = Files::load(&file)?;
|
||||
let now = files.now().naive_local();
|
||||
|
||||
let range = DateRange::new(
|
||||
|
|
@ -49,6 +55,11 @@ pub fn run() -> anyhow::Result<()> {
|
|||
render.render(&files, &entries, &layout);
|
||||
print!("{}", render.display());
|
||||
|
||||
if opt.reformat_all {
|
||||
files.mark_all_dirty();
|
||||
} else if opt.reformat {
|
||||
files.mark_main_dirty();
|
||||
}
|
||||
files.save()?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,6 +175,12 @@ 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