generated from PlexSheep/baserepo
Compare commits
No commits in common. "f6ea98286db1503484b3be2f41e7f542747b0e64" and "6a179a6bd5a51694ce9fb2e7ff0c7b626d0d8de8" have entirely different histories.
f6ea98286d
...
6a179a6bd5
4 changed files with 1 additions and 144 deletions
|
@ -54,7 +54,7 @@ core = []
|
||||||
full = ["default", "core", "log", "bintols"]
|
full = ["default", "core", "log", "bintols"]
|
||||||
log = ["dep:libpt-log"]
|
log = ["dep:libpt-log"]
|
||||||
bintols = ["dep:libpt-bintols", "log"]
|
bintols = ["dep:libpt-bintols", "log"]
|
||||||
cli = ["dep:libpt-cli", "core", "log"]
|
cli = ["dep:libpt-cli", "core"]
|
||||||
# py = ["dep:libpt-py"]
|
# py = ["dep:libpt-py"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
|
|
@ -12,15 +12,9 @@ repository.workspace = true
|
||||||
keywords.workspace = true
|
keywords.workspace = true
|
||||||
categories.workspace = true
|
categories.workspace = true
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["log"]
|
|
||||||
log = ["dep:libpt-log"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
|
||||||
clap = { version = "4.5.7", features = ["derive"] }
|
clap = { version = "4.5.7", features = ["derive"] }
|
||||||
comfy-table = "7.1.1"
|
comfy-table = "7.1.1"
|
||||||
console = "0.15.8"
|
console = "0.15.8"
|
||||||
dialoguer = "0.11.0"
|
dialoguer = "0.11.0"
|
||||||
indicatif = "0.17.8"
|
indicatif = "0.17.8"
|
||||||
libpt-log = {workspace = true, optional = true}
|
|
||||||
|
|
|
@ -1,135 +0,0 @@
|
||||||
use clap::Parser;
|
|
||||||
use libpt_log::Level;
|
|
||||||
|
|
||||||
/// Custom help template for displaying command-line usage information
|
|
||||||
///
|
|
||||||
/// This template modifies the default template provided by Clap to include additional information
|
|
||||||
/// and customize the layout of the help message.
|
|
||||||
///
|
|
||||||
/// Differences from the default template:
|
|
||||||
/// - Includes the application version and author information at the end
|
|
||||||
///
|
|
||||||
/// Apply like this:
|
|
||||||
/// ```
|
|
||||||
/// # use libpt_cli::args::HELP_TEMPLATE;
|
|
||||||
/// use clap::Parser;
|
|
||||||
/// #[derive(Parser, Debug, Clone, PartialEq, Eq, Hash)]
|
|
||||||
/// #[command(help_template = HELP_TEMPLATE)]
|
|
||||||
/// pub struct MyArgs {
|
|
||||||
/// /// show more details
|
|
||||||
/// #[arg(short, long)]
|
|
||||||
/// pub verbose: bool,
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// ## Example
|
|
||||||
///
|
|
||||||
/// Don't forget to set `authors` in your `Cargo.toml`!
|
|
||||||
///
|
|
||||||
/// ```bash
|
|
||||||
/// $ cargo run -- -h
|
|
||||||
/// about: short
|
|
||||||
///
|
|
||||||
/// Usage: aaa [OPTIONS]
|
|
||||||
///
|
|
||||||
/// Options:
|
|
||||||
/// -v, --verbose show more details
|
|
||||||
/// -h, --help Print help (see more with '--help')
|
|
||||||
/// -V, --version Print version
|
|
||||||
///
|
|
||||||
/// aaa: 0.1.0
|
|
||||||
/// Author: Christoph J. Scherr <software@cscherr.de>
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
pub const HELP_TEMPLATE: &str = r#"{about-section}
|
|
||||||
{usage-heading} {usage}
|
|
||||||
|
|
||||||
{all-args}{tab}
|
|
||||||
|
|
||||||
{name}: {version}
|
|
||||||
Author: {author-with-newline}
|
|
||||||
"#;
|
|
||||||
|
|
||||||
#[derive(Parser, Debug, Clone, PartialEq, Eq, Hash)]
|
|
||||||
#[command(help_template = HELP_TEMPLATE)]
|
|
||||||
pub struct DefaultArguments {
|
|
||||||
/// get a [tracing] log level
|
|
||||||
///
|
|
||||||
/// set the verbosity with repeated '-q' and '-v' flags
|
|
||||||
#[command(flatten)]
|
|
||||||
verbose: VerbosityLevel,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Parser, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub struct VerbosityLevel {
|
|
||||||
/// make the output more verbose
|
|
||||||
#[arg(
|
|
||||||
long,
|
|
||||||
short = 'v',
|
|
||||||
action = clap::ArgAction::Count,
|
|
||||||
global = true,
|
|
||||||
// help = L::verbose_help(),
|
|
||||||
// long_help = L::verbose_long_help(),
|
|
||||||
)]
|
|
||||||
verbose: u8,
|
|
||||||
|
|
||||||
/// make the output less verbose
|
|
||||||
///
|
|
||||||
/// ( -qqq for completely quiet)
|
|
||||||
#[arg(
|
|
||||||
long,
|
|
||||||
short = 'q',
|
|
||||||
action = clap::ArgAction::Count,
|
|
||||||
global = true,
|
|
||||||
conflicts_with = "verbose",
|
|
||||||
)]
|
|
||||||
quiet: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VerbosityLevel {
|
|
||||||
/// true only if no verbose and no quiet was set (user is using defaults)
|
|
||||||
#[inline]
|
|
||||||
pub fn changed(&self) -> bool {
|
|
||||||
self.verbose != 0 || self.quiet != 0
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
fn value(&self) -> i8 {
|
|
||||||
let v = Self::level_value(Level::INFO) - (self.quiet as i8) + (self.verbose as i8);
|
|
||||||
if v > Self::level_value(Level::TRACE) {
|
|
||||||
Self::level_value(Level::TRACE)
|
|
||||||
} else {
|
|
||||||
v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// get the [Level] for that VerbosityLevel
|
|
||||||
///
|
|
||||||
/// [None] means that absolutely no output is wanted (completely quiet)
|
|
||||||
#[inline]
|
|
||||||
pub fn level(&self) -> Option<Level> {
|
|
||||||
Some(match self.value() {
|
|
||||||
0 => Level::ERROR,
|
|
||||||
1 => Level::WARN,
|
|
||||||
2 => Level::INFO,
|
|
||||||
3 => Level::DEBUG,
|
|
||||||
4 => Level::TRACE,
|
|
||||||
_ => return None,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
fn level_value(level: Level) -> i8 {
|
|
||||||
match level {
|
|
||||||
Level::TRACE => 4,
|
|
||||||
Level::DEBUG => 3,
|
|
||||||
Level::INFO => 2,
|
|
||||||
Level::WARN => 1,
|
|
||||||
Level::ERROR => 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Debug for VerbosityLevel {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(f, "{:?}", self.level())
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +1,7 @@
|
||||||
pub mod printing;
|
pub mod printing;
|
||||||
pub mod repl;
|
pub mod repl;
|
||||||
pub mod args;
|
|
||||||
|
|
||||||
pub use comfy_table;
|
pub use comfy_table;
|
||||||
pub use console;
|
pub use console;
|
||||||
pub use dialoguer;
|
pub use dialoguer;
|
||||||
pub use indicatif;
|
pub use indicatif;
|
||||||
pub use clap;
|
|
||||||
|
|
Reference in a new issue