remove shellwords crate
This commit is contained in:
parent
ca60ac13d9
commit
e399398444
@ -33,7 +33,6 @@ regex = "1.0"
|
|||||||
rustyline = "5.0.4"
|
rustyline = "5.0.4"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
shellwords = "1.0"
|
|
||||||
siphasher = "0.3"
|
siphasher = "0.3"
|
||||||
syslog = "4.0"
|
syslog = "4.0"
|
||||||
tokio = { version = "0.2.0-alpha.4" }
|
tokio = { version = "0.2.0-alpha.4" }
|
||||||
|
@ -314,25 +314,7 @@ pub fn print_bash_completion(def: &CommandLineInterface) {
|
|||||||
Err(_) => return,
|
Err(_) => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut args = match shellwords::split(&cmdline) {
|
let (_start, completions) = super::get_completions(def, &cmdline, true);
|
||||||
Ok(v) => v,
|
|
||||||
Err(_) => return,
|
|
||||||
};
|
|
||||||
|
|
||||||
if args.len() == 0 { return; }
|
|
||||||
|
|
||||||
args.remove(0); //no need for program name
|
|
||||||
|
|
||||||
if cmdline.ends_with(char::is_whitespace) {
|
|
||||||
//eprintln!("CMDLINE {:?}", cmdline);
|
|
||||||
args.push("".into());
|
|
||||||
}
|
|
||||||
|
|
||||||
let completions = if !args.is_empty() && args[0] == "help" {
|
|
||||||
get_help_completion(def, &help_command_def(), &args[1..])
|
|
||||||
} else {
|
|
||||||
get_nested_completion(def, &args)
|
|
||||||
};
|
|
||||||
|
|
||||||
for item in completions {
|
for item in completions {
|
||||||
println!("{}", item);
|
println!("{}", item);
|
||||||
|
@ -172,6 +172,39 @@ fn test_shellword_split_unclosed() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_completions(
|
||||||
|
cmd_def: &CommandLineInterface,
|
||||||
|
line: &str,
|
||||||
|
skip_first: bool,
|
||||||
|
) -> (usize, Vec<String>) {
|
||||||
|
|
||||||
|
let (mut args, start ) = match shellword_split_unclosed(line, false) {
|
||||||
|
(mut args, None) => {
|
||||||
|
args.push("".into());
|
||||||
|
(args, line.len())
|
||||||
|
}
|
||||||
|
(mut args, Some((start , arg, _quote))) => {
|
||||||
|
args.push(arg);
|
||||||
|
(args, start)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if skip_first {
|
||||||
|
|
||||||
|
if args.len() == 0 { return (0, Vec::new()); }
|
||||||
|
|
||||||
|
args.remove(0); // no need for program name
|
||||||
|
}
|
||||||
|
|
||||||
|
let completions = if !args.is_empty() && args[0] == "help" {
|
||||||
|
get_help_completion(cmd_def, &help_command_def(), &args[1..])
|
||||||
|
} else {
|
||||||
|
get_nested_completion(cmd_def, &args)
|
||||||
|
};
|
||||||
|
|
||||||
|
(start, completions)
|
||||||
|
}
|
||||||
|
|
||||||
pub struct CliHelper {
|
pub struct CliHelper {
|
||||||
cmd_def: CommandLineInterface,
|
cmd_def: CommandLineInterface,
|
||||||
}
|
}
|
||||||
@ -199,24 +232,7 @@ impl rustyline::completion::Completer for CliHelper {
|
|||||||
|
|
||||||
let line = &line[..pos];
|
let line = &line[..pos];
|
||||||
|
|
||||||
let (args, start ) = match shellword_split_unclosed(line, false) {
|
let (start, completions) = super::get_completions(&self.cmd_def, line, false);
|
||||||
(mut args, None) => {
|
|
||||||
args.push("".into());
|
|
||||||
(args, pos)
|
|
||||||
}
|
|
||||||
(mut args, Some((start , arg, _quote))) => {
|
|
||||||
args.push(arg);
|
|
||||||
(args, start)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let def = &self.cmd_def;
|
|
||||||
|
|
||||||
let completions = if !args.is_empty() && args[0] == "help" {
|
|
||||||
get_help_completion(&def, &help_command_def(), &args[1..])
|
|
||||||
} else {
|
|
||||||
get_nested_completion(&def, &args)
|
|
||||||
};
|
|
||||||
|
|
||||||
return Ok((start, completions));
|
return Ok((start, completions));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user