proxmox-backup-manager: add completion helper for port list
This commit is contained in:
parent
525008f7ad
commit
65dab0266c
|
@ -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",
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
Loading…
Reference in New Issue