tape: improve pmt command line completion
This commit is contained in:
parent
f4ba2e3155
commit
0d4e4cae7f
@ -48,6 +48,7 @@ pub const DRIVE_OPTION_SCHEMA: Schema = StringSchema::new(
|
|||||||
|
|
||||||
pub const DRIVE_OPTION_LIST_SCHEMA: Schema =
|
pub const DRIVE_OPTION_LIST_SCHEMA: Schema =
|
||||||
ArraySchema::new("Drive Option List.", &DRIVE_OPTION_SCHEMA)
|
ArraySchema::new("Drive Option List.", &DRIVE_OPTION_SCHEMA)
|
||||||
|
.min_length(1)
|
||||||
.schema();
|
.schema();
|
||||||
|
|
||||||
use proxmox_backup::{
|
use proxmox_backup::{
|
||||||
@ -702,25 +703,38 @@ fn status(param: Value) -> Result<(), Error> {
|
|||||||
schema: DRIVE_OPTION_LIST_SCHEMA,
|
schema: DRIVE_OPTION_LIST_SCHEMA,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
defaults: {
|
||||||
|
description: "Set default options (buffer-writes async-writes read-ahead can-bsr).",
|
||||||
|
type: bool,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
/// Set device driver options (root only)
|
/// Set device driver options (root only)
|
||||||
///
|
fn st_options(
|
||||||
/// If no options specified, we reset to default options
|
options: Option<Vec<String>>,
|
||||||
/// (buffer-writes async-writes read-ahead can-bsr)
|
defaults: Option<bool>,
|
||||||
fn st_options(options: Option<Vec<String>>, param: Value) -> Result<(), Error> {
|
param: Value) -> Result<(), Error> {
|
||||||
|
|
||||||
let handle = get_tape_handle(¶m)?;
|
let handle = get_tape_handle(¶m)?;
|
||||||
|
|
||||||
let options = options.unwrap_or_else(|| {
|
let options = match defaults {
|
||||||
let mut list = Vec::new();
|
Some(true) => {
|
||||||
list.push(String::from("buffer-writes"));
|
if options.is_some() {
|
||||||
list.push(String::from("async-writes"));
|
bail!("option --defaults conflicts with specified options");
|
||||||
list.push(String::from("read-ahead"));
|
}
|
||||||
list.push(String::from("can-bsr"));
|
let mut list = Vec::new();
|
||||||
list
|
list.push(String::from("buffer-writes"));
|
||||||
});
|
list.push(String::from("async-writes"));
|
||||||
|
list.push(String::from("read-ahead"));
|
||||||
|
list.push(String::from("can-bsr"));
|
||||||
|
list
|
||||||
|
}
|
||||||
|
Some(false) | None => {
|
||||||
|
options.unwrap_or_else(|| Vec::new())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let value = parse_drive_options(options)?;
|
let value = parse_drive_options(options)?;
|
||||||
|
|
||||||
@ -904,6 +918,7 @@ fn main() -> Result<(), Error> {
|
|||||||
CliCommand::new(method)
|
CliCommand::new(method)
|
||||||
.completion_cb("drive", complete_drive_name)
|
.completion_cb("drive", complete_drive_name)
|
||||||
.completion_cb("device", complete_drive_path)
|
.completion_cb("device", complete_drive_path)
|
||||||
|
.completion_cb("options", complete_option_name)
|
||||||
};
|
};
|
||||||
|
|
||||||
let cmd_def = CliCommandMap::new()
|
let cmd_def = CliCommandMap::new()
|
||||||
@ -939,3 +954,11 @@ fn main() -> Result<(), Error> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Completion helpers
|
||||||
|
pub fn complete_option_name(_arg: &str, _param: &HashMap<String, String>) -> Vec<String> {
|
||||||
|
DRIVE_OPTIONS
|
||||||
|
.keys()
|
||||||
|
.map(String::from)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user