Merge pull request #564 from Geemili/bin/debug-fowarding
Fix flags for root command not working; Added in debug forwarding
This commit is contained in:
commit
96deecf91f
1 changed files with 22 additions and 4 deletions
|
@ -11,6 +11,8 @@ use std::io::ErrorKind;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
use crossbeam::*;
|
use crossbeam::*;
|
||||||
|
|
||||||
|
const DBG_FLAG: &'static str = "--debug";
|
||||||
|
|
||||||
fn help(cmds: Vec<String>) {
|
fn help(cmds: Vec<String>) {
|
||||||
println!(r#"
|
println!(r#"
|
||||||
|
|
||||||
|
@ -99,6 +101,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_flag() -> Option<String> {
|
||||||
|
env::args().skip(1).filter(|x| x.starts_with("-")).next()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_debug_flag<T: AsRef<str>>(ref s: &T) -> bool {
|
||||||
|
s.as_ref() == DBG_FLAG
|
||||||
|
}
|
||||||
|
|
||||||
fn find_args(command: &str) -> Vec<String> {
|
fn find_args(command: &str) -> Vec<String> {
|
||||||
env::args()
|
env::args()
|
||||||
.skip(1)
|
.skip(1)
|
||||||
|
@ -112,12 +122,16 @@ fn main() {
|
||||||
let mut args = env::args();
|
let mut args = env::args();
|
||||||
let _ = args.next();
|
let _ = args.next();
|
||||||
let first_arg = match find_command() {
|
let first_arg = match find_command() {
|
||||||
|
Some(s) => s,
|
||||||
|
None => match find_flag() {
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
None => {
|
None => {
|
||||||
help(commands);
|
help(commands);
|
||||||
exit(0);
|
exit(0);
|
||||||
},
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
let is_debug = env::args().skip(1).find(is_debug_flag).is_some();
|
||||||
|
|
||||||
match &first_arg[..] {
|
match &first_arg[..] {
|
||||||
"--help" | "-h" => {
|
"--help" | "-h" => {
|
||||||
|
@ -150,11 +164,15 @@ fn main() {
|
||||||
},
|
},
|
||||||
|
|
||||||
s => {
|
s => {
|
||||||
|
let mut subcommand_args = find_args(s);
|
||||||
|
if is_debug && subcommand_args.iter().find(is_debug_flag).is_none() {
|
||||||
|
subcommand_args.insert(0, String::from(DBG_FLAG));
|
||||||
|
}
|
||||||
match Command::new(format!("imag-{}", s))
|
match Command::new(format!("imag-{}", s))
|
||||||
.stdin(Stdio::inherit())
|
.stdin(Stdio::inherit())
|
||||||
.stdout(Stdio::inherit())
|
.stdout(Stdio::inherit())
|
||||||
.stderr(Stdio::inherit())
|
.stderr(Stdio::inherit())
|
||||||
.args(&find_args(s)[..])
|
.args(&subcommand_args[..])
|
||||||
.spawn()
|
.spawn()
|
||||||
.and_then(|mut handle| handle.wait())
|
.and_then(|mut handle| handle.wait())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue