Add argument finder helper function
This commit is contained in:
parent
580c9e5286
commit
eca41e04dd
1 changed files with 9 additions and 0 deletions
|
@ -98,6 +98,14 @@ fn find_command() -> Option<String> {
|
||||||
env::args().skip(1).filter(|x| !x.starts_with("-")).next()
|
env::args().skip(1).filter(|x| !x.starts_with("-")).next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn find_args(command: &str) -> Vec<String> {
|
||||||
|
env::args()
|
||||||
|
.skip(1)
|
||||||
|
.position(|e| e == command)
|
||||||
|
.map(|pos| env::args().skip(pos + 2).collect::<Vec<String>>())
|
||||||
|
.unwrap_or(vec![])
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let commands = get_commands();
|
let commands = get_commands();
|
||||||
let mut args = env::args();
|
let mut args = env::args();
|
||||||
|
@ -145,6 +153,7 @@ fn main() {
|
||||||
.stdin(Stdio::inherit())
|
.stdin(Stdio::inherit())
|
||||||
.stdout(Stdio::inherit())
|
.stdout(Stdio::inherit())
|
||||||
.stderr(Stdio::inherit())
|
.stderr(Stdio::inherit())
|
||||||
|
.args(&find_args(s)[..])
|
||||||
.spawn()
|
.spawn()
|
||||||
.and_then(|mut handle| handle.wait())
|
.and_then(|mut handle| handle.wait())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue