fix: fix cli interface to not need a format flag

This commit is contained in:
Christoph J. Scherr 2024-05-10 15:59:57 +02:00
parent 6c66c285a0
commit df621fdb6d
1 changed files with 5 additions and 30 deletions

View File

@ -54,14 +54,13 @@ impl Format {
#[clap(author, version, about, long_about = None)]
#[clap(group(
ArgGroup::new("format")
.required(true)
.args(&["hex", "bin", "oct", "dec"]),
))]
struct Cli {
#[arg(short, long)]
/// add a prefix (like "0x" for hex)
prefix: bool,
#[arg(short = 'x', long)]
#[arg(short = 'x', long, default_value_t = true)]
/// format to hexadecimal
hex: bool,
#[arg(short, long)]
@ -88,17 +87,16 @@ impl Cli {
Format::Bin
} else if self.dec {
Format::Dec
} else {
} else if self.hex {
Format::Hex
} else {
unreachable!()
}
}
}
fn main() {
match formatter() {
Ok(_) => (),
Err(_err) => usage(),
}
let _ = formatter();
}
fn formatter() -> anyhow::Result<()> {
@ -115,26 +113,3 @@ fn formatter() -> anyhow::Result<()> {
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);
}