generated from PlexSheep/rs-base
fix cli interface to not need a format flag
cargo devel CI / cargo CI (push) Successful in 1m21s
Details
cargo devel CI / cargo CI (push) Successful in 1m21s
Details
This commit is contained in:
parent
e96bb48e4d
commit
348613cbf8
35
src/main.rs
35
src/main.rs
|
@ -54,14 +54,13 @@ impl Format {
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
#[clap(group(
|
#[clap(group(
|
||||||
ArgGroup::new("format")
|
ArgGroup::new("format")
|
||||||
.required(true)
|
|
||||||
.args(&["hex", "bin", "oct", "dec"]),
|
.args(&["hex", "bin", "oct", "dec"]),
|
||||||
))]
|
))]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
/// add a prefix (like "0x" for hex)
|
/// add a prefix (like "0x" for hex)
|
||||||
prefix: bool,
|
prefix: bool,
|
||||||
#[arg(short = 'x', long)]
|
#[arg(short = 'x', long, default_value_t = true)]
|
||||||
/// format to hexadecimal
|
/// format to hexadecimal
|
||||||
hex: bool,
|
hex: bool,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
|
@ -88,17 +87,16 @@ impl Cli {
|
||||||
Format::Bin
|
Format::Bin
|
||||||
} else if self.dec {
|
} else if self.dec {
|
||||||
Format::Dec
|
Format::Dec
|
||||||
} else {
|
} else if self.hex {
|
||||||
Format::Hex
|
Format::Hex
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match formatter() {
|
let _ = formatter();
|
||||||
Ok(_) => (),
|
|
||||||
Err(_err) => usage(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn formatter() -> anyhow::Result<()> {
|
fn formatter() -> anyhow::Result<()> {
|
||||||
|
@ -115,26 +113,3 @@ fn formatter() -> anyhow::Result<()> {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn help() {
|
|
||||||
let help: String = format!(
|
|
||||||
r##"numf {}
|
|
||||||
|
|
||||||
-h, --help print this help
|
|
||||||
-p, --prefix print a prefix before the formatted number
|
|
||||||
-b, --binary format to binary
|
|
||||||
-o, --octal format to octal
|
|
||||||
-x, --hex format to hex (default)
|
|
||||||
|
|
||||||
Author: Christoph J. Scherr 2024
|
|
||||||
"##,
|
|
||||||
env!("CARGO_PKG_VERSION")
|
|
||||||
);
|
|
||||||
println!("{help}");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn usage() {
|
|
||||||
println!("Usage: numf -hpbox NUMBER\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
Reference in New Issue