mirror of
https://github.com/numtide/treefmt.git
synced 2024-09-11 17:07:44 +03:00
cli: cleanup usage
This commit is contained in:
parent
dc9886217a
commit
76d511ea87
33
README.md
33
README.md
@ -39,21 +39,30 @@ quite difficult.
|
||||
|
||||
## Usage
|
||||
|
||||
`$ cargo run -- --help`
|
||||
```
|
||||
treefmt [options] [<file>...]
|
||||
treefmt 0.1.0
|
||||
The various kinds of commands that `treefmt` can execute
|
||||
|
||||
USAGE:
|
||||
treefmt [FLAGS] [OPTIONS] [SUBCOMMAND]
|
||||
|
||||
FLAGS:
|
||||
-h, --help Prints help information
|
||||
-q, --quiet No output printed to stdout
|
||||
-V, --version Prints version information
|
||||
-v, --verbose Log verbosity is based off the number of v used
|
||||
|
||||
OPTIONS:
|
||||
-C, --config <config> Specify where to look for the treefmt.toml file
|
||||
--log-level <log-level> The maximum level of messages that should be logged by treefmt. [possible values:
|
||||
info, warn, error] [default: debug]
|
||||
|
||||
SUBCOMMANDS:
|
||||
--init Init a new project with a default config
|
||||
help Prints this message or the help of the given subcommand(s)
|
||||
```
|
||||
|
||||
* `file`: path to files to format. If no files are passed, format all of the
|
||||
files from the current folder and down.
|
||||
|
||||
### Options
|
||||
|
||||
* `--init`: Creates a templated `treefmt.toml` in the current directory.
|
||||
|
||||
* `--config <path>`: Overrides the `treefmt.toml` file lookup.
|
||||
|
||||
* `--help`: Shows this help.
|
||||
|
||||
## Configuration format
|
||||
|
||||
`treefmt` depends on the `treefmt.toml` to map file extensions to actual code
|
||||
|
@ -15,17 +15,8 @@ use structopt::StructOpt;
|
||||
/// The various kinds of commands that `treefmt` can execute.
|
||||
pub enum Command {
|
||||
#[structopt(name = "--init")]
|
||||
/// init a new project with a default config
|
||||
Init {
|
||||
/// path to file or folder
|
||||
path: Option<PathBuf>,
|
||||
},
|
||||
#[structopt(name = "--config")]
|
||||
/// Specify treefmt.toml file
|
||||
PrjFmt {
|
||||
/// path to file or folder
|
||||
path: PathBuf,
|
||||
},
|
||||
/// Init a new project with a default config
|
||||
Init {},
|
||||
}
|
||||
|
||||
/// ✨ format all your language!
|
||||
@ -46,14 +37,17 @@ pub struct Cli {
|
||||
#[structopt(long = "log-level", default_value = "debug")]
|
||||
/// The maximum level of messages that should be logged by treefmt. [possible values: info, warn, error]
|
||||
pub log_level: LogLevel,
|
||||
|
||||
#[structopt(long = "config", short = "C")]
|
||||
/// Specify where to look for the treefmt.toml file
|
||||
pub config: Option<PathBuf>,
|
||||
}
|
||||
|
||||
/// Run a command with the given logger
|
||||
pub fn run_cli(cli: Cli) -> anyhow::Result<()> {
|
||||
match cli.cmd {
|
||||
Some(Command::Init { path }) => init_cmd(path)?,
|
||||
Some(Command::PrjFmt { path }) => format_cmd(Some(path))?,
|
||||
None => format_cmd(None)?,
|
||||
Some(Command::Init { }) => init_cmd(cli.config)?,
|
||||
None => format_cmd(cli.config)?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user