mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-07 09:51:39 +00:00
improve command line completion with optional argument parameters
This commit is contained in:
parent
ab8a6120ca
commit
75e4c4a205
@ -73,30 +73,36 @@ fn get_simple_completion(
|
|||||||
arg_param: &[&str], // we remove done arguments
|
arg_param: &[&str], // we remove done arguments
|
||||||
args: &[String],
|
args: &[String],
|
||||||
) -> Vec<String> {
|
) -> Vec<String> {
|
||||||
// fixme: arg_param, fixed_param
|
|
||||||
//eprintln!("COMPL: {:?} {:?} {}", arg_param, args, args.len());
|
//eprintln!("COMPL: {:?} {:?} {}", arg_param, args, args.len());
|
||||||
|
|
||||||
if !arg_param.is_empty() {
|
if !arg_param.is_empty() {
|
||||||
let prop_name = arg_param[0];
|
let prop_name = arg_param[0];
|
||||||
if args.len() > 1 {
|
if let Some((optional, schema)) = cli_cmd.info.parameters.lookup(prop_name) {
|
||||||
record_done_argument(done, cli_cmd.info.parameters, prop_name, &args[0]);
|
if optional && args[0].starts_with('-') {
|
||||||
return get_simple_completion(cli_cmd, done, &arg_param[1..], &args[1..]);
|
// argument parameter is optional, and arg looks like an option,
|
||||||
}
|
// so assume its empty and complete the rest
|
||||||
|
} else {
|
||||||
|
record_done_argument(done, cli_cmd.info.parameters, prop_name, &args[0]);
|
||||||
|
if args.len() > 1 {
|
||||||
|
return get_simple_completion(cli_cmd, done, &arg_param[1..], &args[1..]);
|
||||||
|
}
|
||||||
|
|
||||||
if args.len() == 1 {
|
if args.len() == 1 {
|
||||||
record_done_argument(done, cli_cmd.info.parameters, prop_name, &args[0]);
|
return get_property_completion(
|
||||||
if let Some((_, schema)) = cli_cmd.info.parameters.lookup(prop_name) {
|
schema,
|
||||||
return get_property_completion(
|
prop_name,
|
||||||
schema,
|
&cli_cmd.completion_functions,
|
||||||
prop_name,
|
&args[0],
|
||||||
&cli_cmd.completion_functions,
|
done,
|
||||||
&args[0],
|
);
|
||||||
done,
|
}
|
||||||
);
|
|
||||||
|
return Vec::new();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// unknown arg_param - should never happen
|
||||||
|
return Vec::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Vec::new();
|
|
||||||
}
|
}
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user