Skip to content

Commit

Permalink
Merge pull request #679 from loco-rs/loco-cli-verbose
Browse files Browse the repository at this point in the history
Loco cli verbose - support also text
  • Loading branch information
jondot committed Jul 30, 2024
2 parents 95bf4d4 + 541d77c commit 81b44ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
14 changes: 4 additions & 10 deletions loco-cli/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ use std::env;
use std::path::PathBuf;
use tracing::level_filters::LevelFilter;
use tracing_subscriber::EnvFilter;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
struct Cli {
#[arg(global = true, short, long, action = clap::ArgAction::Count)]
#[arg(global = true, short, long, value_enum, default_value = "ERROR")]
/// Verbosity level
verbose: u8,
verbose: LevelFilter,

#[command(subcommand)]
command: Commands,
Expand All @@ -32,14 +33,7 @@ fn main() -> eyre::Result<()> {
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::builder()
.with_default_directive(match cli.verbose {
// The default one for `from_default_env`
0 => LevelFilter::ERROR.into(),
1 => LevelFilter::WARN.into(),
2 => LevelFilter::INFO.into(),
3 => LevelFilter::DEBUG.into(),
_ => LevelFilter::TRACE.into(),
})
.with_default_directive(cli.verbose.into())
.from_env_lossy(),
)
.init();
Expand Down
8 changes: 4 additions & 4 deletions loco-cli/tests/cmd/cli.trycmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Create a new Loco website
Usage: loco[EXE] new [OPTIONS]

Options:
-p, --path <PATH> Local path to generate into [default: .]
-v, --verbose... Verbosity level
-h, --help Print help
-V, --version Print version
-p, --path <PATH> Local path to generate into [default: .]
-v, --verbose <VERBOSE> Verbosity level [default: ERROR]
-h, --help Print help
-V, --version Print version

```

0 comments on commit 81b44ef

Please sign in to comment.