-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[red-knot] Add verbosity argument to CLI (#12404)
- Loading branch information
1 parent
a62e2d2
commit ad19b3f
Showing
6 changed files
with
89 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub(crate) mod target_version; | ||
pub(crate) mod verbosity; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] | ||
pub(crate) enum VerbosityLevel { | ||
Info, | ||
Debug, | ||
Trace, | ||
} | ||
|
||
/// Logging flags to `#[command(flatten)]` into your CLI | ||
#[derive(clap::Args, Debug, Clone, Default)] | ||
#[command(about = None, long_about = None)] | ||
pub(crate) struct Verbosity { | ||
#[arg( | ||
long, | ||
short = 'v', | ||
help = "Use verbose output (or `-vv` and `-vvv` for more verbose output)", | ||
action = clap::ArgAction::Count, | ||
global = true, | ||
)] | ||
verbose: u8, | ||
} | ||
|
||
impl Verbosity { | ||
/// Returns the verbosity level based on the number of `-v` flags. | ||
/// | ||
/// Returns `None` if the user did not specify any verbosity flags. | ||
pub(crate) fn level(&self) -> Option<VerbosityLevel> { | ||
match self.verbose { | ||
0 => None, | ||
1 => Some(VerbosityLevel::Info), | ||
2 => Some(VerbosityLevel::Debug), | ||
_ => Some(VerbosityLevel::Trace), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters