use complete_file_name from proxmox-router 1.1

This commit is contained in:
Dietmar Maurer 2021-10-13 12:55:51 +02:00
parent 82f5ad18f0
commit b3f279e2d9
20 changed files with 56 additions and 110 deletions

View File

@ -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" ] }

View File

@ -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" ] }

View File

@ -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",

View File

@ -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<String, String>) -> 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));

View File

@ -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"

View File

@ -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" }

View File

@ -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<S>(arg: &str, _param: &HashMap<String, String, S>) -> Vec<String>
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<P: AsRef<Path>>(

View File

@ -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"

View File

@ -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)

View File

@ -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"])

View File

@ -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 {

View File

@ -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)
)
}

View File

@ -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"

View File

@ -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)

View File

@ -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"

View File

@ -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"

View File

@ -6,7 +6,7 @@ edition = "2018"
description = "Simple RRD database implementation."
[dev-dependencies]
proxmox-router = "1"
proxmox-router = "1.1"
[dependencies]
anyhow = "1.0"

View File

@ -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)
)
;

View File

@ -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" }

View File

@ -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();