style(args): use a different message in the case of missing params

This commit is contained in:
Orhun Parmaksız 2021-12-04 16:48:06 +03:00
parent b9d55a2302
commit cf151b4108
No known key found for this signature in database
GPG key ID: F83424824B3E4B90

View file

@ -66,8 +66,9 @@ impl Args {
opts.optflag("h", "help", "display this help and exit");
opts.optflag("V", "version", "output version information and exit");
let env_args = env::args().collect::<Vec<String>>();
let matches = opts
.parse(&env::args().collect::<Vec<String>>()[1..])
.parse(&env_args[1..])
.map_err(|e| eprintln!("error: `{}`", e))
.ok()?;
@ -77,7 +78,7 @@ impl Args {
|| !matches.free.is_empty()
|| matches.opt_str("explain").is_some();
if matches.opt_present("h") || !required_args_present {
if matches.opt_present("h") || env_args.len() == 1 {
let usage = opts.usage_with_format(|opts| {
HELP_MESSAGE
.replace("{bin}", env!("CARGO_PKG_NAME"))
@ -85,6 +86,14 @@ impl Args {
});
println!("{}", usage);
None
} else if !required_args_present {
println!(
"{}: no variables specified\n\
Try `{} --help' for more information.",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_NAME")
);
None
} else if matches.opt_present("V") {
println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
None