remove shellwords crate

This commit is contained in:
Dietmar Maurer 2019-11-29 12:43:29 +01:00
parent ca60ac13d9
commit e399398444
3 changed files with 35 additions and 38 deletions

View File

@ -33,7 +33,6 @@ regex = "1.0"
rustyline = "5.0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
shellwords = "1.0"
siphasher = "0.3"
syslog = "4.0"
tokio = { version = "0.2.0-alpha.4" }

View File

@ -314,25 +314,7 @@ pub fn print_bash_completion(def: &CommandLineInterface) {
Err(_) => return,
};
let mut args = match shellwords::split(&cmdline) {
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)
};
let (_start, completions) = super::get_completions(def, &cmdline, true);
for item in completions {
println!("{}", item);

View File

@ -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 {
cmd_def: CommandLineInterface,
}
@ -199,24 +232,7 @@ impl rustyline::completion::Completer for CliHelper {
let line = &line[..pos];
let (args, start ) = match shellword_split_unclosed(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)
};
let (start, completions) = super::get_completions(&self.cmd_def, line, false);
return Ok((start, completions));
}