fix '--' parameter handling and help error output
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
1e373b3395
commit
750b5cb3db
28
src/main.rs
28
src/main.rs
@ -55,6 +55,17 @@ fn main() {
|
|||||||
let mut use_sd_notify = false;
|
let mut use_sd_notify = false;
|
||||||
let mut path = None;
|
let mut path = None;
|
||||||
|
|
||||||
|
let mut nonopt_arg = |arg: OsString| {
|
||||||
|
if path.is_some() {
|
||||||
|
let _ = stderr().write_all(b"unexpected extra parameter: ");
|
||||||
|
let _ = stderr().write_all(arg.as_bytes());
|
||||||
|
let _ = stderr().write_all(b"\n");
|
||||||
|
usage(1, &program, &mut stderr());
|
||||||
|
}
|
||||||
|
|
||||||
|
path = Some(arg);
|
||||||
|
};
|
||||||
|
|
||||||
for arg in &mut args {
|
for arg in &mut args {
|
||||||
if arg == "-h" || arg == "--help" {
|
if arg == "-h" || arg == "--help" {
|
||||||
usage(0, &program, &mut stdout());
|
usage(0, &program, &mut stdout());
|
||||||
@ -65,23 +76,22 @@ fn main() {
|
|||||||
} else if arg == "--system" {
|
} else if arg == "--system" {
|
||||||
use_sd_notify = true;
|
use_sd_notify = true;
|
||||||
} else {
|
} else {
|
||||||
let bytes = arg.as_bytes();
|
if arg.as_bytes().starts_with(b"-") {
|
||||||
if bytes.starts_with(b"-") {
|
|
||||||
let _ = stderr().write_all(b"unexpected option: ");
|
let _ = stderr().write_all(b"unexpected option: ");
|
||||||
let _ = stderr().write_all(arg.as_bytes());
|
let _ = stderr().write_all(arg.as_bytes());
|
||||||
|
let _ = stderr().write_all(b"\n");
|
||||||
usage(1, &program, &mut stderr());
|
usage(1, &program, &mut stderr());
|
||||||
}
|
}
|
||||||
|
|
||||||
if path.is_some() {
|
nonopt_arg(arg);
|
||||||
let _ = stderr().write_all(b"unexpected extra parameter: ");
|
|
||||||
let _ = stderr().write_all(arg.as_bytes());
|
|
||||||
usage(1, &program, &mut stderr());
|
|
||||||
}
|
|
||||||
|
|
||||||
path = Some(arg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for arg in &mut args {
|
||||||
|
nonopt_arg(arg);
|
||||||
|
}
|
||||||
|
drop(nonopt_arg);
|
||||||
|
|
||||||
let path = match path {
|
let path = match path {
|
||||||
Some(path) => path,
|
Some(path) => path,
|
||||||
None => {
|
None => {
|
||||||
|
Loading…
Reference in New Issue
Block a user