chore: update clap

This commit is contained in:
grimhilt 2024-03-31 22:17:26 +02:00
parent 1aa02a24af
commit 3420634bea
20 changed files with 241 additions and 240 deletions

122
Cargo.lock generated
View File

@ -42,23 +42,51 @@ dependencies = [
] ]
[[package]] [[package]]
name = "ansi_term" name = "anstream"
version = "0.12.1" version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb"
dependencies = [ dependencies = [
"winapi", "anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"utf8parse",
] ]
[[package]] [[package]]
name = "atty" name = "anstyle"
version = "0.2.14" version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc"
[[package]]
name = "anstyle-parse"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
dependencies = [ dependencies = [
"hermit-abi 0.1.19", "utf8parse",
"libc", ]
"winapi",
[[package]]
name = "anstyle-query"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
dependencies = [
"anstyle",
"windows-sys 0.52.0",
] ]
[[package]] [[package]]
@ -140,19 +168,37 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "2.34.0" version = "4.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0"
dependencies = [ dependencies = [
"ansi_term", "clap_builder",
"atty",
"bitflags 1.3.2",
"strsim",
"textwrap 0.11.0",
"unicode-width",
"vec_map",
] ]
[[package]]
name = "clap_builder"
version = "4.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_lex"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]] [[package]]
name = "colored" name = "colored"
version = "2.1.0" version = "2.1.0"
@ -386,15 +432,6 @@ version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.2.6" version = "0.2.6"
@ -706,7 +743,7 @@ dependencies = [
"rust-crypto", "rust-crypto",
"rustc-serialize", "rustc-serialize",
"tempfile", "tempfile",
"textwrap 0.16.1", "textwrap",
"tokio", "tokio",
"xml-rs", "xml-rs",
] ]
@ -726,7 +763,7 @@ version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
dependencies = [ dependencies = [
"hermit-abi 0.2.6", "hermit-abi",
"libc", "libc",
] ]
@ -1235,9 +1272,9 @@ dependencies = [
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.8.0" version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01"
[[package]] [[package]]
name = "syn" name = "syn"
@ -1289,15 +1326,6 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"unicode-width",
]
[[package]] [[package]]
name = "textwrap" name = "textwrap"
version = "0.16.1" version = "0.16.1"
@ -1497,18 +1525,18 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]] [[package]]
name = "vcpkg" name = "vcpkg"
version = "0.2.15" version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.4"

View File

@ -10,7 +10,7 @@ rustc-serialize="0.3.25"
reqwest = { version = "0.12", features = ["stream", "json", "multipart"] } reqwest = { version = "0.12", features = ["stream", "json", "multipart"] }
tokio = { version = "1.37", features = ["full"] } tokio = { version = "1.37", features = ["full"] }
dotenv ="0.15.0" dotenv ="0.15.0"
clap = "2.34.0" clap = "4.5.4"
rust-crypto = "0.2.36" rust-crypto = "0.2.36"
colored = "2.1.0" colored = "2.1.0"
xml-rs = "0.8.19" xml-rs = "0.8.19"

View File

@ -1,6 +1,5 @@
use std::io::Write; use std::io::Write;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use clap::Values;
use glob::glob; use glob::glob;
use crate::store::{self, object::Object}; use crate::store::{self, object::Object};
use crate::utils::{self, path}; use crate::utils::{self, path};
@ -8,8 +7,8 @@ use crate::store::object::object::{Obj, ObjMethods};
use crate::utils::nextsyncignore::{self, ignore_file}; use crate::utils::nextsyncignore::{self, ignore_file};
use crate::utils::path::{normalize_relative, repo_root, path_buf_to_string}; use crate::utils::path::{normalize_relative, repo_root, path_buf_to_string};
pub struct AddArgs<'a> { pub struct AddArgs {
pub files: Option<Values<'a>>, pub files: Vec<String>,
pub force: bool, pub force: bool,
pub all: bool, pub all: bool,
} }
@ -18,13 +17,13 @@ pub struct AddArgs<'a> {
pub fn add(args: AddArgs) { pub fn add(args: AddArgs) {
let mut pattern: String; let mut pattern: String;
let file_vec: Vec<&str> = match args.all { let file_vec: Vec<String> = match args.all {
true => { true => {
pattern = path_buf_to_string(repo_root()); pattern = path_buf_to_string(repo_root());
pattern.push_str("/*"); pattern.push_str("/*");
vec![&pattern] vec![pattern]
}, },
false => args.files.unwrap().collect(), false => args.files,
}; };
let mut added_files: Vec<String> = vec![]; let mut added_files: Vec<String> = vec![];
@ -32,8 +31,7 @@ pub fn add(args: AddArgs) {
let rules = nextsyncignore::get_rules(); let rules = nextsyncignore::get_rules();
for file in file_vec { for file in file_vec {
dbg!(&file); let f = match normalize_relative(&file) {
let f = match normalize_relative(file) {
Ok(f) => f, Ok(f) => f,
Err(err) => { Err(err) => {
eprintln!("err: {} {}", file, err); eprintln!("err: {} {}", file, err);

View File

@ -2,7 +2,6 @@ use std::io;
use std::io::prelude::*; use std::io::prelude::*;
use std::fs::DirBuilder; use std::fs::DirBuilder;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use clap::Values;
use regex::Regex; use regex::Regex;
use crate::services::downloader::Downloader; use crate::services::downloader::Downloader;
use crate::utils::api::ApiProps; use crate::utils::api::ApiProps;
@ -18,16 +17,16 @@ use crate::commands::init;
pub const DEPTH: &str = "3"; pub const DEPTH: &str = "3";
pub struct CloneArgs<'a> { pub struct CloneArgs {
pub remote: Values<'a>, pub remote: String,
pub depth: Option<String>, pub depth: Option<String>,
} }
pub fn clone(args: CloneArgs) { pub fn clone(args: CloneArgs) {
let d = DIR_PATH.lock().unwrap().clone(); let d = DIR_PATH.lock().unwrap().clone();
let url = args.remote.clone().next().unwrap(); let url = args.remote.clone();
let (host, tmp_user, dist_path_str) = get_url_props(url); let (host, tmp_user, dist_path_str) = get_url_props(&url);
let username = match tmp_user { let username = match tmp_user {
Some(u) => u.to_string(), Some(u) => u.to_string(),
None => { None => {

View File

@ -1,12 +1,11 @@
use std::fs::OpenOptions; use std::fs::OpenOptions;
use clap::Values;
use std::io::{self, Write, BufRead, Seek, SeekFrom}; use std::io::{self, Write, BufRead, Seek, SeekFrom};
use crate::utils::{path, read}; use crate::utils::{path, read};
use std::collections::HashMap; use std::collections::HashMap;
pub struct ConfigSetArgs<'a> { pub struct ConfigSetArgs {
pub name: Option<Values<'a>>, pub name: String,
pub value: Option<Values<'a>>, pub value: String,
} }
pub fn config_set(args: ConfigSetArgs) { pub fn config_set(args: ConfigSetArgs) {
@ -15,17 +14,14 @@ pub fn config_set(args: ConfigSetArgs) {
option_categories.insert("force_insecure", "core"); option_categories.insert("force_insecure", "core");
option_categories.insert("token", "core"); option_categories.insert("token", "core");
let name = args.name.unwrap().next().unwrap();
let value = args.value.unwrap().next().unwrap();
// get category of option // get category of option
let category = option_categories.get(name); let category = option_categories.get(args.name.as_str());
if category.is_none() { if category.is_none() {
eprintln!("fatal: '{}' is not a valid option.", name); eprintln!("fatal: '{}' is not a valid option.", args.name.clone());
std::process::exit(1); std::process::exit(1);
} }
let _ = write_option_in_cat(category.unwrap(), name, value); let _ = write_option_in_cat(category.unwrap(), &args.name, &args.value);
} }

View File

@ -1,4 +1,3 @@
use clap::Values;
use crate::commands::clone::get_url_props; use crate::commands::clone::get_url_props;
use crate::services::api::ApiError::RequestError; use crate::services::api::ApiError::RequestError;
@ -6,9 +5,9 @@ use crate::services::login::Login;
use crate::services::api_call::ApiCall; use crate::services::api_call::ApiCall;
use crate::commands::config; use crate::commands::config;
pub struct CredentialArgs<'a> { pub struct CredentialArgs {
pub username: Option<Values<'a>>, pub username: String,
pub password: Option<Values<'a>>, pub password: Option<String>,
} }
pub fn credential_add(args: CredentialArgs) { pub fn credential_add(args: CredentialArgs) {
@ -23,9 +22,9 @@ pub fn credential_add(args: CredentialArgs) {
let (host, _, _) = get_url_props(&remote); let (host, _, _) = get_url_props(&remote);
// get username and password // get username and password
let username = args.username.unwrap().next().unwrap(); let username = args.username.to_owned();
let password = match args.password { let password = match args.password {
Some(mut pwd) => pwd.next().unwrap().to_owned(), Some(mut pwd) => pwd.to_owned(),
None => { None => {
println!("Please enter the password for {}: ", username); println!("Please enter the password for {}: ", username);
rpassword::read_password().unwrap() rpassword::read_password().unwrap()
@ -34,7 +33,7 @@ pub fn credential_add(args: CredentialArgs) {
// get token // get token
let get_token = Login::new() let get_token = Login::new()
.set_auth(username, &password) .set_auth(&username, &password)
.set_host(Some(host)) .set_host(Some(host))
.send_login(); .send_login();

View File

@ -1,7 +1,6 @@
use std::env; use std::env;
use std::fs::{DirBuilder, File}; use std::fs::{DirBuilder, File};
use std::path::PathBuf; use std::path::PathBuf;
use crate::utils::read::read_folder;
use crate::global::global::DIR_PATH; use crate::global::global::DIR_PATH;
pub fn init() { pub fn init() {

View File

@ -1,24 +1,14 @@
use clap::Values;
use crate::commands::config; use crate::commands::config;
use super::config::get_all_remote; use super::config::get_all_remote;
pub struct RemoteArgs<'a> { pub struct RemoteArgs {
pub name: Option<Values<'a>>, pub name: String,
pub url: Option<Values<'a>>, pub url: String,
} }
pub fn remote_add(args: RemoteArgs) { pub fn remote_add(args: RemoteArgs) {
if args.name.is_none() || args.url.is_none() { let _ = config::add_remote(&args.name, &args.url);
eprintln!("Missing argument: remote add command need a name and an url");
return;
}
let name = args.name.unwrap().next().unwrap();
let url = args.url.unwrap().next().unwrap();
let _ = config::add_remote(name, url);
} }
pub fn remote_list(verbose: bool) { pub fn remote_list(verbose: bool) {

View File

@ -1,4 +1,4 @@
use clap::{App, SubCommand}; use clap::Command;
mod subcommands; mod subcommands;
@ -9,42 +9,41 @@ mod global;
mod store; mod store;
fn main() { fn main() {
let app = App::new("Nextsync") let app = Command::new("Nextsync")
.version("1.0") .version("1.0")
.author("grimhilt") .author("grimhilt")
.about("A git-line command line tool to interact with nextcloud") .about("A git-line command line tool to interact with nextcloud")
.setting(clap::AppSettings::SubcommandRequiredElseHelp) .subcommands([
.subcommand(subcommands::clone::create()) subcommands::clone::create(),
.subcommand(subcommands::init::create()) subcommands::init::create(),
.subcommand(subcommands::status::create()) subcommands::status::create(),
.subcommand(subcommands::add::create()) subcommands::add::create(),
.subcommand(subcommands::push::create()) subcommands::push::create(),
.subcommand(subcommands::reset::create()) subcommands::reset::create(),
.subcommand(subcommands::remote::create()) subcommands::remote::create(),
.subcommand(subcommands::config::create()) subcommands::config::create(),
.subcommand(subcommands::remote_diff::create()) subcommands::remote_diff::create(),
.subcommand(subcommands::pull::create()) subcommands::pull::create(),
.subcommand(subcommands::credential::create()) subcommands::credential::create(),
.subcommand( ]);
SubCommand::with_name("test") // .setting(clap::AppSettings::SubcommandRequiredElseHelp);
);
let matches = app.get_matches(); let matches = app.get_matches();
match matches.subcommand() { match matches.subcommand() {
("init", Some(args)) => subcommands::init::handler(args), Some(("init", args)) => subcommands::init::handler(args),
("status", Some(args)) => subcommands::status::handler(args), Some(("status", args)) => subcommands::status::handler(args),
("add", Some(args)) => subcommands::add::handler(args), Some(("add", args)) => subcommands::add::handler(args),
("reset", Some(_)) => commands::reset::reset(), Some(("reset", _)) => commands::reset::reset(),
("clone", Some(args)) => subcommands::clone::handler(args), Some(("clone", args)) => subcommands::clone::handler(args),
("push", Some(_)) => commands::push::push(), Some(("push", _)) => commands::push::push(),
("config", Some(args)) => subcommands::config::handler(args), Some(("config", args)) => subcommands::config::handler(args),
("remote-diff", Some(args)) => subcommands::remote_diff::handler(args), Some(("remote-diff", args)) => subcommands::remote_diff::handler(args),
("pull", Some(args)) => subcommands::pull::handler(args), Some(("pull", args)) => subcommands::pull::handler(args),
("remote", Some(args)) => subcommands::remote::handler(args), Some(("remote", args)) => subcommands::remote::handler(args),
("credential", Some(args)) => subcommands::credential::handler(args), Some(("credential", args)) => subcommands::credential::handler(args),
Some((_, _)) => {},
(_, _) => {}, None => {},
}; };
} }

View File

@ -1,38 +1,40 @@
use clap::{App, Arg, SubCommand, ArgMatches}; use clap::{Arg, ArgMatches, Command};
use crate::commands; use crate::commands;
use crate::commands::add::AddArgs; use crate::commands::add::AddArgs;
pub fn create() -> App<'static, 'static> { pub fn create() -> Command {
SubCommand::with_name("add") Command::new("add")
.arg( .arg(
Arg::with_name("files") Arg::new("files")
.required(true) .required(true)
.conflicts_with("all") .conflicts_with("all")
.multiple(true) .num_args(1..)
.takes_value(true)
.value_name("FILE") .value_name("FILE")
.help("Files to add"), .help("Files to add"),
) )
.arg( .arg(
Arg::with_name("force") Arg::new("force")
.short("f") .short('f')
.long("force") .long("force")
.help("Allow adding otherwise ignored files."), .help("Allow adding otherwise ignored files."),
) )
.arg( .arg(
Arg::with_name("all") Arg::new("all")
.short("A") .short('A')
.long("all") .long("all")
.help("This adds, modifies, and removes index entries to match the working tree"), .help("This adds, modifies, and removes index entries to match the working tree"),
) )
.about("Add changes to the index") .about("Add changes to the index")
} }
pub fn handler(args: &ArgMatches<'_>) { pub fn handler(args: &ArgMatches) {
commands::add::add(AddArgs { commands::add::add(AddArgs {
files: args.values_of("files"), files: match args.get_many::<String>("files") {
force: args.is_present("force"), None => vec![],
all: args.is_present("all"), Some(vals) => vals.map(|s| s.to_string()).collect(),
},
force: args.contains_id("force"),
all: args.contains_id("all"),
}); });
} }

View File

@ -1,4 +1,4 @@
use clap::{App, Arg, SubCommand, ArgMatches}; use clap::{Arg, Command, ArgMatches};
// use textwrap::{fill, Options}; // use textwrap::{fill, Options};
use crate::commands::clone::CloneArgs; use crate::commands::clone::CloneArgs;
@ -10,45 +10,43 @@ use crate::commands;
// "ok" // "ok"
// } // }
pub fn create() -> App<'static, 'static> { pub fn create() -> Command {
// let remote_desc = sized_str(&format!("The repository to clone from. See the NEXTSYNC URLS section below for more information on specifying repositories.")); // let remote_desc = sized_str(&format!("The repository to clone from. See the NEXTSYNC URLS section below for more information on specifying repositories."));
// let depth_desc = sized_str(&format!("Depth of the recursive fetch of object properties. This value should be lower when there are a lot of files per directory and higher when there are a lot of subdirectories with fewer files. (Default: {})", clone::DEPTH)); // let depth_desc = sized_str(&format!("Depth of the recursive fetch of object properties. This value should be lower when there are a lot of files per directory and higher when there are a lot of subdirectories with fewer files. (Default: {})", clone::DEPTH));
SubCommand::with_name("clone") Command::new("clone")
.arg( .arg(
Arg::with_name("remote") Arg::new("remote")
.required(true) .required(true)
.takes_value(true) .num_args(1)
.value_name("REMOTE") .value_name("REMOTE")
//.help(_desc) //.help(_desc)
) )
.arg( .arg(
Arg::with_name("depth") Arg::new("depth")
.short("d") .short('d')
.long("depth") .long("depth")
.required(false) .required(false)
.takes_value(true) .num_args(1)
//.help(&depth_desc) //.help(&depth_desc)
) )
.arg( .arg(
Arg::with_name("directory") Arg::new("directory")
.required(false) .required(false)
.takes_value(true) .num_args(1)
.value_name("DIRECTORY") .value_name("DIRECTORY")
) )
.about("Clone a repository into a new directory") .about("Clone a repository into a new directory")
.after_help("NEXTSYNC URLS\nThe following syntaxes may be used:\n\t- user@host.xz/path/to/repo\n\t- http[s]://host.xz/apps/files/?dir=/path/to/repo&fileid=111111\n\t- [http[s]://]host.xz/remote.php/dav/files/user/path/to/repo\n") .after_help("NEXTSYNC URLS\nThe following syntaxes may be used:\n\t- user@host.xz/path/to/repo\n\t- http[s]://host.xz/apps/files/?dir=/path/to/repo&fileid=111111\n\t- [http[s]://]host.xz/remote.php/dav/files/user/path/to/repo\n")
} }
pub fn handler(args: &ArgMatches<'_>) { pub fn handler(args: &ArgMatches) {
if let Some(val) = args.values_of("directory") { if let Some(val) = args.get_one::<String>("directory") {
global::global::set_dir_path(String::from(val.clone().next().unwrap())); global::global::set_dir_path(String::from(val.to_string()));
} }
if let Some(remote) = args.values_of("remote") { if let Some(remote) = args.get_one::<String>("remote") {
commands::clone::clone(CloneArgs { commands::clone::clone(CloneArgs {
remote, remote: remote.to_string(),
depth: args.values_of("depth").map( depth: args.get_one::<String>("depth").cloned(),
|mut val| val.next().unwrap().to_owned()
),
}); });
} }
} }

View File

@ -1,32 +1,32 @@
use clap::{App, Arg, SubCommand, ArgMatches}; use clap::{Arg, Command, ArgMatches};
use crate::commands::config::ConfigSetArgs; use crate::commands::config::ConfigSetArgs;
use crate::commands; use crate::commands;
pub fn create() -> App<'static, 'static> { pub fn create() -> Command {
SubCommand::with_name("config") Command::new("config")
.about("Get and set repository or global options") .about("Get and set repository or global options")
.subcommand( .subcommand(
SubCommand::with_name("get") Command::new("get")
.about("Get the value of a configuration variable") .about("Get the value of a configuration variable")
.arg( .arg(
Arg::with_name("name") Arg::new("name")
.help("The name of the configuration variable") .help("The name of the configuration variable")
.required(true) .required(true)
.index(1) .index(1)
) )
) )
.subcommand( .subcommand(
SubCommand::with_name("set") Command::new("set")
.about("Set a configuration variable") .about("Set a configuration variable")
.arg( .arg(
Arg::with_name("name") Arg::new("name")
.help("The name of the configuration variable") .help("The name of the configuration variable")
.required(true) .required(true)
.index(1) .index(1)
) )
.arg( .arg(
Arg::with_name("value") Arg::new("value")
.help("The value to set") .help("The value to set")
.required(true) .required(true)
.index(2) .index(2)
@ -34,20 +34,15 @@ pub fn create() -> App<'static, 'static> {
) )
} }
pub fn handler(args: &ArgMatches<'_>) { pub fn handler(args: &ArgMatches) {
match args.subcommand() { match args.subcommand() {
("set", Some(set_matches)) => { Some(("set", set_matches)) => {
commands::config::config_set(ConfigSetArgs { commands::config::config_set(ConfigSetArgs {
name: set_matches.values_of("name"), name: set_matches.get_one::<String>("name").unwrap().to_string(),
value: set_matches.values_of("value"), value: set_matches.get_one::<String>("value").unwrap().to_string(),
}); });
} }
_ => println!("Invalid or missing subcommand for 'config'"), _ => println!("Invalid or missing subcommand for 'config'"),
} }
// AddArgs {
// files: args.values_of("files"),
// force: args.is_present("force"),
// all: args.is_present("all"),
// });
} }

View File

@ -1,24 +1,24 @@
use clap::{App, Arg, SubCommand, ArgMatches}; use clap::{Arg, Command, ArgMatches};
use crate::commands; use crate::commands;
use crate::commands::credential::CredentialArgs; use crate::commands::credential::CredentialArgs;
pub fn create() -> App<'static, 'static> { pub fn create() -> Command {
SubCommand::with_name("credential") Command::new("credential")
.about("Manage set of credentials") .about("Manage set of credentials")
.subcommand( .subcommand(
SubCommand::with_name("add") Command::new("add")
.arg( .arg(
Arg::with_name("username") Arg::new("username")
.required(true) .required(true)
.takes_value(true) .num_args(1)
.value_name("NAME") .value_name("NAME")
.help("The username used to connect to nextcloud"), .help("The username used to connect to nextcloud"),
) )
.arg( .arg(
Arg::with_name("password") Arg::new("password")
.required(false) .required(false)
.takes_value(true) .num_args(1)
.value_name("PASSWORD") .value_name("PASSWORD")
.help("The passowd used to connect to nextcloud (optional)"), .help("The passowd used to connect to nextcloud (optional)"),
) )
@ -26,12 +26,12 @@ pub fn create() -> App<'static, 'static> {
) )
} }
pub fn handler(args: &ArgMatches<'_>) { pub fn handler(args: &ArgMatches) {
match args.subcommand() { match args.subcommand() {
("add", Some(add_matches)) => { Some(("add", add_matches)) => {
commands::credential::credential_add(CredentialArgs { commands::credential::credential_add(CredentialArgs {
username: add_matches.values_of("username"), username: add_matches.get_one::<String>("username").unwrap().to_string(),
password: add_matches.values_of("password"), password: add_matches.get_one::<String>("password").cloned(),
}); });
} }
_ => println!("Invalid or missing subcommand for 'credential'"), _ => println!("Invalid or missing subcommand for 'credential'"),

View File

@ -1,23 +1,23 @@
use clap::{App, Arg, SubCommand, ArgMatches}; use clap::{Arg, Command, ArgMatches};
use crate::global; use crate::global;
use crate::commands; use crate::commands;
pub fn create() -> App<'static, 'static> { pub fn create() -> Command {
SubCommand::with_name("init") Command::new("init")
.arg( .arg(
Arg::with_name("directory") Arg::new("directory")
.required(false) .required(false)
.takes_value(true) .num_args(1)
.value_name("DIRECTORY") .value_name("DIRECTORY")
) )
.about("Create an empty Nextsync repository") .about("Create an empty Nextsync repository")
// Create an empty nextsync repository or reinitialize an existing one // Create an empty nextsync repository or reinitialize an existing one
} }
pub fn handler(args: &ArgMatches<'_>) { pub fn handler(args: &ArgMatches) {
if let Some(val) = args.values_of("directory") { if let Some(val) = args.get_one::<String>("directory") {
global::global::set_dir_path(String::from(val.clone().next().unwrap())); global::global::set_dir_path(val.to_string());
} }
commands::init::init(); commands::init::init();
} }

View File

@ -1,23 +1,23 @@
use clap::{App, Arg, SubCommand, ArgMatches}; use clap::{Arg, Command, ArgMatches};
use crate::global; use crate::global;
use crate::commands; use crate::commands;
pub fn create() -> App<'static, 'static> { pub fn create() -> Command {
SubCommand::with_name("pull") Command::new("pull")
.arg( .arg(
Arg::with_name("path") Arg::new("path")
.required(false) .required(false)
.takes_value(true) .num_args(1)
.value_name("PATH") .value_name("PATH")
.help("The path to pull."), .help("The path to pull."),
) )
.about("Fetch and integrate changes from the nextcloud server.") .about("Fetch and integrate changes from the nextcloud server.")
} }
pub fn handler(args: &ArgMatches<'_>) { pub fn handler(args: &ArgMatches) {
if let Some(val) = args.values_of("path") { if let Some(val) = args.get_one::<String>("path") {
global::global::set_dir_path(String::from(val.clone().next().unwrap())); global::global::set_dir_path(val.to_string());
} }
commands::pull::pull(); commands::pull::pull();
} }

View File

@ -1,6 +1,6 @@
use clap::{App, SubCommand}; use clap::Command;
pub fn create() -> App<'static, 'static> { pub fn create() -> Command {
SubCommand::with_name("push") Command::new("push")
.about("Push changes on nextcloud") .about("Push changes on nextcloud")
} }

View File

@ -1,21 +1,21 @@
use clap::{App, Arg, SubCommand, ArgMatches}; use clap::{Arg, Command, ArgMatches};
use crate::commands; use crate::commands;
use crate::commands::remote::RemoteArgs; use crate::commands::remote::RemoteArgs;
pub fn create() -> App<'static, 'static> { pub fn create() -> Command {
SubCommand::with_name("remote") Command::new("remote")
.about("Manage set of tracked repositories") .about("Manage set of tracked repositories")
.subcommand( .subcommand(
SubCommand::with_name("add") Command::new("add")
.arg( .arg(
Arg::with_name("name") Arg::new("name")
.required(true) .required(true)
.index(1) .index(1)
.help("The name of the remote"), .help("The name of the remote"),
) )
.arg( .arg(
Arg::with_name("url") Arg::new("url")
.required(true) .required(true)
.index(2) .index(2)
.help("The url of the remote"), .help("The url of the remote"),
@ -23,25 +23,23 @@ pub fn create() -> App<'static, 'static> {
.about("Add a new remote to this repository") .about("Add a new remote to this repository")
) )
.arg( .arg(
Arg::with_name("verbose") Arg::new("verbose")
.short("v") .short('v')
.long("verbose") .long("verbose")
.required(false)
.takes_value(false)
.help("Be a little more verbose and show remote url after name.") .help("Be a little more verbose and show remote url after name.")
) )
} }
pub fn handler(args: &ArgMatches<'_>) { pub fn handler(args: &ArgMatches) {
match args.subcommand() { match args.subcommand() {
("add", Some(add_matches)) => { Some(("add", add_matches)) => {
commands::remote::remote_add(RemoteArgs { commands::remote::remote_add(RemoteArgs {
name: add_matches.values_of("name"), name: add_matches.get_one::<String>("name").unwrap().to_string(),
url: add_matches.values_of("url"), url: add_matches.get_one::<String>("url").unwrap().to_string(),
}); });
} }
_ => { _ => {
commands::remote::remote_list(args.is_present("verbose")); commands::remote::remote_list(args.contains_id("verbose"));
} }
} }
} }

View File

@ -1,14 +1,14 @@
use clap::{App, Arg, SubCommand, ArgMatches}; use clap::{Arg, Command, ArgMatches};
use crate::global; use crate::global;
use crate::commands; use crate::commands;
pub fn create() -> App<'static, 'static> { pub fn create() -> Command {
SubCommand::with_name("remote-diff") Command::new("remote-diff")
.arg( .arg(
Arg::with_name("path") Arg::new("path")
.required(false) .required(false)
.takes_value(true) .num_args(1)
.value_name("PATH") .value_name("PATH")
.help("The path to pull."), .help("The path to pull."),
) )
@ -16,9 +16,9 @@ pub fn create() -> App<'static, 'static> {
} }
pub fn handler(args: &ArgMatches<'_>) { pub fn handler(args: &ArgMatches) {
if let Some(val) = args.values_of("path") { if let Some(val) = args.get_one::<String>("path") {
global::global::set_dir_path(String::from(val.clone().next().unwrap())); global::global::set_dir_path(val.to_string());
} }
commands::remote_diff::remote_diff(); commands::remote_diff::remote_diff();
} }

View File

@ -1,6 +1,6 @@
use clap::{App, SubCommand}; use clap::Command;
pub fn create() -> App<'static, 'static> { pub fn create() -> Command {
SubCommand::with_name("reset") Command::new("reset")
.about("Clear the index") .about("Clear the index")
} }

View File

@ -1,30 +1,30 @@
use clap::{App, Arg, SubCommand, ArgMatches}; use clap::{Arg, Command, ArgMatches};
use crate::global; use crate::global;
use crate::commands; use crate::commands;
use crate::commands::status::StatusArgs; use crate::commands::status::StatusArgs;
pub fn create() -> App<'static, 'static> { pub fn create() -> Command {
SubCommand::with_name("status") Command::new("status")
.arg( .arg(
Arg::with_name("directory") Arg::new("directory")
.required(false) .num_args(1)
.takes_value(true)
.value_name("DIRECTORY") .value_name("DIRECTORY")
) )
.arg( .arg(
Arg::with_name("nostyle") Arg::new("nostyle")
.long("nostyle") .long("nostyle")
.help("Status with minium information and style"), .help("Status with minium information and style"),
) )
.about("Show the working tree status") .about("Show the working tree status")
} }
pub fn handler(args: &ArgMatches<'_>) { pub fn handler(args: &ArgMatches) {
if let Some(val) = args.values_of("directory") { if let Some(val) = args.get_one::<String>("directory") {
global::global::set_dir_path(String::from(val.clone().next().unwrap())); global::global::set_dir_path(val.to_string());
} }
commands::status::status(StatusArgs { commands::status::status(StatusArgs {
nostyle: args.is_present("nostyle"), nostyle: args.contains_id("nostyle"),
}); });
} }