diff --git a/Cargo.lock b/Cargo.lock index 12829b5..03bc2ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,23 +42,51 @@ dependencies = [ ] [[package]] -name = "ansi_term" -version = "0.12.1" +name = "anstream" +version = "0.6.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" dependencies = [ - "winapi", + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", ] [[package]] -name = "atty" -version = "0.2.14" +name = "anstyle" +version = "1.0.6" 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 = [ - "hermit-abi 0.1.19", - "libc", - "winapi", + "utf8parse", +] + +[[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]] @@ -140,19 +168,37 @@ dependencies = [ [[package]] name = "clap" -version = "2.34.0" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ - "ansi_term", - "atty", - "bitflags 1.3.2", - "strsim", - "textwrap 0.11.0", - "unicode-width", - "vec_map", + "clap_builder", ] +[[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]] name = "colored" version = "2.1.0" @@ -386,15 +432,6 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "hermit-abi" version = "0.2.6" @@ -706,7 +743,7 @@ dependencies = [ "rust-crypto", "rustc-serialize", "tempfile", - "textwrap 0.16.1", + "textwrap", "tokio", "xml-rs", ] @@ -726,7 +763,7 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi", "libc", ] @@ -1235,9 +1272,9 @@ dependencies = [ [[package]] name = "strsim" -version = "0.8.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" [[package]] name = "syn" @@ -1289,15 +1326,6 @@ dependencies = [ "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]] name = "textwrap" version = "0.16.1" @@ -1497,18 +1525,18 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "vcpkg" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index 9915e44..4a08fac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ rustc-serialize="0.3.25" reqwest = { version = "0.12", features = ["stream", "json", "multipart"] } tokio = { version = "1.37", features = ["full"] } dotenv ="0.15.0" -clap = "2.34.0" +clap = "4.5.4" rust-crypto = "0.2.36" colored = "2.1.0" xml-rs = "0.8.19" diff --git a/src/commands/add.rs b/src/commands/add.rs index 9e72ee0..7b28c9a 100644 --- a/src/commands/add.rs +++ b/src/commands/add.rs @@ -1,6 +1,5 @@ use std::io::Write; use std::path::{Path, PathBuf}; -use clap::Values; use glob::glob; use crate::store::{self, object::Object}; 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::path::{normalize_relative, repo_root, path_buf_to_string}; -pub struct AddArgs<'a> { - pub files: Option>, +pub struct AddArgs { + pub files: Vec, pub force: bool, pub all: bool, } @@ -18,13 +17,13 @@ pub struct AddArgs<'a> { pub fn add(args: AddArgs) { let mut pattern: String; - let file_vec: Vec<&str> = match args.all { + let file_vec: Vec = match args.all { true => { pattern = path_buf_to_string(repo_root()); pattern.push_str("/*"); - vec![&pattern] + vec![pattern] }, - false => args.files.unwrap().collect(), + false => args.files, }; let mut added_files: Vec = vec![]; @@ -32,8 +31,7 @@ pub fn add(args: AddArgs) { let rules = nextsyncignore::get_rules(); for file in file_vec { - dbg!(&file); - let f = match normalize_relative(file) { + let f = match normalize_relative(&file) { Ok(f) => f, Err(err) => { eprintln!("err: {} {}", file, err); diff --git a/src/commands/clone.rs b/src/commands/clone.rs index 8b57564..f83723e 100644 --- a/src/commands/clone.rs +++ b/src/commands/clone.rs @@ -2,7 +2,6 @@ use std::io; use std::io::prelude::*; use std::fs::DirBuilder; use std::path::{Path, PathBuf}; -use clap::Values; use regex::Regex; use crate::services::downloader::Downloader; use crate::utils::api::ApiProps; @@ -18,16 +17,16 @@ use crate::commands::init; pub const DEPTH: &str = "3"; -pub struct CloneArgs<'a> { - pub remote: Values<'a>, +pub struct CloneArgs { + pub remote: String, pub depth: Option, } pub fn clone(args: CloneArgs) { let d = DIR_PATH.lock().unwrap().clone(); - let url = args.remote.clone().next().unwrap(); - let (host, tmp_user, dist_path_str) = get_url_props(url); + let url = args.remote.clone(); + let (host, tmp_user, dist_path_str) = get_url_props(&url); let username = match tmp_user { Some(u) => u.to_string(), None => { diff --git a/src/commands/config.rs b/src/commands/config.rs index 35f48a8..e1c19c4 100644 --- a/src/commands/config.rs +++ b/src/commands/config.rs @@ -1,12 +1,11 @@ use std::fs::OpenOptions; -use clap::Values; use std::io::{self, Write, BufRead, Seek, SeekFrom}; use crate::utils::{path, read}; use std::collections::HashMap; -pub struct ConfigSetArgs<'a> { - pub name: Option>, - pub value: Option>, +pub struct ConfigSetArgs { + pub name: String, + pub value: String, } 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("token", "core"); - let name = args.name.unwrap().next().unwrap(); - let value = args.value.unwrap().next().unwrap(); - // get category of option - let category = option_categories.get(name); + let category = option_categories.get(args.name.as_str()); 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); } - let _ = write_option_in_cat(category.unwrap(), name, value); + let _ = write_option_in_cat(category.unwrap(), &args.name, &args.value); } diff --git a/src/commands/credential.rs b/src/commands/credential.rs index 7bf2149..36b1b24 100644 --- a/src/commands/credential.rs +++ b/src/commands/credential.rs @@ -1,4 +1,3 @@ -use clap::Values; use crate::commands::clone::get_url_props; use crate::services::api::ApiError::RequestError; @@ -6,9 +5,9 @@ use crate::services::login::Login; use crate::services::api_call::ApiCall; use crate::commands::config; -pub struct CredentialArgs<'a> { - pub username: Option>, - pub password: Option>, +pub struct CredentialArgs { + pub username: String, + pub password: Option, } pub fn credential_add(args: CredentialArgs) { @@ -23,9 +22,9 @@ pub fn credential_add(args: CredentialArgs) { let (host, _, _) = get_url_props(&remote); // get username and password - let username = args.username.unwrap().next().unwrap(); + let username = args.username.to_owned(); let password = match args.password { - Some(mut pwd) => pwd.next().unwrap().to_owned(), + Some(mut pwd) => pwd.to_owned(), None => { println!("Please enter the password for {}: ", username); rpassword::read_password().unwrap() @@ -34,7 +33,7 @@ pub fn credential_add(args: CredentialArgs) { // get token let get_token = Login::new() - .set_auth(username, &password) + .set_auth(&username, &password) .set_host(Some(host)) .send_login(); diff --git a/src/commands/init.rs b/src/commands/init.rs index e0dee36..86e266f 100644 --- a/src/commands/init.rs +++ b/src/commands/init.rs @@ -1,7 +1,6 @@ use std::env; use std::fs::{DirBuilder, File}; use std::path::PathBuf; -use crate::utils::read::read_folder; use crate::global::global::DIR_PATH; pub fn init() { diff --git a/src/commands/remote.rs b/src/commands/remote.rs index acf71f0..46f2dd1 100644 --- a/src/commands/remote.rs +++ b/src/commands/remote.rs @@ -1,24 +1,14 @@ -use clap::Values; - use crate::commands::config; use super::config::get_all_remote; -pub struct RemoteArgs<'a> { - pub name: Option>, - pub url: Option>, +pub struct RemoteArgs { + pub name: String, + pub url: String, } pub fn remote_add(args: RemoteArgs) { - if args.name.is_none() || args.url.is_none() { - 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); + let _ = config::add_remote(&args.name, &args.url); } pub fn remote_list(verbose: bool) { diff --git a/src/main.rs b/src/main.rs index ff10cbf..e86417b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use clap::{App, SubCommand}; +use clap::Command; mod subcommands; @@ -9,42 +9,41 @@ mod global; mod store; fn main() { - let app = App::new("Nextsync") + let app = Command::new("Nextsync") .version("1.0") .author("grimhilt") .about("A git-line command line tool to interact with nextcloud") - .setting(clap::AppSettings::SubcommandRequiredElseHelp) - .subcommand(subcommands::clone::create()) - .subcommand(subcommands::init::create()) - .subcommand(subcommands::status::create()) - .subcommand(subcommands::add::create()) - .subcommand(subcommands::push::create()) - .subcommand(subcommands::reset::create()) - .subcommand(subcommands::remote::create()) - .subcommand(subcommands::config::create()) - .subcommand(subcommands::remote_diff::create()) - .subcommand(subcommands::pull::create()) - .subcommand(subcommands::credential::create()) - .subcommand( - SubCommand::with_name("test") - ); + .subcommands([ + subcommands::clone::create(), + subcommands::init::create(), + subcommands::status::create(), + subcommands::add::create(), + subcommands::push::create(), + subcommands::reset::create(), + subcommands::remote::create(), + subcommands::config::create(), + subcommands::remote_diff::create(), + subcommands::pull::create(), + subcommands::credential::create(), + ]); + // .setting(clap::AppSettings::SubcommandRequiredElseHelp); let matches = app.get_matches(); match matches.subcommand() { - ("init", Some(args)) => subcommands::init::handler(args), - ("status", Some(args)) => subcommands::status::handler(args), - ("add", Some(args)) => subcommands::add::handler(args), - ("reset", Some(_)) => commands::reset::reset(), - ("clone", Some(args)) => subcommands::clone::handler(args), - ("push", Some(_)) => commands::push::push(), - ("config", Some(args)) => subcommands::config::handler(args), - ("remote-diff", Some(args)) => subcommands::remote_diff::handler(args), - ("pull", Some(args)) => subcommands::pull::handler(args), - ("remote", Some(args)) => subcommands::remote::handler(args), - ("credential", Some(args)) => subcommands::credential::handler(args), - - (_, _) => {}, + Some(("init", args)) => subcommands::init::handler(args), + Some(("status", args)) => subcommands::status::handler(args), + Some(("add", args)) => subcommands::add::handler(args), + Some(("reset", _)) => commands::reset::reset(), + Some(("clone", args)) => subcommands::clone::handler(args), + Some(("push", _)) => commands::push::push(), + Some(("config", args)) => subcommands::config::handler(args), + Some(("remote-diff", args)) => subcommands::remote_diff::handler(args), + Some(("pull", args)) => subcommands::pull::handler(args), + Some(("remote", args)) => subcommands::remote::handler(args), + Some(("credential", args)) => subcommands::credential::handler(args), + Some((_, _)) => {}, + None => {}, }; } diff --git a/src/subcommands/add.rs b/src/subcommands/add.rs index 83dd21a..cdfa1a1 100644 --- a/src/subcommands/add.rs +++ b/src/subcommands/add.rs @@ -1,38 +1,40 @@ -use clap::{App, Arg, SubCommand, ArgMatches}; +use clap::{Arg, ArgMatches, Command}; use crate::commands; use crate::commands::add::AddArgs; -pub fn create() -> App<'static, 'static> { - SubCommand::with_name("add") +pub fn create() -> Command { + Command::new("add") .arg( - Arg::with_name("files") + Arg::new("files") .required(true) .conflicts_with("all") - .multiple(true) - .takes_value(true) + .num_args(1..) .value_name("FILE") .help("Files to add"), ) .arg( - Arg::with_name("force") - .short("f") + Arg::new("force") + .short('f') .long("force") .help("Allow adding otherwise ignored files."), ) .arg( - Arg::with_name("all") - .short("A") + Arg::new("all") + .short('A') .long("all") .help("This adds, modifies, and removes index entries to match the working tree"), ) .about("Add changes to the index") } -pub fn handler(args: &ArgMatches<'_>) { +pub fn handler(args: &ArgMatches) { commands::add::add(AddArgs { - files: args.values_of("files"), - force: args.is_present("force"), - all: args.is_present("all"), + files: match args.get_many::("files") { + None => vec![], + Some(vals) => vals.map(|s| s.to_string()).collect(), + }, + force: args.contains_id("force"), + all: args.contains_id("all"), }); } diff --git a/src/subcommands/clone.rs b/src/subcommands/clone.rs index 81ce2f2..2f48d94 100644 --- a/src/subcommands/clone.rs +++ b/src/subcommands/clone.rs @@ -1,4 +1,4 @@ -use clap::{App, Arg, SubCommand, ArgMatches}; +use clap::{Arg, Command, ArgMatches}; // use textwrap::{fill, Options}; use crate::commands::clone::CloneArgs; @@ -10,45 +10,43 @@ use crate::commands; // "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 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::with_name("remote") + Arg::new("remote") .required(true) - .takes_value(true) + .num_args(1) .value_name("REMOTE") //.help(_desc) ) .arg( - Arg::with_name("depth") - .short("d") + Arg::new("depth") + .short('d') .long("depth") .required(false) - .takes_value(true) + .num_args(1) //.help(&depth_desc) ) .arg( - Arg::with_name("directory") + Arg::new("directory") .required(false) - .takes_value(true) + .num_args(1) .value_name("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") } -pub fn handler(args: &ArgMatches<'_>) { - if let Some(val) = args.values_of("directory") { - global::global::set_dir_path(String::from(val.clone().next().unwrap())); +pub fn handler(args: &ArgMatches) { + if let Some(val) = args.get_one::("directory") { + 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::("remote") { commands::clone::clone(CloneArgs { - remote, - depth: args.values_of("depth").map( - |mut val| val.next().unwrap().to_owned() - ), + remote: remote.to_string(), + depth: args.get_one::("depth").cloned(), }); } } diff --git a/src/subcommands/config.rs b/src/subcommands/config.rs index a576a08..e61cf21 100644 --- a/src/subcommands/config.rs +++ b/src/subcommands/config.rs @@ -1,32 +1,32 @@ -use clap::{App, Arg, SubCommand, ArgMatches}; +use clap::{Arg, Command, ArgMatches}; use crate::commands::config::ConfigSetArgs; use crate::commands; -pub fn create() -> App<'static, 'static> { - SubCommand::with_name("config") +pub fn create() -> Command { + Command::new("config") .about("Get and set repository or global options") .subcommand( - SubCommand::with_name("get") + Command::new("get") .about("Get the value of a configuration variable") .arg( - Arg::with_name("name") + Arg::new("name") .help("The name of the configuration variable") .required(true) .index(1) ) ) .subcommand( - SubCommand::with_name("set") + Command::new("set") .about("Set a configuration variable") .arg( - Arg::with_name("name") + Arg::new("name") .help("The name of the configuration variable") .required(true) .index(1) ) .arg( - Arg::with_name("value") + Arg::new("value") .help("The value to set") .required(true) .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() { - ("set", Some(set_matches)) => { + Some(("set", set_matches)) => { commands::config::config_set(ConfigSetArgs { - name: set_matches.values_of("name"), - value: set_matches.values_of("value"), + name: set_matches.get_one::("name").unwrap().to_string(), + value: set_matches.get_one::("value").unwrap().to_string(), }); } _ => println!("Invalid or missing subcommand for 'config'"), } - // AddArgs { - // files: args.values_of("files"), - // force: args.is_present("force"), - // all: args.is_present("all"), - // }); } diff --git a/src/subcommands/credential.rs b/src/subcommands/credential.rs index 651e049..a34db22 100644 --- a/src/subcommands/credential.rs +++ b/src/subcommands/credential.rs @@ -1,24 +1,24 @@ -use clap::{App, Arg, SubCommand, ArgMatches}; +use clap::{Arg, Command, ArgMatches}; use crate::commands; use crate::commands::credential::CredentialArgs; -pub fn create() -> App<'static, 'static> { - SubCommand::with_name("credential") +pub fn create() -> Command { + Command::new("credential") .about("Manage set of credentials") .subcommand( - SubCommand::with_name("add") + Command::new("add") .arg( - Arg::with_name("username") + Arg::new("username") .required(true) - .takes_value(true) + .num_args(1) .value_name("NAME") .help("The username used to connect to nextcloud"), ) .arg( - Arg::with_name("password") + Arg::new("password") .required(false) - .takes_value(true) + .num_args(1) .value_name("PASSWORD") .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() { - ("add", Some(add_matches)) => { + Some(("add", add_matches)) => { commands::credential::credential_add(CredentialArgs { - username: add_matches.values_of("username"), - password: add_matches.values_of("password"), + username: add_matches.get_one::("username").unwrap().to_string(), + password: add_matches.get_one::("password").cloned(), }); } _ => println!("Invalid or missing subcommand for 'credential'"), diff --git a/src/subcommands/init.rs b/src/subcommands/init.rs index b4c3658..6727bb6 100644 --- a/src/subcommands/init.rs +++ b/src/subcommands/init.rs @@ -1,23 +1,23 @@ -use clap::{App, Arg, SubCommand, ArgMatches}; +use clap::{Arg, Command, ArgMatches}; use crate::global; use crate::commands; -pub fn create() -> App<'static, 'static> { - SubCommand::with_name("init") +pub fn create() -> Command { + Command::new("init") .arg( - Arg::with_name("directory") + Arg::new("directory") .required(false) - .takes_value(true) + .num_args(1) .value_name("DIRECTORY") ) .about("Create an empty Nextsync repository") // Create an empty nextsync repository or reinitialize an existing one } -pub fn handler(args: &ArgMatches<'_>) { - if let Some(val) = args.values_of("directory") { - global::global::set_dir_path(String::from(val.clone().next().unwrap())); +pub fn handler(args: &ArgMatches) { + if let Some(val) = args.get_one::("directory") { + global::global::set_dir_path(val.to_string()); } commands::init::init(); } diff --git a/src/subcommands/pull.rs b/src/subcommands/pull.rs index 8684d51..03a6080 100644 --- a/src/subcommands/pull.rs +++ b/src/subcommands/pull.rs @@ -1,23 +1,23 @@ -use clap::{App, Arg, SubCommand, ArgMatches}; +use clap::{Arg, Command, ArgMatches}; use crate::global; use crate::commands; -pub fn create() -> App<'static, 'static> { - SubCommand::with_name("pull") +pub fn create() -> Command { + Command::new("pull") .arg( - Arg::with_name("path") + Arg::new("path") .required(false) - .takes_value(true) + .num_args(1) .value_name("PATH") .help("The path to pull."), ) .about("Fetch and integrate changes from the nextcloud server.") } -pub fn handler(args: &ArgMatches<'_>) { - if let Some(val) = args.values_of("path") { - global::global::set_dir_path(String::from(val.clone().next().unwrap())); +pub fn handler(args: &ArgMatches) { + if let Some(val) = args.get_one::("path") { + global::global::set_dir_path(val.to_string()); } commands::pull::pull(); } diff --git a/src/subcommands/push.rs b/src/subcommands/push.rs index 3365d0c..19cd50e 100644 --- a/src/subcommands/push.rs +++ b/src/subcommands/push.rs @@ -1,6 +1,6 @@ -use clap::{App, SubCommand}; +use clap::Command; -pub fn create() -> App<'static, 'static> { - SubCommand::with_name("push") +pub fn create() -> Command { + Command::new("push") .about("Push changes on nextcloud") } diff --git a/src/subcommands/remote.rs b/src/subcommands/remote.rs index 1f388e5..17ff076 100644 --- a/src/subcommands/remote.rs +++ b/src/subcommands/remote.rs @@ -1,21 +1,21 @@ -use clap::{App, Arg, SubCommand, ArgMatches}; +use clap::{Arg, Command, ArgMatches}; use crate::commands; use crate::commands::remote::RemoteArgs; -pub fn create() -> App<'static, 'static> { - SubCommand::with_name("remote") +pub fn create() -> Command { + Command::new("remote") .about("Manage set of tracked repositories") .subcommand( - SubCommand::with_name("add") + Command::new("add") .arg( - Arg::with_name("name") + Arg::new("name") .required(true) .index(1) .help("The name of the remote"), ) .arg( - Arg::with_name("url") + Arg::new("url") .required(true) .index(2) .help("The url of the remote"), @@ -23,25 +23,23 @@ pub fn create() -> App<'static, 'static> { .about("Add a new remote to this repository") ) .arg( - Arg::with_name("verbose") - .short("v") + Arg::new("verbose") + .short('v') .long("verbose") - .required(false) - .takes_value(false) .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() { - ("add", Some(add_matches)) => { + Some(("add", add_matches)) => { commands::remote::remote_add(RemoteArgs { - name: add_matches.values_of("name"), - url: add_matches.values_of("url"), + name: add_matches.get_one::("name").unwrap().to_string(), + url: add_matches.get_one::("url").unwrap().to_string(), }); } _ => { - commands::remote::remote_list(args.is_present("verbose")); + commands::remote::remote_list(args.contains_id("verbose")); } } } diff --git a/src/subcommands/remote_diff.rs b/src/subcommands/remote_diff.rs index 9986c16..a7505c0 100644 --- a/src/subcommands/remote_diff.rs +++ b/src/subcommands/remote_diff.rs @@ -1,14 +1,14 @@ -use clap::{App, Arg, SubCommand, ArgMatches}; +use clap::{Arg, Command, ArgMatches}; use crate::global; use crate::commands; -pub fn create() -> App<'static, 'static> { - SubCommand::with_name("remote-diff") +pub fn create() -> Command { + Command::new("remote-diff") .arg( - Arg::with_name("path") + Arg::new("path") .required(false) - .takes_value(true) + .num_args(1) .value_name("PATH") .help("The path to pull."), ) @@ -16,9 +16,9 @@ pub fn create() -> App<'static, 'static> { } -pub fn handler(args: &ArgMatches<'_>) { - if let Some(val) = args.values_of("path") { - global::global::set_dir_path(String::from(val.clone().next().unwrap())); +pub fn handler(args: &ArgMatches) { + if let Some(val) = args.get_one::("path") { + global::global::set_dir_path(val.to_string()); } commands::remote_diff::remote_diff(); } diff --git a/src/subcommands/reset.rs b/src/subcommands/reset.rs index 90593ba..f2bbde9 100644 --- a/src/subcommands/reset.rs +++ b/src/subcommands/reset.rs @@ -1,6 +1,6 @@ -use clap::{App, SubCommand}; +use clap::Command; -pub fn create() -> App<'static, 'static> { - SubCommand::with_name("reset") +pub fn create() -> Command { + Command::new("reset") .about("Clear the index") } diff --git a/src/subcommands/status.rs b/src/subcommands/status.rs index aee3884..031fc3e 100644 --- a/src/subcommands/status.rs +++ b/src/subcommands/status.rs @@ -1,30 +1,30 @@ -use clap::{App, Arg, SubCommand, ArgMatches}; +use clap::{Arg, Command, ArgMatches}; use crate::global; use crate::commands; use crate::commands::status::StatusArgs; -pub fn create() -> App<'static, 'static> { - SubCommand::with_name("status") +pub fn create() -> Command { + Command::new("status") .arg( - Arg::with_name("directory") - .required(false) - .takes_value(true) + Arg::new("directory") + .num_args(1) .value_name("DIRECTORY") ) .arg( - Arg::with_name("nostyle") + Arg::new("nostyle") .long("nostyle") .help("Status with minium information and style"), ) .about("Show the working tree status") } -pub fn handler(args: &ArgMatches<'_>) { - if let Some(val) = args.values_of("directory") { - global::global::set_dir_path(String::from(val.clone().next().unwrap())); +pub fn handler(args: &ArgMatches) { + if let Some(val) = args.get_one::("directory") { + global::global::set_dir_path(val.to_string()); } + commands::status::status(StatusArgs { - nostyle: args.is_present("nostyle"), + nostyle: args.contains_id("nostyle"), }); }