mirror of
https://github.com/numtide/treefmt.git
synced 2024-09-11 17:07:44 +03:00
cli: format the whole tree by default (#74)
Instead of formatting the current directory, format the whole tree if no paths are given. Use `treefmt .` to format the current folder. That way it's less likely that some files will not be re-formatted, even if the user is working in a sub-folder.
This commit is contained in:
parent
69cdd005b5
commit
6e560d5f09
@ -56,12 +56,13 @@ FLAGS:
|
||||
OPTIONS:
|
||||
--log-level <log-level> The maximum level of messages that should be logged by treefmt. [possible values:
|
||||
info, warn, error] [default: debug]
|
||||
--tree-root <tree-root> Set the location of the tree root. Defaults to the location of the treefmt.toml file
|
||||
--tree-root <tree-root> Set the path to the tree root directory. Defaults to the folder holding the
|
||||
treefmt.toml file
|
||||
-C <work-dir> Run as if treefmt was started in <work-dir> instead of the current working directory
|
||||
[default: .]
|
||||
|
||||
ARGS:
|
||||
<paths>... Paths to format [default: .]
|
||||
<paths>... Paths to format. Defaults to formatting the whole tree
|
||||
```
|
||||
|
||||
## Configuration format
|
||||
|
@ -39,6 +39,13 @@ pub fn format_cmd(
|
||||
config_file.clone().parent().unwrap().to_path_buf()
|
||||
});
|
||||
|
||||
// Default to the tree root if no paths have been given
|
||||
let paths = if paths.is_empty() {
|
||||
vec![tree_root.clone()]
|
||||
} else {
|
||||
paths.to_owned()
|
||||
};
|
||||
|
||||
let cache_dir = proj_dirs.cache_dir().join("eval-cache");
|
||||
// Make sure the cache directory exists.
|
||||
fs::create_dir_all(&cache_dir)?;
|
||||
|
@ -50,8 +50,8 @@ pub struct Cli {
|
||||
/// Set the path to the tree root directory. Defaults to the folder holding the treefmt.toml file.
|
||||
pub tree_root: Option<PathBuf>,
|
||||
|
||||
#[structopt(default_value = ".")]
|
||||
/// Paths to format
|
||||
#[structopt()]
|
||||
/// Paths to format. Defaults to formatting the whole tree.
|
||||
pub paths: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user