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:
Jonas Chevalier 2021-02-27 15:07:09 +00:00 committed by GitHub
parent 69cdd005b5
commit 6e560d5f09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

@ -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

View File

@ -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)?;

View File

@ -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>,
}