mirror of
https://github.com/orhun/systeroid
synced 2024-10-15 11:52:19 +00:00
style(args): use a different message in the case of missing params
This commit is contained in:
parent
b9d55a2302
commit
cf151b4108
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue