diff --git a/Cargo.toml b/Cargo.toml index 772588f6..29b854af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -100,7 +100,7 @@ proxmox = { version = "0.14.0", features = [ "sortable-macro" ] } proxmox-http = { version = "0.5.0", features = [ "client", "http-helpers", "websocket" ] } proxmox-io = "1" proxmox-lang = "1" -proxmox-router = { version = "1", features = [ "cli" ] } +proxmox-router = { version = "1.1", features = [ "cli" ] } proxmox-schema = { version = "1", features = [ "api-macro" ] } proxmox-section-config = "1" proxmox-tfa = { version = "1", features = [ "u2f" ] } diff --git a/pbs-client/Cargo.toml b/pbs-client/Cargo.toml index 272cf356..c8a93b30 100644 --- a/pbs-client/Cargo.toml +++ b/pbs-client/Cargo.toml @@ -33,7 +33,7 @@ proxmox-fuse = "0.1.1" proxmox-http = { version = "0.5.0", features = [ "client", "http-helpers", "websocket" ] } proxmox-io = { version = "1", features = [ "tokio" ] } proxmox-lang = "1" -proxmox-router = { version = "1", features = [ "cli" ] } +proxmox-router = { version = "1.1", features = [ "cli" ] } proxmox-schema = "1" proxmox-time = "1" pxar = { version = "0.10.1", features = [ "tokio-io" ] } diff --git a/pbs-client/src/catalog_shell.rs b/pbs-client/src/catalog_shell.rs index 16595b41..dbc23ef6 100644 --- a/pbs-client/src/catalog_shell.rs +++ b/pbs-client/src/catalog_shell.rs @@ -79,13 +79,13 @@ pub fn catalog_shell_cli() -> CommandLineInterface { "restore-selected", CliCommand::new(&API_METHOD_RESTORE_SELECTED_COMMAND) .arg_param(&["target"]) - .completion_cb("target", pbs_tools::fs::complete_file_name), + .completion_cb("target", cli::complete_file_name), ) .insert( "restore", CliCommand::new(&API_METHOD_RESTORE_COMMAND) .arg_param(&["target"]) - .completion_cb("target", pbs_tools::fs::complete_file_name), + .completion_cb("target", cli::complete_file_name), ) .insert( "find", diff --git a/pbs-client/src/tools/mod.rs b/pbs-client/src/tools/mod.rs index f6ae4bcd..a12635cf 100644 --- a/pbs-client/src/tools/mod.rs +++ b/pbs-client/src/tools/mod.rs @@ -11,7 +11,7 @@ use serde_json::{json, Value}; use xdg::BaseDirectories; use proxmox_schema::*; -use proxmox_router::cli::shellword_split; +use proxmox_router::cli::{complete_file_name, shellword_split}; use proxmox::tools::fs::file_get_json; use pbs_api_types::{BACKUP_REPO_URL, Authid, UserWithTokens}; @@ -411,7 +411,7 @@ pub fn complete_backup_source(arg: &str, param: &HashMap) -> Vec return result; } - let files = pbs_tools::fs::complete_file_name(data[1], param); + let files = complete_file_name(data[1], param); for file in files { result.push(format!("{}:{}", data[0], file)); diff --git a/pbs-config/Cargo.toml b/pbs-config/Cargo.toml index 1e9d8ce1..e8caeb12 100644 --- a/pbs-config/Cargo.toml +++ b/pbs-config/Cargo.toml @@ -19,7 +19,7 @@ serde_json = "1.0" proxmox = "0.14.0" proxmox-lang = "1" -proxmox-router = { version = "1", default-features = false } +proxmox-router = { version = "1.1", default-features = false } proxmox-schema = "1" proxmox-section-config = "1" proxmox-time = "1" diff --git a/pbs-tape/Cargo.toml b/pbs-tape/Cargo.toml index 94be071d..f65bf852 100644 --- a/pbs-tape/Cargo.toml +++ b/pbs-tape/Cargo.toml @@ -27,7 +27,7 @@ proxmox-time = "1" proxmox-uuid = "1" # router::cli is only used by binaries, so maybe we should split them out -proxmox-router = "1" +proxmox-router = "1.1" pbs-api-types = { path = "../pbs-api-types" } pbs-tools = { path = "../pbs-tools" } diff --git a/pbs-tools/src/fs.rs b/pbs-tools/src/fs.rs index 4af75e1d..b2bd152c 100644 --- a/pbs-tools/src/fs.rs +++ b/pbs-tools/src/fs.rs @@ -1,9 +1,7 @@ //! File system helper utilities. use std::borrow::{Borrow, BorrowMut}; -use std::collections::HashMap; use std::fs::File; -use std::hash::BuildHasher; use std::io::{self, BufRead}; use std::ops::{Deref, DerefMut}; use std::os::unix::io::{AsRawFd, RawFd}; @@ -12,7 +10,7 @@ use std::path::Path; use anyhow::{bail, format_err, Error}; use nix::dir; use nix::dir::Dir; -use nix::fcntl::{AtFlags, OFlag}; +use nix::fcntl::OFlag; use nix::sys::stat::Mode; use regex::Regex; @@ -350,61 +348,6 @@ fn do_lock_dir_noblock( Ok(handle) } -pub fn complete_file_name(arg: &str, _param: &HashMap) -> Vec -where - S: BuildHasher, -{ - let mut result = vec![]; - - let mut dirname = std::path::PathBuf::from(if arg.is_empty() { "./" } else { arg }); - - let is_dir = match nix::sys::stat::fstatat(libc::AT_FDCWD, &dirname, AtFlags::empty()) { - Ok(stat) => (stat.st_mode & libc::S_IFMT) == libc::S_IFDIR, - Err(_) => false, - }; - - if !is_dir { - if let Some(parent) = dirname.parent() { - dirname = parent.to_owned(); - } - } - - let mut dir = - match nix::dir::Dir::openat(libc::AT_FDCWD, &dirname, OFlag::O_DIRECTORY, Mode::empty()) { - Ok(d) => d, - Err(_) => return result, - }; - - for item in dir.iter() { - if let Ok(entry) = item { - if let Ok(name) = entry.file_name().to_str() { - if name == "." || name == ".." { - continue; - } - let mut newpath = dirname.clone(); - newpath.push(name); - - if let Ok(stat) = - nix::sys::stat::fstatat(libc::AT_FDCWD, &newpath, AtFlags::empty()) - { - if (stat.st_mode & libc::S_IFMT) == libc::S_IFDIR { - newpath.push(""); - if let Some(newpath) = newpath.to_str() { - result.push(newpath.to_owned()); - } - continue; - } - } - if let Some(newpath) = newpath.to_str() { - result.push(newpath.to_owned()); - } - } - } - } - - result -} - /// Get an iterator over lines of a file, skipping empty lines and comments (lines starting with a /// `#`). pub fn file_get_non_comment_lines>( diff --git a/proxmox-backup-client/Cargo.toml b/proxmox-backup-client/Cargo.toml index 0b84e176..e4e135e8 100644 --- a/proxmox-backup-client/Cargo.toml +++ b/proxmox-backup-client/Cargo.toml @@ -23,7 +23,7 @@ pathpatterns = "0.1.2" pxar = { version = "0.10.1", features = [ "tokio-io" ] } proxmox = { version = "0.14.0", features = [ "sortable-macro" ] } -proxmox-router = { version = "1", features = [ "cli" ] } +proxmox-router = { version = "1.1", features = [ "cli" ] } proxmox-schema = { version = "1", features = [ "api-macro" ] } proxmox-time = "1" diff --git a/proxmox-backup-client/src/key.rs b/proxmox-backup-client/src/key.rs index 89bbed50..2984c581 100644 --- a/proxmox-backup-client/src/key.rs +++ b/proxmox-backup-client/src/key.rs @@ -7,7 +7,8 @@ use serde_json::Value; use proxmox::sys::linux::tty; use proxmox::tools::fs::{file_get_contents, replace_file, CreateOptions}; use proxmox_router::cli::{ - format_and_print_result_full, get_output_format, CliCommand, CliCommandMap, ColumnConfig, + complete_file_name, format_and_print_result_full, get_output_format, + CliCommand, CliCommandMap, ColumnConfig, OUTPUT_FORMAT, }; use proxmox_schema::{api, ApiType, ReturnType}; @@ -451,35 +452,35 @@ fn paper_key( pub fn cli() -> CliCommandMap { let key_create_cmd_def = CliCommand::new(&API_METHOD_CREATE) .arg_param(&["path"]) - .completion_cb("path", pbs_tools::fs::complete_file_name); + .completion_cb("path", complete_file_name); let key_import_with_master_key_cmd_def = CliCommand::new(&API_METHOD_IMPORT_WITH_MASTER_KEY) .arg_param(&["master-keyfile"]) - .completion_cb("master-keyfile", pbs_tools::fs::complete_file_name) + .completion_cb("master-keyfile", complete_file_name) .arg_param(&["encrypted-keyfile"]) - .completion_cb("encrypted-keyfile", pbs_tools::fs::complete_file_name) + .completion_cb("encrypted-keyfile", complete_file_name) .arg_param(&["path"]) - .completion_cb("path", pbs_tools::fs::complete_file_name); + .completion_cb("path", complete_file_name); let key_change_passphrase_cmd_def = CliCommand::new(&API_METHOD_CHANGE_PASSPHRASE) .arg_param(&["path"]) - .completion_cb("path", pbs_tools::fs::complete_file_name); + .completion_cb("path", complete_file_name); let key_create_master_key_cmd_def = CliCommand::new(&API_METHOD_CREATE_MASTER_KEY); let key_import_master_pubkey_cmd_def = CliCommand::new(&API_METHOD_IMPORT_MASTER_PUBKEY) .arg_param(&["path"]) - .completion_cb("path", pbs_tools::fs::complete_file_name); + .completion_cb("path", complete_file_name); let key_show_master_pubkey_cmd_def = CliCommand::new(&API_METHOD_SHOW_MASTER_PUBKEY) .arg_param(&["path"]) - .completion_cb("path", pbs_tools::fs::complete_file_name); + .completion_cb("path", complete_file_name); let key_show_cmd_def = CliCommand::new(&API_METHOD_SHOW_KEY) .arg_param(&["path"]) - .completion_cb("path", pbs_tools::fs::complete_file_name); + .completion_cb("path", complete_file_name); let paper_key_cmd_def = CliCommand::new(&API_METHOD_PAPER_KEY) .arg_param(&["path"]) - .completion_cb("path", pbs_tools::fs::complete_file_name); + .completion_cb("path", complete_file_name); CliCommandMap::new() .insert("create", key_create_cmd_def) diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs index 12deb43c..0ad16b42 100644 --- a/proxmox-backup-client/src/main.rs +++ b/proxmox-backup-client/src/main.rs @@ -1429,13 +1429,13 @@ fn main() { .arg_param(&["backupspec"]) .completion_cb("repository", complete_repository) .completion_cb("backupspec", complete_backup_source) - .completion_cb("keyfile", pbs_tools::fs::complete_file_name) - .completion_cb("master-pubkey-file", pbs_tools::fs::complete_file_name) + .completion_cb("keyfile", complete_file_name) + .completion_cb("master-pubkey-file", complete_file_name) .completion_cb("chunk-size", complete_chunk_size); let benchmark_cmd_def = CliCommand::new(&API_METHOD_BENCHMARK) .completion_cb("repository", complete_repository) - .completion_cb("keyfile", pbs_tools::fs::complete_file_name); + .completion_cb("keyfile", complete_file_name); let list_cmd_def = CliCommand::new(&API_METHOD_LIST_BACKUP_GROUPS) .completion_cb("repository", complete_repository); @@ -1448,7 +1448,7 @@ fn main() { .completion_cb("repository", complete_repository) .completion_cb("snapshot", complete_group_or_snapshot) .completion_cb("archive-name", complete_archive_name) - .completion_cb("target", pbs_tools::fs::complete_file_name); + .completion_cb("target", complete_file_name); let prune_cmd_def = CliCommand::new(&API_METHOD_PRUNE) .arg_param(&["group"]) diff --git a/proxmox-backup-client/src/mount.rs b/proxmox-backup-client/src/mount.rs index 1971eb12..265622f3 100644 --- a/proxmox-backup-client/src/mount.rs +++ b/proxmox-backup-client/src/mount.rs @@ -94,7 +94,7 @@ pub fn mount_cmd_def() -> CliCommand { .completion_cb("repository", complete_repository) .completion_cb("snapshot", complete_group_or_snapshot) .completion_cb("archive-name", complete_pxar_archive_name) - .completion_cb("target", pbs_tools::fs::complete_file_name) + .completion_cb("target", complete_file_name) } pub fn map_cmd_def() -> CliCommand { diff --git a/proxmox-backup-client/src/snapshot.rs b/proxmox-backup-client/src/snapshot.rs index 1e809d3f..6b563d79 100644 --- a/proxmox-backup-client/src/snapshot.rs +++ b/proxmox-backup-client/src/snapshot.rs @@ -403,8 +403,8 @@ pub fn snapshot_mgtm_cli() -> CliCommandMap { CliCommand::new(&API_METHOD_UPLOAD_LOG) .arg_param(&["snapshot", "logfile"]) .completion_cb("snapshot", complete_backup_snapshot) - .completion_cb("logfile", pbs_tools::fs::complete_file_name) - .completion_cb("keyfile", pbs_tools::fs::complete_file_name) + .completion_cb("logfile", complete_file_name) + .completion_cb("keyfile", complete_file_name) .completion_cb("repository", complete_repository) ) } diff --git a/proxmox-file-restore/Cargo.toml b/proxmox-file-restore/Cargo.toml index 2d075e4c..5c8da8f8 100644 --- a/proxmox-file-restore/Cargo.toml +++ b/proxmox-file-restore/Cargo.toml @@ -18,7 +18,7 @@ pxar = { version = "0.10.1", features = [ "tokio-io" ] } proxmox = { version = "0.14.0" } proxmox-lang = "1" -proxmox-router = { version = "1", features = [ "cli" ] } +proxmox-router = { version = "1.1", features = [ "cli" ] } proxmox-schema = { version = "1", features = [ "api-macro" ] } proxmox-time = "1" proxmox-uuid = "1" diff --git a/proxmox-file-restore/src/main.rs b/proxmox-file-restore/src/main.rs index 044bd2bd..dc507dc1 100644 --- a/proxmox-file-restore/src/main.rs +++ b/proxmox-file-restore/src/main.rs @@ -8,8 +8,10 @@ use serde_json::{json, Value}; use proxmox::tools::fs::{create_path, CreateOptions}; use proxmox_router::cli::{ - default_table_format_options, format_and_print_result_full, get_output_format, - run_cli_command, CliCommand, CliCommandMap, CliEnvironment, ColumnConfig, OUTPUT_FORMAT, + complete_file_name, default_table_format_options, + format_and_print_result_full, get_output_format, + run_cli_command, + CliCommand, CliCommandMap, CliEnvironment, ColumnConfig, OUTPUT_FORMAT, }; use proxmox_schema::api; use pxar::accessor::aio::Accessor; @@ -459,7 +461,7 @@ fn main() { .arg_param(&["snapshot", "path", "target"]) .completion_cb("repository", complete_repository) .completion_cb("snapshot", complete_group_or_snapshot) - .completion_cb("target", pbs_tools::fs::complete_file_name); + .completion_cb("target", complete_file_name); let status_cmd_def = CliCommand::new(&API_METHOD_STATUS); let stop_cmd_def = CliCommand::new(&API_METHOD_STOP) diff --git a/proxmox-rest-server/Cargo.toml b/proxmox-rest-server/Cargo.toml index a00986cf..9eb3860f 100644 --- a/proxmox-rest-server/Cargo.toml +++ b/proxmox-rest-server/Cargo.toml @@ -33,7 +33,7 @@ url = "2.1" proxmox = "0.14.0" proxmox-io = "1" proxmox-lang = "1" -proxmox-router = "1" +proxmox-router = "1.1" proxmox-schema = { version = "1", features = [ "api-macro", "upid-api-impl" ] } proxmox-time = "1" diff --git a/proxmox-restore-daemon/Cargo.toml b/proxmox-restore-daemon/Cargo.toml index 54ab9f3a..99ce2cec 100644 --- a/proxmox-restore-daemon/Cargo.toml +++ b/proxmox-restore-daemon/Cargo.toml @@ -27,7 +27,7 @@ pathpatterns = "0.1.2" pxar = { version = "0.10.1", features = [ "tokio-io" ] } proxmox = { version = "0.14.0", features = [ "sortable-macro" ] } -proxmox-router = { version = "1", features = [ "cli" ] } +proxmox-router = { version = "1.1", features = [ "cli" ] } proxmox-schema = { version = "1", features = [ "api-macro" ] } proxmox-time = "1" diff --git a/proxmox-rrd/Cargo.toml b/proxmox-rrd/Cargo.toml index 0ede97f5..31473962 100644 --- a/proxmox-rrd/Cargo.toml +++ b/proxmox-rrd/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" description = "Simple RRD database implementation." [dev-dependencies] -proxmox-router = "1" +proxmox-router = "1.1" [dependencies] anyhow = "1.0" diff --git a/proxmox-rrd/examples/prrd.rs b/proxmox-rrd/examples/prrd.rs index bf2817c4..59e75d3c 100644 --- a/proxmox-rrd/examples/prrd.rs +++ b/proxmox-rrd/examples/prrd.rs @@ -7,7 +7,7 @@ use serde::{Serialize, Deserialize}; use serde_json::json; use proxmox_router::RpcEnvironment; -use proxmox_router::cli::{run_cli_command, CliCommand, CliCommandMap, CliEnvironment}; +use proxmox_router::cli::{run_cli_command, complete_file_name, CliCommand, CliCommandMap, CliEnvironment}; use proxmox_schema::{api, parse_property_string}; use proxmox_schema::{ApiStringFormat, ApiType, IntegerSchema, Schema, StringSchema}; @@ -350,55 +350,55 @@ fn main() -> Result<(), Error> { "create", CliCommand::new(&API_METHOD_CREATE_RRD) .arg_param(&["path"]) - //.completion_cb("path", pbs_tools::fs::complete_file_name) + .completion_cb("path", complete_file_name) ) .insert( "dump", CliCommand::new(&API_METHOD_DUMP_RRD) .arg_param(&["path"]) - //.completion_cb("path", pbs_tools::fs::complete_file_name) + .completion_cb("path", complete_file_name) ) .insert( "fetch", CliCommand::new(&API_METHOD_FETCH_RRD) .arg_param(&["path"]) - //.completion_cb("path", pbs_tools::fs::complete_file_name) + .completion_cb("path", complete_file_name) ) .insert( "first", CliCommand::new(&API_METHOD_FIRST_UPDATE_TIME) .arg_param(&["path"]) - //.completion_cb("path", pbs_tools::fs::complete_file_name) + .completion_cb("path", complete_file_name) ) .insert( "info", CliCommand::new(&API_METHOD_RRD_INFO) .arg_param(&["path"]) - //.completion_cb("path", pbs_tools::fs::complete_file_name) + .completion_cb("path", complete_file_name) ) .insert( "last", CliCommand::new(&API_METHOD_LAST_UPDATE_TIME) .arg_param(&["path"]) - //.completion_cb("path", pbs_tools::fs::complete_file_name) + .completion_cb("path", complete_file_name) ) .insert( "lastupdate", CliCommand::new(&API_METHOD_LAST_UPDATE) .arg_param(&["path"]) - //.completion_cb("path", pbs_tools::fs::complete_file_name) + .completion_cb("path", complete_file_name) ) .insert( "resize", CliCommand::new(&API_METHOD_RESIZE_RRD) .arg_param(&["path"]) - //.completion_cb("path", pbs_tools::fs::complete_file_name) + .completion_cb("path", complete_file_name) ) .insert( "update", CliCommand::new(&API_METHOD_UPDATE_RRD) .arg_param(&["path"]) - //.completion_cb("path", pbs_tools::fs::complete_file_name) + .completion_cb("path", complete_file_name) ) ; diff --git a/pxar-bin/Cargo.toml b/pxar-bin/Cargo.toml index f1fca565..4b3724b3 100644 --- a/pxar-bin/Cargo.toml +++ b/pxar-bin/Cargo.toml @@ -18,7 +18,7 @@ tokio = { version = "1.6", features = [ "rt", "rt-multi-thread" ] } pathpatterns = "0.1.2" proxmox = "0.14.0" proxmox-schema = { version = "1", features = [ "api-macro" ] } -proxmox-router = "1" +proxmox-router = "1.1" pxar = { version = "0.10.1", features = [ "tokio-io" ] } pbs-client = { path = "../pbs-client" } diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs index 3bc82008..6f60494d 100644 --- a/pxar-bin/src/main.rs +++ b/pxar-bin/src/main.rs @@ -461,29 +461,29 @@ fn main() { "create", CliCommand::new(&API_METHOD_CREATE_ARCHIVE) .arg_param(&["archive", "source"]) - .completion_cb("archive", pbs_tools::fs::complete_file_name) - .completion_cb("source", pbs_tools::fs::complete_file_name), + .completion_cb("archive", complete_file_name) + .completion_cb("source", complete_file_name), ) .insert( "extract", CliCommand::new(&API_METHOD_EXTRACT_ARCHIVE) .arg_param(&["archive", "target"]) - .completion_cb("archive", pbs_tools::fs::complete_file_name) - .completion_cb("target", pbs_tools::fs::complete_file_name) - .completion_cb("files-from", pbs_tools::fs::complete_file_name), + .completion_cb("archive", complete_file_name) + .completion_cb("target", complete_file_name) + .completion_cb("files-from", complete_file_name), ) .insert( "mount", CliCommand::new(&API_METHOD_MOUNT_ARCHIVE) .arg_param(&["archive", "mountpoint"]) - .completion_cb("archive", pbs_tools::fs::complete_file_name) - .completion_cb("mountpoint", pbs_tools::fs::complete_file_name), + .completion_cb("archive", complete_file_name) + .completion_cb("mountpoint", complete_file_name), ) .insert( "list", CliCommand::new(&API_METHOD_DUMP_ARCHIVE) .arg_param(&["archive"]) - .completion_cb("archive", pbs_tools::fs::complete_file_name), + .completion_cb("archive", complete_file_name), ); let rpcenv = CliEnvironment::new();