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
|
/// 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
|
||||||
|
#[structopt(short, long)]
|
||||||
|
reformat: bool,
|
||||||
|
/// Reformat the file and all imports
|
||||||
|
#[structopt(short = "R", long)]
|
||||||
|
reformat_all: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_file() -> PathBuf {
|
fn default_file() -> PathBuf {
|
||||||
|
|
@ -31,7 +37,7 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
let opt = Opt::from_args();
|
let opt = Opt::from_args();
|
||||||
|
|
||||||
let file = opt.file.unwrap_or_else(default_file);
|
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 now = files.now().naive_local();
|
||||||
|
|
||||||
let range = DateRange::new(
|
let range = DateRange::new(
|
||||||
|
|
@ -49,6 +55,11 @@ pub fn run() -> anyhow::Result<()> {
|
||||||
render.render(&files, &entries, &layout);
|
render.render(&files, &entries, &layout);
|
||||||
print!("{}", render.display());
|
print!("{}", render.display());
|
||||||
|
|
||||||
|
if opt.reformat_all {
|
||||||
|
files.mark_all_dirty();
|
||||||
|
} else if opt.reformat {
|
||||||
|
files.mark_main_dirty();
|
||||||
|
}
|
||||||
files.save()?;
|
files.save()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -175,6 +175,12 @@ 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