proxmox-backup-manager: add completion helper for port list

This commit is contained in:
Dietmar Maurer 2020-05-08 17:28:04 +02:00
parent 525008f7ad
commit 65dab0266c
2 changed files with 23 additions and 0 deletions

View File

@ -365,6 +365,8 @@ fn network_commands() -> CommandLineInterface {
.fixed_param("node", String::from("localhost"))
.arg_param(&["iface"])
.completion_cb("iface", config::network::complete_interface_name)
.completion_cb("bridge_ports", config::network::complete_port_list)
.completion_cb("slaves", config::network::complete_port_list)
)
.insert(
"update",
@ -372,6 +374,8 @@ fn network_commands() -> CommandLineInterface {
.fixed_param("node", String::from("localhost"))
.arg_param(&["iface"])
.completion_cb("iface", config::network::complete_interface_name)
.completion_cb("bridge_ports", config::network::complete_port_list)
.completion_cb("slaves", config::network::complete_port_list)
)
.insert(
"remove",

View File

@ -532,6 +532,25 @@ pub fn complete_interface_name(_arg: &str, _param: &HashMap<String, String>) ->
}
}
pub fn complete_port_list(arg: &str, _param: &HashMap<String, String>) -> Vec<String> {
let mut ports = Vec::new();
match config() {
Ok((data, _digest)) => {
for (iface, interface) in data.interfaces.iter() {
if interface.interface_type == NetworkInterfaceType::Eth {
ports.push(iface.to_string());
}
}
}
Err(_) => return vec![],
};
let arg = arg.clone().trim();
let prefix = if let Some(idx) = arg.rfind(",") { &arg[..idx+1] } else { "" };
ports.iter().map(|port| format!("{}{}", prefix, port)).collect()
}
#[cfg(test)]
mod test {