diff --git a/Cargo.lock b/Cargo.lock index 0d2d340..c572683 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,12 +11,54 @@ dependencies = [ "memchr", ] +[[package]] +name = "anstream" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + [[package]] name = "anstyle" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "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]] name = "anyhow" version = "1.0.79" @@ -38,17 +80,6 @@ dependencies = [ "wait-timeout", ] -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -104,28 +135,36 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "3.2.25" +version = "4.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +checksum = "52bdc885e4cacc7f7c9eedc1ef6da641603180c783c41a15c264944deeaab642" dependencies = [ - "atty", - "bitflags 1.3.2", + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9" +dependencies = [ + "anstream", + "anstyle", "clap_lex", - "indexmap 1.9.3", - "once_cell", "strsim", - "termcolor", - "textwrap", ] [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "combine" @@ -399,27 +438,12 @@ dependencies = [ "memmap2", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "hashbrown" 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 = "home" version = "0.5.9" @@ -455,16 +479,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", -] - [[package]] name = "indexmap" version = "2.1.0" @@ -472,7 +486,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", - "hashbrown 0.14.3", + "hashbrown", ] [[package]] @@ -619,12 +633,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "os_str_bytes" -version = "6.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" - [[package]] name = "percent-encoding" version = "2.3.1" @@ -800,7 +808,7 @@ version = "0.9.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1bf28c79a99f70ee1f1d83d10c875d2e70618417fda01ad1785e027579d9d38" dependencies = [ - "indexmap 2.1.0", + "indexmap", "itoa", "ryu", "serde", @@ -852,12 +860,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - [[package]] name = "thiserror" version = "1.0.56" @@ -941,6 +943,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "wait-timeout" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 4b93050..c92bce8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ path = "src/wints/lib.rs" [dependencies] anyhow = "1.0" -clap = { version = "3", features = ["cargo"] } +clap = { version = "4.4", features = ["cargo"] } directories-next = "2.0" fuzzy-matcher = "0.3" glob = "0.3" diff --git a/src/bin/wints/cli.rs b/src/bin/wints/cli.rs index c28c245..05a0c35 100644 --- a/src/bin/wints/cli.rs +++ b/src/bin/wints/cli.rs @@ -1,7 +1,7 @@ -use crate::commands; use anyhow::Result; -use clap::AppSettings; -use wints::util::command_prelude::*; +use clap::Command; + +use crate::commands; pub fn main() -> Result<()> { let matches = cli().get_matches(); @@ -17,17 +17,14 @@ pub fn main() -> Result<()> { command_exec(command_args) } -fn cli() -> clap::App<'static> { +fn cli() -> Command { let args = commands::global_args(); let subcommands = commands::builtin(); - App::new("wints") + Command::new("wints") .about("What I Need To See - a fuzzy term-based URLs opener") .version(crate_version!()) - .settings(&[ - AppSettings::DeriveDisplayOrder, - AppSettings::AllowExternalSubcommands, - ]) + .allow_external_subcommands(true) .args(args) .subcommands(subcommands) } diff --git a/src/bin/wints/commands/add.rs b/src/bin/wints/commands/add.rs index bbf7367..8cbb134 100644 --- a/src/bin/wints/commands/add.rs +++ b/src/bin/wints/commands/add.rs @@ -1,27 +1,28 @@ -use crate::commands::{general_args, global_arg, module_arg}; use anyhow::Result; -use clap::ArgMatches; -use directories_next::BaseDirs; -use std::path::PathBuf; +use clap::{Arg, ArgMatches, Command}; + use wints::ops; use wints::ops::wints_add::AddOptions; -use wints::util::command_prelude::*; -pub fn command() -> App { - subcommand("add") +use crate::commands::{ + general_args, get_global_basedir, get_pathbuf_arg, get_string_arg, global_arg, module_arg, +}; + +pub fn command() -> Command { + Command::new("add") .about("Add a url to a context") .args(general_args()) .arg(module_arg()) .arg(global_arg()) .arg( - arg("url") + Arg::new("url") .help("URL to set") .value_name("URL") .required(true) .index(1), ) .arg( - arg("context") + Arg::new("context") .help("Context of the URL") .value_name("CONTEXT") .required(true) @@ -30,16 +31,13 @@ pub fn command() -> App { } pub fn exec(args: &ArgMatches) -> Result<()> { - let local_basedir = PathBuf::from(args.value_of("config").unwrap().to_string()); - let global_basedir = match args.value_of("global-config") { - None => BaseDirs::new().unwrap().home_dir().join(".wints"), - Some(value) => PathBuf::from(value), - }; - let module_name = args.value_of("module").unwrap().to_string(); - let url = args.value_of("url").unwrap().to_string(); - let context = args.value_of("context").unwrap().to_string(); - let global_module = args.is_present("global"); - let dry_run = args.is_present("dry-run"); + let local_basedir = get_pathbuf_arg(args, "config"); + let global_basedir = get_global_basedir(args); + let module_name = get_string_arg(args, "module"); + let url = get_string_arg(args, "url"); + let context = get_string_arg(args, "context"); + let global_module = args.get_flag("global"); + let dry_run = args.get_flag("dry-run"); ops::wints_add::add(AddOptions { local_basedir, diff --git a/src/bin/wints/commands/init.rs b/src/bin/wints/commands/init.rs index 4224169..9ae07fe 100644 --- a/src/bin/wints/commands/init.rs +++ b/src/bin/wints/commands/init.rs @@ -1,38 +1,37 @@ -use crate::commands::{general_args, global_arg, module_arg}; use anyhow::Result; -use clap::ArgMatches; -use directories_next::BaseDirs; -use std::path::PathBuf; +use clap::builder::PossibleValuesParser; +use clap::{Arg, ArgMatches, Command}; + use wints::ops; use wints::ops::wints_init::InitOptions; -use wints::util::command_prelude::*; -pub fn command() -> App { - subcommand("init") +use crate::commands::{ + general_args, get_global_basedir, get_pathbuf_arg, get_string_arg, global_arg, module_arg, +}; + +pub fn command() -> Command { + Command::new("init") .about("Initialise a new module") .args(general_args()) .arg(module_arg()) .arg(global_arg()) .arg( - arg("template") + Arg::new("template") .help("Template name to use") .value_name("TEMPLATE") - .possible_values(["empty", "default"]) + .value_parser(PossibleValuesParser::new(["empty", "default"])) .default_value("empty") .index(1), ) } pub fn exec(args: &ArgMatches) -> Result<()> { - let local_basedir = PathBuf::from(args.value_of("config").unwrap().to_string()); - let global_basedir = match args.value_of("global-config") { - None => BaseDirs::new().unwrap().home_dir().join(".wints"), - Some(value) => PathBuf::from(value), - }; - let module_name = args.value_of("module").unwrap().to_string(); - let template = args.value_of("template").unwrap().to_string(); - let global_module = args.is_present("global"); - let dry_run = args.is_present("dry-run"); + let local_basedir = get_pathbuf_arg(args, "config"); + let global_basedir = get_global_basedir(args); + let module_name = get_string_arg(args, "module"); + let template = get_string_arg(args, "template"); + let global_module = args.get_flag("global"); + let dry_run = args.get_flag("dry-run"); ops::wints_init::init(InitOptions { local_basedir, diff --git a/src/bin/wints/commands/mod.rs b/src/bin/wints/commands/mod.rs index e22168c..001574c 100644 --- a/src/bin/wints/commands/mod.rs +++ b/src/bin/wints/commands/mod.rs @@ -1,14 +1,17 @@ +use std::path::PathBuf; + +use anyhow::Result; +use clap::ArgAction::SetTrue; +use clap::{Arg, ArgMatches, Command}; +use directories_next::BaseDirs; + mod add; mod init; mod scan; mod search; mod url; -use anyhow::Result; -use clap::ArgMatches; -use wints::util::command_prelude::*; - -pub fn builtin() -> Vec { +pub fn builtin() -> Vec { vec![ init::command(), add::command(), @@ -26,26 +29,27 @@ pub fn global_args() -> Vec { pub fn general_args() -> Vec { vec![ - arg("config") + Arg::new("config") .help("Folder of local configuration storage") .value_name("PATH") .default_value(".wints") .short('C') .long("config"), - arg("global-config") + Arg::new("global-config") .help("Folder of global configuration storage [default: HOME_DIR/.wints]") .value_name("PATH") .short('G') .long("global-config"), - arg("dry-run") + Arg::new("dry-run") .help("Do not actually change anything, just log what are going to do") .short('n') - .long("dry-run"), + .long("dry-run") + .action(SetTrue), ] } pub fn module_arg() -> Arg { - arg("module") + Arg::new("module") .help("Module name to use") .value_name("MODULE NAME") .default_value("main") @@ -54,10 +58,11 @@ pub fn module_arg() -> Arg { } pub fn global_arg() -> Arg { - arg("global") + Arg::new("global") .help("Work with global configuration") .short('g') .long("global") + .action(SetTrue) } pub fn builtin_exec(cmd: &str) -> fn(&ArgMatches) -> Result<()> { @@ -73,3 +78,21 @@ pub fn builtin_exec(cmd: &str) -> fn(&ArgMatches) -> Result<()> { pub fn global_exec() -> fn(&ArgMatches) -> Result<()> { search::exec } + +fn get_string_arg(args: &ArgMatches, arg_name: &str) -> String { + args.get_one::(arg_name) + .map(|s| s.as_str()) + .unwrap() + .to_string() +} + +fn get_pathbuf_arg(args: &ArgMatches, arg_name: &str) -> PathBuf { + PathBuf::from(get_string_arg(args, arg_name)) +} + +fn get_global_basedir(args: &ArgMatches) -> PathBuf { + match args.get_one::("global-config").map(|s| s.as_str()) { + None => BaseDirs::new().unwrap().home_dir().join(".wints"), + Some(value) => PathBuf::from(value), + } +} diff --git a/src/bin/wints/commands/scan.rs b/src/bin/wints/commands/scan.rs index 32c681e..05774d9 100644 --- a/src/bin/wints/commands/scan.rs +++ b/src/bin/wints/commands/scan.rs @@ -1,20 +1,21 @@ -use crate::commands::{general_args, global_arg, module_arg}; use anyhow::Result; -use clap::ArgMatches; -use directories_next::BaseDirs; -use std::path::PathBuf; +use clap::{Arg, ArgMatches, Command}; + use wints::ops; use wints::ops::wints_scan::ScanOptions; -use wints::util::command_prelude::*; -pub fn command() -> App { - subcommand("scan") +use crate::commands::{ + general_args, get_global_basedir, get_pathbuf_arg, get_string_arg, global_arg, module_arg, +}; + +pub fn command() -> Command { + Command::new("scan") .about("Scan a directory tree for new URLs") .args(general_args()) .arg(module_arg()) .arg(global_arg()) .arg( - arg("path") + Arg::new("path") .help("Path to scan (file or directories)") .value_name("PATH") .default_value(".") @@ -23,15 +24,12 @@ pub fn command() -> App { } pub fn exec(args: &ArgMatches) -> Result<()> { - let local_basedir = PathBuf::from(args.value_of("config").unwrap().to_string()); - let global_basedir = match args.value_of("global-config") { - None => BaseDirs::new().unwrap().home_dir().join(".wints"), - Some(value) => PathBuf::from(value), - }; - let module_name = args.value_of("module").unwrap().to_string(); - let scan_path = PathBuf::from(args.value_of("path").unwrap()); - let global_module = args.is_present("global"); - let dry_run = args.is_present("dry-run"); + let local_basedir = get_pathbuf_arg(args, "config"); + let global_basedir = get_global_basedir(args); + let module_name = get_string_arg(args, "module"); + let scan_path = get_pathbuf_arg(args, "path"); + let global_module = args.get_flag("global"); + let dry_run = args.get_flag("dry-run"); ops::wints_scan::scan(ScanOptions { local_basedir, diff --git a/src/bin/wints/commands/search.rs b/src/bin/wints/commands/search.rs index 077f01c..1a060d0 100644 --- a/src/bin/wints/commands/search.rs +++ b/src/bin/wints/commands/search.rs @@ -1,31 +1,28 @@ -use crate::commands::module_arg; use anyhow::Result; -use clap::ArgMatches; -use directories_next::BaseDirs; -use std::path::PathBuf; +use clap::{Arg, ArgMatches}; + use wints::ops; use wints::ops::wints_search::SearchOptions; -use wints::util::command_prelude::*; + +use crate::commands::{get_global_basedir, get_pathbuf_arg, get_string_arg, module_arg}; pub fn args() -> Vec { vec![ module_arg(), - arg("terms") + Arg::new("terms") .help("Terms to search for") .value_name("TERM") - //.conflicts_with("scan") - .multiple(true) + .num_args(1..) .index(1), ] } pub fn exec(args: &ArgMatches) -> Result<()> { - let local_basedir = PathBuf::from(args.value_of("config").unwrap().to_string()); - let global_basedir = match args.value_of("global-config") { - None => BaseDirs::new().unwrap().home_dir().join(".wints"), - Some(value) => PathBuf::from(value), - }; - let module_name = args.value_of("module").unwrap().to_string(); + let local_basedir = get_pathbuf_arg(args, "config"); + let global_basedir = get_global_basedir(args); + let module_name = get_string_arg(args, "module"); + let dry_run = args.get_flag("dry-run"); + let matching_terms = args.get_many::("terms").map(|values_ref| { values_ref .collect::>() @@ -34,8 +31,6 @@ pub fn exec(args: &ArgMatches) -> Result<()> { .collect() }); - let dry_run = args.is_present("dry-run"); - ops::wints_search::search(SearchOptions { local_basedir, global_basedir, diff --git a/src/bin/wints/commands/url.rs b/src/bin/wints/commands/url.rs index d022771..e90be43 100644 --- a/src/bin/wints/commands/url.rs +++ b/src/bin/wints/commands/url.rs @@ -1,23 +1,24 @@ -use crate::commands::{general_args, global_arg}; use anyhow::Result; -use clap::ArgMatches; -use directories_next::BaseDirs; -use std::path::PathBuf; +use clap::{Arg, ArgMatches, Command}; + use wints::ops; use wints::ops::wints_url_ignore::IgnoreUrlOptions; use wints::ops::wints_url_ignore_glob::IgnoreGlobOptions; -use wints::util::command_prelude::*; -pub fn command() -> App { - subcommand("url") +use crate::commands::{ + general_args, get_global_basedir, get_pathbuf_arg, get_string_arg, global_arg, +}; + +pub fn command() -> Command { + Command::new("url") .about("Actions about url configuration") .subcommand( - subcommand("ignore") + Command::new("ignore") .about("Add an URL to the ignore list during scan") .args(general_args()) .arg(global_arg()) .arg( - arg("url") + Arg::new("url") .help("URL to ignore") .value_name("URL") .required(true) @@ -25,12 +26,12 @@ pub fn command() -> App { ), ) .subcommand( - subcommand("ignore-glob") + Command::new("ignore-glob") .about("Add an glob/file to the ignore list during scan") .args(general_args()) .arg(global_arg()) .arg( - arg("glob") + Arg::new("glob") .help("Glob/file to ignore") .value_name("GLOB") .required(true) @@ -48,14 +49,11 @@ pub fn exec(args: &ArgMatches) -> Result<()> { } pub fn exec_ignore(args: &ArgMatches) -> Result<()> { - let local_basedir = PathBuf::from(args.value_of("config").unwrap().to_string()); - let global_basedir = match args.value_of("global-config") { - None => BaseDirs::new().unwrap().home_dir().join(".wints"), - Some(value) => PathBuf::from(value), - }; - let url = args.value_of("url").unwrap().to_string(); - let global = args.is_present("global"); - let dry_run = args.is_present("dry-run"); + let local_basedir = get_pathbuf_arg(args, "config"); + let global_basedir = get_global_basedir(args); + let url = get_string_arg(args, "url"); + let global = args.get_flag("global"); + let dry_run = args.get_flag("dry-run"); ops::wints_url_ignore::ignore_url(IgnoreUrlOptions { local_basedir, @@ -67,14 +65,11 @@ pub fn exec_ignore(args: &ArgMatches) -> Result<()> { } pub fn exec_ignore_glob(args: &ArgMatches) -> Result<()> { - let local_basedir = PathBuf::from(args.value_of("config").unwrap().to_string()); - let global_basedir = match args.value_of("global-config") { - None => BaseDirs::new().unwrap().home_dir().join(".wints"), - Some(value) => PathBuf::from(value), - }; - let glob = args.value_of("glob").unwrap().to_string(); - let global = args.is_present("global"); - let dry_run = args.is_present("dry-run"); + let local_basedir = get_pathbuf_arg(args, "config"); + let global_basedir = get_global_basedir(args); + let glob = get_string_arg(args, "glob"); + let global = args.get_flag("global"); + let dry_run = args.get_flag("dry-run"); ops::wints_url_ignore_glob::ignore_glob(IgnoreGlobOptions { local_basedir, diff --git a/src/bin/wints/main.rs b/src/bin/wints/main.rs index eb3054a..b073a54 100644 --- a/src/bin/wints/main.rs +++ b/src/bin/wints/main.rs @@ -1,11 +1,11 @@ #[macro_use] extern crate clap; +use anyhow::Result; + pub mod cli; pub mod commands; -use anyhow::Result; - fn main() -> Result<()> { cli::main() } diff --git a/src/wints/core/module.rs b/src/wints/core/module.rs index 199fcea..4a80b33 100644 --- a/src/wints/core/module.rs +++ b/src/wints/core/module.rs @@ -208,7 +208,7 @@ mod tests { "https://test1.tld", "https://test2.tld", "https://test3.tld", - "https://test4.tld" + "https://test4.tld", ], module.list_of_all_urls() ); @@ -260,7 +260,7 @@ mod tests { "https://test1.tld", "https://test2.tld", "https://test3.tld", - "https://test4.tld" + "https://test4.tld", ], module.list_of_urls_from_matching_context(vec_of_strings!["terms"]) ); diff --git a/src/wints/core/storage.rs b/src/wints/core/storage.rs index 8f982a6..962bce2 100644 --- a/src/wints/core/storage.rs +++ b/src/wints/core/storage.rs @@ -1,12 +1,14 @@ -use crate::core::config::WintsConfig; -use crate::core::module::WintsModule; -use anyhow::Result; use std::collections::HashMap; use std::fs; use std::fs::{File, OpenOptions}; use std::io::Write; use std::path::PathBuf; +use anyhow::Result; + +use crate::core::config::WintsConfig; +use crate::core::module::WintsModule; + #[derive(Debug)] pub struct WintsStorage { local_basedir: PathBuf, diff --git a/src/wints/ops/wints_add.rs b/src/wints/ops/wints_add.rs index f8acf7c..ed02387 100644 --- a/src/wints/ops/wints_add.rs +++ b/src/wints/ops/wints_add.rs @@ -1,7 +1,9 @@ +use std::path::PathBuf; + +use anyhow::Result; + use crate::core::storage::WintsStorage; use crate::util::log::{DRY_RUN, WRITE}; -use anyhow::Result; -use std::path::PathBuf; pub struct AddOptions { pub local_basedir: PathBuf, diff --git a/src/wints/ops/wints_init.rs b/src/wints/ops/wints_init.rs index 4da9ea6..d2fa5cc 100644 --- a/src/wints/ops/wints_init.rs +++ b/src/wints/ops/wints_init.rs @@ -1,9 +1,11 @@ +use std::path::PathBuf; +use std::process; + +use anyhow::Result; + use crate::core::module::WintsModule; use crate::core::storage::WintsStorage; use crate::util::log::{CAUTION, DRY_RUN, WRITE}; -use anyhow::Result; -use std::path::PathBuf; -use std::process; pub struct InitOptions { pub local_basedir: PathBuf, diff --git a/src/wints/ops/wints_scan.rs b/src/wints/ops/wints_scan.rs index e9c134c..3080a5b 100644 --- a/src/wints/ops/wints_scan.rs +++ b/src/wints/ops/wints_scan.rs @@ -1,8 +1,10 @@ +use std::path::PathBuf; + +use anyhow::Result; + use crate::core::storage::WintsStorage; use crate::util::log::{DONE, DRY_RUN, INFO, SAD, SEARCH, WRITE}; use crate::util::url_scanner; -use anyhow::Result; -use std::path::PathBuf; pub struct ScanOptions { pub local_basedir: PathBuf, diff --git a/src/wints/ops/wints_search.rs b/src/wints/ops/wints_search.rs index 52017d7..a40093f 100644 --- a/src/wints/ops/wints_search.rs +++ b/src/wints/ops/wints_search.rs @@ -1,9 +1,11 @@ +use std::path::PathBuf; +use std::process; + +use anyhow::Result; + use crate::core::module::WintsModule; use crate::core::storage::WintsStorage; use crate::util::log::{CAUTION, DONE, DRY_RUN, GOTO, INFO, SAD, SEARCH, TRY}; -use anyhow::Result; -use std::path::PathBuf; -use std::process; pub struct SearchOptions { pub local_basedir: PathBuf, diff --git a/src/wints/ops/wints_url_ignore.rs b/src/wints/ops/wints_url_ignore.rs index 947d979..24dbd2b 100644 --- a/src/wints/ops/wints_url_ignore.rs +++ b/src/wints/ops/wints_url_ignore.rs @@ -1,7 +1,9 @@ +use std::path::PathBuf; + +use anyhow::Result; + use crate::core::storage::WintsStorage; use crate::util::log::{DRY_RUN, WRITE}; -use anyhow::Result; -use std::path::PathBuf; pub struct IgnoreUrlOptions { pub local_basedir: PathBuf, diff --git a/src/wints/ops/wints_url_ignore_glob.rs b/src/wints/ops/wints_url_ignore_glob.rs index fabf8f7..35af784 100644 --- a/src/wints/ops/wints_url_ignore_glob.rs +++ b/src/wints/ops/wints_url_ignore_glob.rs @@ -1,7 +1,9 @@ +use std::path::PathBuf; + +use anyhow::Result; + use crate::core::storage::WintsStorage; use crate::util::log::{DRY_RUN, WRITE}; -use anyhow::Result; -use std::path::PathBuf; pub struct IgnoreGlobOptions { pub local_basedir: PathBuf, diff --git a/src/wints/util/command_prelude.rs b/src/wints/util/command_prelude.rs deleted file mode 100644 index 577b24f..0000000 --- a/src/wints/util/command_prelude.rs +++ /dev/null @@ -1,15 +0,0 @@ -use clap::{AppSettings, SubCommand}; - -pub type App = clap::App<'static>; -pub type Arg = clap::Arg<'static>; - -pub fn subcommand(name: &'static str) -> App { - SubCommand::with_name(name).settings(&[ - AppSettings::DeriveDisplayOrder, - AppSettings::DontCollapseArgsInUsage, - ]) -} - -pub fn arg(name: &'static str) -> Arg { - Arg::with_name(name) -} diff --git a/src/wints/util/mod.rs b/src/wints/util/mod.rs index c837b6e..21f3b64 100644 --- a/src/wints/util/mod.rs +++ b/src/wints/util/mod.rs @@ -1,3 +1,2 @@ -pub mod command_prelude; pub mod log; pub mod url_scanner; diff --git a/tests/cli.rs b/tests/cli.rs index bdaab84..5a352c7 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -1,15 +1,15 @@ -mod commands; - -use std::process::Command; - -use anyhow::Result; -use assert_cmd::prelude::*; use std::fs; use std::fs::File; use std::io::Write; use std::path::PathBuf; +use std::process::Command; + +use anyhow::Result; +use assert_cmd::prelude::*; use tempfile::tempdir; +mod commands; + pub struct WintsCommand { pub cmd: Command, pub current_dir: PathBuf, diff --git a/tests/commands/add.rs b/tests/commands/add.rs index 6b46eff..312b1f8 100644 --- a/tests/commands/add.rs +++ b/tests/commands/add.rs @@ -1,9 +1,10 @@ -use crate::WintsCommand; use anyhow::Result; use assert_cmd::prelude::*; use predicate::str::contains; use predicates::prelude::*; +use crate::WintsCommand; + #[test] fn add_to_main_module() -> Result<()> { let mut wints = WintsCommand::new()?; diff --git a/tests/commands/init.rs b/tests/commands/init.rs index 9cb576a..56cef86 100644 --- a/tests/commands/init.rs +++ b/tests/commands/init.rs @@ -1,9 +1,10 @@ -use crate::WintsCommand; use anyhow::Result; use assert_cmd::prelude::*; use predicate::str::contains; use predicates::prelude::*; +use crate::WintsCommand; + #[test] fn no_template() -> Result<()> { let mut wints = WintsCommand::new()?; diff --git a/tests/commands/scan.rs b/tests/commands/scan.rs index 065cafd..2f13303 100644 --- a/tests/commands/scan.rs +++ b/tests/commands/scan.rs @@ -1,9 +1,10 @@ -use crate::WintsCommand; use anyhow::Result; use assert_cmd::prelude::*; use predicate::str::contains; use predicates::prelude::*; +use crate::WintsCommand; + #[test] fn specific_path() -> Result<()> { let mut wints = WintsCommand::new()?; diff --git a/tests/commands/search.rs b/tests/commands/search.rs index 5a1dc89..94e776c 100644 --- a/tests/commands/search.rs +++ b/tests/commands/search.rs @@ -1,9 +1,10 @@ -use crate::WintsCommand; use anyhow::Result; use assert_cmd::prelude::*; use predicate::str::contains; use predicates::prelude::*; +use crate::WintsCommand; + #[test] fn using_unknown_module() -> Result<()> { let mut wints = WintsCommand::new()?; diff --git a/tests/commands/url_ignore.rs b/tests/commands/url_ignore.rs index e732738..cb11ada 100644 --- a/tests/commands/url_ignore.rs +++ b/tests/commands/url_ignore.rs @@ -1,9 +1,11 @@ -use crate::WintsCommand; +use std::fs; + use anyhow::Result; use assert_cmd::prelude::*; use predicate::str::contains; use predicates::prelude::*; -use std::fs; + +use crate::WintsCommand; #[test] fn ignore_locally() -> Result<()> { diff --git a/tests/commands/url_ignore_glob.rs b/tests/commands/url_ignore_glob.rs index b1d6818..37b70c5 100644 --- a/tests/commands/url_ignore_glob.rs +++ b/tests/commands/url_ignore_glob.rs @@ -1,9 +1,11 @@ -use crate::WintsCommand; +use std::fs; + use anyhow::Result; use assert_cmd::prelude::*; use predicate::str::contains; use predicates::prelude::*; -use std::fs; + +use crate::WintsCommand; #[test] fn ignore_glob_locally() -> Result<()> {