src/cli/command.rs: use static array for arg_param
This commit is contained in:
parent
329d40b50b
commit
49fddd985c
@ -1566,7 +1566,7 @@ fn key_mgmt_cli() -> CliCommandMap {
|
||||
);
|
||||
|
||||
let key_create_cmd_def = CliCommand::new(&API_METHOD_KEY_CREATE)
|
||||
.arg_param(vec!["path"])
|
||||
.arg_param(&["path"])
|
||||
.completion_cb("path", tools::complete_file_name);
|
||||
|
||||
#[sortable]
|
||||
@ -1582,7 +1582,7 @@ fn key_mgmt_cli() -> CliCommandMap {
|
||||
);
|
||||
|
||||
let key_change_passphrase_cmd_def = CliCommand::new(&API_METHOD_KEY_CHANGE_PASSPHRASE)
|
||||
.arg_param(vec!["path"])
|
||||
.arg_param(&["path"])
|
||||
.completion_cb("path", tools::complete_file_name);
|
||||
|
||||
const API_METHOD_KEY_CREATE_MASTER_KEY: ApiMethod = ApiMethod::new(
|
||||
@ -1602,7 +1602,7 @@ fn key_mgmt_cli() -> CliCommandMap {
|
||||
);
|
||||
|
||||
let key_import_master_pubkey_cmd_def = CliCommand::new(&API_METHOD_KEY_IMPORT_MASTER_PUBKEY)
|
||||
.arg_param(vec!["path"])
|
||||
.arg_param(&["path"])
|
||||
.completion_cb("path", tools::complete_file_name);
|
||||
|
||||
CliCommandMap::new()
|
||||
@ -1948,7 +1948,7 @@ fn main() {
|
||||
);
|
||||
|
||||
let backup_cmd_def = CliCommand::new(&API_METHOD_CREATE_BACKUP)
|
||||
.arg_param(vec!["backupspec"])
|
||||
.arg_param(&["backupspec"])
|
||||
.completion_cb("repository", complete_repository)
|
||||
.completion_cb("backupspec", complete_backup_source)
|
||||
.completion_cb("keyfile", tools::complete_file_name)
|
||||
@ -1985,7 +1985,7 @@ fn main() {
|
||||
);
|
||||
|
||||
let upload_log_cmd_def = CliCommand::new(&API_METHOD_UPLOAD_LOG)
|
||||
.arg_param(vec!["snapshot", "logfile"])
|
||||
.arg_param(&["snapshot", "logfile"])
|
||||
.completion_cb("snapshot", complete_backup_snapshot)
|
||||
.completion_cb("logfile", tools::complete_file_name)
|
||||
.completion_cb("keyfile", tools::complete_file_name)
|
||||
@ -2020,7 +2020,7 @@ fn main() {
|
||||
);
|
||||
|
||||
let snapshots_cmd_def = CliCommand::new(&API_METHOD_LIST_SNAPSHOTS)
|
||||
.arg_param(vec!["group"])
|
||||
.arg_param(&["group"])
|
||||
.completion_cb("group", complete_backup_group)
|
||||
.completion_cb("repository", complete_repository);
|
||||
|
||||
@ -2037,7 +2037,7 @@ fn main() {
|
||||
);
|
||||
|
||||
let forget_cmd_def = CliCommand::new(&API_METHOD_FORGET_SNAPSHOTS)
|
||||
.arg_param(vec!["snapshot"])
|
||||
.arg_param(&["snapshot"])
|
||||
.completion_cb("repository", complete_repository)
|
||||
.completion_cb("snapshot", complete_backup_snapshot);
|
||||
|
||||
@ -2093,7 +2093,7 @@ We do not extraxt '.pxar' archives when writing to stdandard output.
|
||||
);
|
||||
|
||||
let restore_cmd_def = CliCommand::new(&API_METHOD_RESTORE)
|
||||
.arg_param(vec!["snapshot", "archive-name", "target"])
|
||||
.arg_param(&["snapshot", "archive-name", "target"])
|
||||
.completion_cb("repository", complete_repository)
|
||||
.completion_cb("snapshot", complete_group_or_snapshot)
|
||||
.completion_cb("archive-name", complete_archive_name)
|
||||
@ -2113,7 +2113,7 @@ We do not extraxt '.pxar' archives when writing to stdandard output.
|
||||
);
|
||||
|
||||
let files_cmd_def = CliCommand::new(&API_METHOD_LIST_SNAPSHOT_FILES)
|
||||
.arg_param(vec!["snapshot"])
|
||||
.arg_param(&["snapshot"])
|
||||
.completion_cb("repository", complete_repository)
|
||||
.completion_cb("snapshot", complete_backup_snapshot);
|
||||
|
||||
@ -2130,7 +2130,7 @@ We do not extraxt '.pxar' archives when writing to stdandard output.
|
||||
);
|
||||
|
||||
let catalog_cmd_def = CliCommand::new(&API_METHOD_DUMP_CATALOG)
|
||||
.arg_param(vec!["snapshot"])
|
||||
.arg_param(&["snapshot"])
|
||||
.completion_cb("repository", complete_repository)
|
||||
.completion_cb("snapshot", complete_backup_snapshot);
|
||||
|
||||
@ -2147,7 +2147,7 @@ We do not extraxt '.pxar' archives when writing to stdandard output.
|
||||
);
|
||||
|
||||
let prune_cmd_def = CliCommand::new(&API_METHOD_PRUNE)
|
||||
.arg_param(vec!["group"])
|
||||
.arg_param(&["group"])
|
||||
.completion_cb("group", complete_backup_group)
|
||||
.completion_cb("repository", complete_repository);
|
||||
|
||||
@ -2207,7 +2207,7 @@ We do not extraxt '.pxar' archives when writing to stdandard output.
|
||||
);
|
||||
|
||||
let mount_cmd_def = CliCommand::new(&API_METHOD_MOUNT)
|
||||
.arg_param(vec!["snapshot", "archive-name", "target"])
|
||||
.arg_param(&["snapshot", "archive-name", "target"])
|
||||
.completion_cb("repository", complete_repository)
|
||||
.completion_cb("snapshot", complete_group_or_snapshot)
|
||||
.completion_cb("archive-name", complete_archive_name)
|
||||
@ -2228,7 +2228,7 @@ We do not extraxt '.pxar' archives when writing to stdandard output.
|
||||
);
|
||||
|
||||
let shell_cmd_def = CliCommand::new(&API_METHOD_SHELL)
|
||||
.arg_param(vec!["snapshot", "archive-name"])
|
||||
.arg_param(&["snapshot", "archive-name"])
|
||||
.completion_cb("repository", complete_repository)
|
||||
.completion_cb("archive-name", complete_archive_name)
|
||||
.completion_cb("snapshot", complete_group_or_snapshot);
|
||||
|
@ -12,11 +12,11 @@ fn datastore_commands() -> CommandLineInterface {
|
||||
.insert("list", CliCommand::new(&api2::config::datastore::GET).into())
|
||||
.insert("create",
|
||||
CliCommand::new(&api2::config::datastore::POST)
|
||||
.arg_param(vec!["name", "path"])
|
||||
.arg_param(&["name", "path"])
|
||||
.into())
|
||||
.insert("remove",
|
||||
CliCommand::new(&api2::config::datastore::DELETE)
|
||||
.arg_param(vec!["name"])
|
||||
.arg_param(&["name"])
|
||||
.completion_cb("name", config::datastore::complete_datastore_name)
|
||||
.into());
|
||||
|
||||
@ -33,12 +33,12 @@ fn garbage_collection_commands() -> CommandLineInterface {
|
||||
let cmd_def = CliCommandMap::new()
|
||||
.insert("status",
|
||||
CliCommand::new(&api2::admin::datastore::API_METHOD_GARBAGE_COLLECTION_STATUS)
|
||||
.arg_param(vec!["store"])
|
||||
.arg_param(&["store"])
|
||||
.completion_cb("store", config::datastore::complete_datastore_name)
|
||||
.into())
|
||||
.insert("start",
|
||||
CliCommand::new(&api2::admin::datastore::API_METHOD_START_GARBAGE_COLLECTION)
|
||||
.arg_param(vec!["store"])
|
||||
.arg_param(&["store"])
|
||||
.completion_cb("store", config::datastore::complete_datastore_name)
|
||||
.into());
|
||||
|
||||
|
@ -487,26 +487,26 @@ fn main() {
|
||||
|
||||
let cmd_def = CliCommandMap::new()
|
||||
.insert("create", CliCommand::new(&API_METHOD_CREATE_ARCHIVE)
|
||||
.arg_param(vec!["archive", "source", "exclude"])
|
||||
.arg_param(&["archive", "source", "exclude"])
|
||||
.completion_cb("archive", tools::complete_file_name)
|
||||
.completion_cb("source", tools::complete_file_name)
|
||||
.into()
|
||||
)
|
||||
.insert("extract", CliCommand::new(&API_METHOD_EXTRACT_ARCHIVE)
|
||||
.arg_param(vec!["archive", "pattern"])
|
||||
.arg_param(&["archive", "pattern"])
|
||||
.completion_cb("archive", tools::complete_file_name)
|
||||
.completion_cb("target", tools::complete_file_name)
|
||||
.completion_cb("files-from", tools::complete_file_name)
|
||||
.into()
|
||||
)
|
||||
.insert("mount", CliCommand::new(&API_METHOD_MOUNT_ARCHIVE)
|
||||
.arg_param(vec!["archive", "mountpoint"])
|
||||
.arg_param(&["archive", "mountpoint"])
|
||||
.completion_cb("archive", tools::complete_file_name)
|
||||
.completion_cb("mountpoint", tools::complete_file_name)
|
||||
.into()
|
||||
)
|
||||
.insert("list", CliCommand::new(&API_METHOD_DUMP_ARCHIVE)
|
||||
.arg_param(vec!["archive"])
|
||||
.arg_param(&["archive"])
|
||||
.completion_cb("archive", tools::complete_file_name)
|
||||
.into()
|
||||
);
|
||||
|
@ -38,7 +38,7 @@ fn generate_usage_str(
|
||||
format: DocumentationFormat,
|
||||
indent: &str) -> String {
|
||||
|
||||
let arg_param = &cli_cmd.arg_param;
|
||||
let arg_param = cli_cmd.arg_param;
|
||||
let fixed_param = &cli_cmd.fixed_param;
|
||||
let schema = cli_cmd.info.parameters;
|
||||
|
||||
@ -171,7 +171,7 @@ fn handle_simple_command(
|
||||
) {
|
||||
|
||||
let (params, rest) = match getopts::parse_arguments(
|
||||
&args, &cli_cmd.arg_param, &cli_cmd.info.parameters) {
|
||||
&args, cli_cmd.arg_param, &cli_cmd.info.parameters) {
|
||||
Ok((p, r)) => (p, r),
|
||||
Err(err) => {
|
||||
print_simple_usage_error(prefix, cli_cmd, err.into());
|
||||
@ -415,7 +415,7 @@ fn print_help_completion(def: &CommandLineInterface, help_cmd: &CliCommand, args
|
||||
|
||||
match def {
|
||||
CommandLineInterface::Simple(_) => {
|
||||
print_simple_completion(help_cmd, &mut done, &help_cmd.arg_param, &help_cmd.arg_param, args);
|
||||
print_simple_completion(help_cmd, &mut done, help_cmd.arg_param, &help_cmd.arg_param, args);
|
||||
}
|
||||
CommandLineInterface::Nested(map) => {
|
||||
if args.is_empty() {
|
||||
@ -428,7 +428,7 @@ fn print_help_completion(def: &CommandLineInterface, help_cmd: &CliCommand, args
|
||||
let first = &args[0];
|
||||
|
||||
if first.starts_with("-") {
|
||||
print_simple_completion(help_cmd, &mut done, &help_cmd.arg_param, &help_cmd.arg_param, args);
|
||||
print_simple_completion(help_cmd, &mut done, help_cmd.arg_param, &help_cmd.arg_param, args);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -454,7 +454,7 @@ fn print_nested_completion(def: &CommandLineInterface, args: &[String]) {
|
||||
cli_cmd.fixed_param.iter().for_each(|(key, value)| {
|
||||
record_done_argument(&mut done, &cli_cmd.info.parameters, &key, &value);
|
||||
});
|
||||
print_simple_completion(cli_cmd, &mut done, &cli_cmd.arg_param, &cli_cmd.arg_param, args);
|
||||
print_simple_completion(cli_cmd, &mut done, cli_cmd.arg_param, &cli_cmd.arg_param, args);
|
||||
}
|
||||
CommandLineInterface::Nested(map) => {
|
||||
if args.is_empty() {
|
||||
@ -576,7 +576,7 @@ pub type CompletionFunction = fn(&str, &HashMap<String, String>) -> Vec<String>;
|
||||
|
||||
pub struct CliCommand {
|
||||
pub info: &'static ApiMethod,
|
||||
pub arg_param: Vec<&'static str>,
|
||||
pub arg_param: &'static [&'static str],
|
||||
pub fixed_param: HashMap<&'static str, String>,
|
||||
pub completion_functions: HashMap<String, CompletionFunction>,
|
||||
}
|
||||
@ -585,13 +585,13 @@ impl CliCommand {
|
||||
|
||||
pub fn new(info: &'static ApiMethod) -> Self {
|
||||
Self {
|
||||
info, arg_param: vec![],
|
||||
info, arg_param: &[],
|
||||
fixed_param: HashMap::new(),
|
||||
completion_functions: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn arg_param(mut self, names: Vec<&'static str>) -> Self {
|
||||
pub fn arg_param(mut self, names: &'static [&'static str]) -> Self {
|
||||
self.arg_param = names;
|
||||
self
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ pub (crate) fn parse_argument_list<T: AsRef<str>>(
|
||||
/// list of additional command line arguments.
|
||||
pub fn parse_arguments<T: AsRef<str>>(
|
||||
args: &[T],
|
||||
arg_param: &Vec<&'static str>,
|
||||
arg_param: &[&str],
|
||||
schema: &ObjectSchema,
|
||||
) -> Result<(Value, Vec<String>), ParameterError> {
|
||||
let mut errors = ParameterError::new();
|
||||
|
Loading…
Reference in New Issue
Block a user