diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 66 |
1 files changed, 36 insertions, 30 deletions
diff --git a/src/main.rs b/src/main.rs index 2021fc5..769fe98 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ extern crate clap; -use clap::{App, Arg}; +use clap::Arg; +use clap::Command; use std::env; use std::io::Error; use std::io::ErrorKind; @@ -8,76 +9,81 @@ use std::process; /// Central application entry point. fn main() { - let desc: &str = &format!( + let desc = &format!( "{}\n{}", env!("CARGO_PKG_DESCRIPTION"), env!("CARGO_PKG_HOMEPAGE") ); - let app = App::new(env!("CARGO_PKG_NAME")) + let app = Command::new(env!("CARGO_PKG_NAME")) .version(env!("CARGO_PKG_VERSION")) .about(desc) .arg( - Arg::with_name(hx::ARG_COL) - .short("c") + Arg::new(hx::ARG_COL) + .action(clap::ArgAction::Set) + .short('c') .long(hx::ARG_COL) .value_name("columns") .help("Set column length") - .takes_value(true), + .num_args(1) ) .arg( - Arg::with_name(hx::ARG_LEN) - .short("l") + Arg::new(hx::ARG_LEN) + .action(clap::ArgAction::Set) + .short('l') .long(hx::ARG_LEN) .value_name(hx::ARG_LEN) .help("Set <len> bytes to read") - .takes_value(true), + .num_args(1) ) .arg( - Arg::with_name(hx::ARG_FMT) - .short("f") + Arg::new(hx::ARG_FMT) + .action(clap::ArgAction::Set) + .short('f') .long(hx::ARG_FMT) .help("Set format of octet: Octal (o), LowerHex (x), UpperHex (X), Binary (b)") - .possible_values(&["o", "x", "X", "b"]) - .takes_value(true), + .value_parser(["o", "x", "X", "b"]) + .num_args(1) ) .arg( - Arg::with_name(hx::ARG_INP) + Arg::new(hx::ARG_INP) .help("Pass file path as an argument, or input data may be passed via stdin") .required(false) .index(1), ) .arg( - Arg::with_name(hx::ARG_CLR) - .short("t") + Arg::new(hx::ARG_CLR) + .action(clap::ArgAction::Set) + .short('t') .long(hx::ARG_CLR) .help("Set color tint terminal output. 0 to disable, 1 to enable") - .possible_values(&["0", "1"]) - .takes_value(true), + .value_parser(["0", "1"]) + .num_args(1) ) .arg( - Arg::with_name(hx::ARG_ARR) - .short("a") + Arg::new(hx::ARG_ARR) + .action(clap::ArgAction::Set) + .short('a') .long(hx::ARG_ARR) .value_name("array_format") .help("Set source code format output: rust (r), C (c), golang (g), python (p), kotlin (k), java (j), swift (s), fsharp (f)") - .possible_values(&["r", "c", "g", "p", "k", "j", "s", "f"]) - .takes_value(true), + .value_parser(["r", "c", "g", "p", "k", "j", "s", "f"]) + .num_args(1) ) .arg( - Arg::with_name(hx::ARG_FNC) - .short("u") + Arg::new(hx::ARG_FNC) + .short('u') .long(hx::ARG_FNC) .value_name("func_length") .help("Set function wave length") - .takes_value(true), + .num_args(1) ) .arg( - Arg::with_name(hx::ARG_PLC) - .short("p") + Arg::new(hx::ARG_PLC) + .short('p') .long(hx::ARG_PLC) .value_name("func_places") .help("Set function wave output decimal places") - .takes_value(true), + .num_args(1) ); let matches = app.get_matches(); @@ -85,14 +91,14 @@ fn main() { Ok(_) => { process::exit(0); } - Err(_) => { + Err(e) => { let err = &Error::last_os_error(); let suppress_error = match err.kind() { ErrorKind::BrokenPipe => process::exit(0), _ => false, }; if !suppress_error { - eprintln!("error: {}", err); + eprintln!("error: {}", e); process::exit(1); } } |