getopts: allow "-option" and "--option"
This commit is contained in:
parent
0c9ce2bbf0
commit
7556cab45e
|
@ -16,21 +16,24 @@ fn parse_argument(arg: &str) -> RawArgument {
|
||||||
|
|
||||||
let length = chars.len();
|
let length = chars.len();
|
||||||
|
|
||||||
if length >= 2 && chars[0] == '-' && chars[1] == '-' {
|
if length >= 2 {
|
||||||
|
|
||||||
if length == 2 { return RawArgument::Separator; }
|
if length == 2 { return RawArgument::Separator; }
|
||||||
|
|
||||||
for start in 2..length {
|
if chars[0] == '-' {
|
||||||
if chars[start] == '=' {
|
let first = if chars[1] == '-' { 2 } else { 1 };
|
||||||
let name: String = chars[2..start].iter().collect();
|
|
||||||
let value: String = chars[start+1..length].iter().collect();
|
for start in first..length {
|
||||||
return RawArgument::Option { name, value: Some(value) }
|
if chars[start] == '=' {
|
||||||
|
let name: String = chars[first..start].iter().collect();
|
||||||
|
let value: String = chars[start+1..length].iter().collect();
|
||||||
|
return RawArgument::Option { name, value: Some(value) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let name: String = chars[first..].iter().collect();
|
||||||
|
return RawArgument::Option { name: name, value: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
let name: String = chars[2..].iter().collect();
|
|
||||||
return RawArgument::Option { name: name, value: None }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RawArgument::Argument { value: arg.to_string() }
|
RawArgument::Argument { value: arg.to_string() }
|
||||||
|
|
Loading…
Reference in New Issue