diff options
author | Canop <cano.petrole@gmail.com> | 2022-06-07 18:59:31 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2022-06-07 18:59:31 +0200 |
commit | 1c61e362e614afebfd55591fbc37efde084795ad (patch) | |
tree | a449aa4864427dd38efad01b2d66bdb8e8a1ae75 | |
parent | 4bcc94ba280eb342e585d9070ddc5adccfa39950 (diff) |
update from clap2 to clap3
-rw-r--r-- | Cargo.lock | 207 | ||||
-rw-r--r-- | Cargo.toml | 7 | ||||
-rw-r--r-- | bacon.toml | 1 | ||||
-rw-r--r-- | build.rs | 31 | ||||
-rw-r--r-- | src/app/selection.rs | 1 | ||||
-rw-r--r-- | src/cli/clap_args.rs | 124 | ||||
-rw-r--r-- | src/cli/install_launch_args.rs | 2 | ||||
-rw-r--r-- | src/cli/mod.rs | 2 | ||||
-rw-r--r-- | src/tree/tree_options.rs | 18 |
9 files changed, 152 insertions, 241 deletions
@@ -51,15 +51,6 @@ dependencies = [ ] [[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - -[[package]] name = "anyhow" version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -149,10 +140,11 @@ dependencies = [ "char_reader", "chrono", "clap", + "clap_complete", "cli-log 2.0.0", "crokey", "crossbeam", - "crossterm 0.23.2", + "crossterm", "custom_error", "deser-hjson", "directories", @@ -251,17 +243,35 @@ dependencies = [ [[package]] name = "clap" -version = "2.34.0" +version = "3.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" dependencies = [ - "ansi_term", "atty", "bitflags", + "clap_lex", + "indexmap", "strsim", + "termcolor", "textwrap", - "unicode-width", - "vec_map", +] + +[[package]] +name = "clap_complete" +version = "3.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da92e6facd8d73c22745a5d3cbb59bdf8e46e3235c923e516527d8e81eec14a4" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_lex" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" +dependencies = [ + "os_str_bytes", ] [[package]] @@ -309,7 +319,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af4d7a805ca0d92f8c61a31c809d4323fdaa939b0b440e544d21db7797c5aaad" dependencies = [ - "crossterm 0.23.2", + "crossterm", ] [[package]] @@ -328,7 +338,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd55b26d7b832a245ff71f470688539afccf705ab74b7f0fbb8da43bafcafcf8" dependencies = [ "crokey-proc_macros", - "crossterm 0.23.2", + "crossterm", "once_cell", "serde", ] @@ -415,63 +425,22 @@ dependencies = [ [[package]] name = "crossterm" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c36c10130df424b2f3552fcc2ddcd9b28a27b1e54b358b45874f88d1ca6888c" -dependencies = [ - "bitflags", - "crossterm_winapi 0.7.0", - "lazy_static", - "libc", - "mio 0.7.14", - "parking_lot 0.11.2", - "signal-hook 0.1.17", - "winapi", -] - -[[package]] -name = "crossterm" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c85525306c4291d1b73ce93c8acf9c339f9b213aef6c1d85c3830cbf1c16325c" -dependencies = [ - "bitflags", - "crossterm_winapi 0.9.0", - "libc", - "mio 0.7.14", - "parking_lot 0.11.2", - "signal-hook 0.3.14", - "signal-hook-mio", - "winapi", -] - -[[package]] -name = "crossterm" version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2102ea4f781910f8a5b98dd061f4c2023f479ce7bb1236330099ceb5a93cf17" dependencies = [ "bitflags", - "crossterm_winapi 0.9.0", + "crossterm_winapi", "libc", - "mio 0.8.3", - "parking_lot 0.12.1", - "signal-hook 0.3.14", + "mio", + "parking_lot", + "signal-hook", "signal-hook-mio", "winapi", ] [[package]] name = "crossterm_winapi" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0da8964ace4d3e4a044fd027919b2237000b24315a37c916f61809f1ff2140b9" -dependencies = [ - "winapi", -] - -[[package]] -name = "crossterm_winapi" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c" @@ -503,15 +472,15 @@ dependencies = [ [[package]] name = "csv2svg" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8e2619b51a7edc3570447c19b821b4f8e17b4e0ddab688582f6ceb2a83acf07" +checksum = "5eede96fa4be061f1b49b92c756f8d150de9fbb5b11e09c6c2b3d670e32fd9f5" dependencies = [ "anyhow", "argh", "chrono", "cli-log 0.1.0", - "crossterm 0.19.0", + "crossterm", "csv", "directories-next", "libc", @@ -699,13 +668,13 @@ dependencies = [ [[package]] name = "glassbench" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "133c8a14cc4a000675a871544b164f446964090897cdaa2448081a56bd2a72bc" +checksum = "b56c8dd194e65fc268f379096640af9443f5f79386392131b75d66faff5d59f4" dependencies = [ "base64", "chrono", - "crossterm 0.22.1", + "crossterm", "csv2svg", "git2", "lazy_static", @@ -1052,19 +1021,6 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" -dependencies = [ - "libc", - "log", - "miow", - "ntapi", - "winapi", -] - -[[package]] -name = "mio" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799" @@ -1076,15 +1032,6 @@ dependencies = [ ] [[package]] -name = "miow" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" -dependencies = [ - "winapi", -] - -[[package]] name = "nix" version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1098,15 +1045,6 @@ dependencies = [ ] [[package]] -name = "ntapi" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" -dependencies = [ - "winapi", -] - -[[package]] name = "num-integer" version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1215,15 +1153,10 @@ dependencies = [ ] [[package]] -name = "parking_lot" -version = "0.11.2" +name = "os_str_bytes" +version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core 0.8.5", -] +checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" [[package]] name = "parking_lot" @@ -1232,21 +1165,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.3", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall", - "smallvec", - "winapi", + "parking_lot_core", ] [[package]] @@ -1603,17 +1522,6 @@ dependencies = [ [[package]] name = "signal-hook" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e31d442c16f047a671b5a71e2161d6e68814012b7f5379d269ebd915fac2729" -dependencies = [ - "libc", - "mio 0.7.14", - "signal-hook-registry", -] - -[[package]] -name = "signal-hook" version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a253b5e89e2698464fc26b545c9edceb338e18a89effeeecfea192c3025be29d" @@ -1629,9 +1537,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" dependencies = [ "libc", - "mio 0.7.14", - "mio 0.8.3", - "signal-hook 0.3.14", + "mio", + "signal-hook", ] [[package]] @@ -1697,9 +1604,9 @@ checksum = "991af58f8bd0512b0c76abc87f8f6a8a492c314ebcd13189b426c00c95f6f0ee" [[package]] name = "strsim" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "svg" @@ -1755,6 +1662,15 @@ dependencies = [ ] [[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] name = "termimad" version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1762,7 +1678,7 @@ checksum = "c8a16d7de8d4c97a4149cc3b9d3681c5dba36011c303745bb1af19636e89ba39" dependencies = [ "coolor", "crossbeam", - "crossterm 0.23.2", + "crossterm", "minimad", "thiserror", "unicode-width", @@ -1788,12 +1704,9 @@ checksum = "9f6aff13ca3293315b94f6dbd9c69e1c958fe421c294681e2ffda80c9858e36f" [[package]] name = "textwrap" -version = "0.11.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thiserror" @@ -1939,12 +1852,6 @@ 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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -25,7 +25,7 @@ ansi_colours = "1.0" base64 = "0.13" bet = "1.0" char_reader = "0.1" -clap = { version="2.33", default-features=false, features=["suggestions", "color"] } +clap = "3.1" cli-log = "2.0" chrono = "0.4" crokey = "0.4.1" @@ -65,7 +65,7 @@ umask = "2.0.0" unicode-width = "0.1.8" [dev-dependencies] -glassbench = "0.3.2" +glassbench = "0.3.3" [target.'cfg(unix)'.dependencies] lfs-core = "0.11.0" @@ -75,7 +75,8 @@ users = "0.11" is_executable = "1.0.1" [build-dependencies] -clap = "2.33" +clap = "3.1" +clap_complete = "3.1" [profile.dev] debug = false @@ -39,6 +39,7 @@ command = [ "-A", "clippy::manual_unwrap_or", "-A", "clippy::len_without_is_empty", "-A", "clippy::manual_range_contains", + "-A", "clippy::neg_multiply", ] need_stdout = false @@ -2,28 +2,37 @@ // It builds shell completion scripts. use { - clap::Shell, + clap_complete::{Generator, Shell}, std::{ env, - str::FromStr, + ffi::OsStr, }, }; include!("src/cli/clap_args.rs"); +fn write_completions_file<G: Generator + Copy, P: AsRef<OsStr>>(generator: G, out_dir: P) { + let mut app = clap_app(); + for name in &["broot", "br"] { + clap_complete::generate_to( + generator, + &mut app, + name.to_string(), + &out_dir, + ).expect("clap complete generation failed"); + } +} + /// write the shell completion scripts which will be added to /// the release archive fn build_completion_scripts() { - // out_dir should be defined, see - // https://doc.rust-lang.org/cargo/reference/environment-variables.html let out_dir = env::var_os("OUT_DIR").expect("out dir not set"); - let mut app = clap_app(); - for variant in &Shell::variants() { - let variant = Shell::from_str(variant).unwrap(); - app.gen_completions("broot", variant, &out_dir); - app.gen_completions("br", variant, &out_dir); - } - println!("completion scripts generated in {:?}", out_dir); + write_completions_file(Shell::Bash, &out_dir); + write_completions_file(Shell::Elvish, &out_dir); + write_completions_file(Shell::Fish, &out_dir); + write_completions_file(Shell::PowerShell, &out_dir); + write_completions_file(Shell::Zsh, &out_dir); + eprintln!("completion scripts generated in {:?}", out_dir); } fn main() { diff --git a/src/app/selection.rs b/src/app/selection.rs index f435dcb..7eabbf7 100644 --- a/src/app/selection.rs +++ b/src/app/selection.rs @@ -131,6 +131,7 @@ impl<'a> SelInfo<'a> { SelInfo::More(stage) => { let common_extension = stage.paths()[0] .extension().and_then(|e| e.to_str()); + #[allow(clippy::question_mark)] if common_extension.is_none() { return None; } diff --git a/src/cli/clap_args.rs b/src/cli/clap_args.rs index bf4fe69..0ac9524 100644 --- a/src/cli/clap_args.rs +++ b/src/cli/clap_args.rs @@ -1,166 +1,165 @@ /// this module generate the clap App, which defines /// launch arguments -/// declare the possible CLI arguments -pub fn clap_app() -> clap::App<'static, 'static> { - let app = clap::App::new("broot") +/// Declare the possible CLI arguments +pub fn clap_app() -> clap::Command<'static> { + let app = clap::Command::new("broot") .version(env!("CARGO_PKG_VERSION")) .author("dystroy <denys.seguret@gmail.com>") .about( "A tree explorer and a customizable launcher\n\ Complete documentation lives at https://dystroy.org/broot" ) - .setting(clap::AppSettings::ColoredHelp) - .arg(clap::Arg::with_name("ROOT").help("sets the root directory")) + .arg(clap::Arg::new("ROOT").help("sets the root directory")) // tree flags .arg( - clap::Arg::with_name("dates") - .short("d") + clap::Arg::new("dates") + .short('d') .long("dates") .help("Show the last modified date of files and directories"), ) .arg( - clap::Arg::with_name("no-dates") - .short("D") + clap::Arg::new("no-dates") + .short('D') .long("no-dates") .help("Don't show last modified date"), ) .arg( - clap::Arg::with_name("only-folders") - .short("f") + clap::Arg::new("only-folders") + .short('f') .long("only-folders") .help("Only show folders"), ) .arg( - clap::Arg::with_name("no-only-folders") - .short("F") + clap::Arg::new("no-only-folders") + .short('F') .long("no-only-folders") .help("Show folders and files alike"), ) .arg( - clap::Arg::with_name("show-root-fs") + clap::Arg::new("show-root-fs") .long("show-root-fs") .help("Show filesystem info on top"), ) .arg( - clap::Arg::with_name("show-git-info") - .short("g") + clap::Arg::new("show-git-info") + .short('g') .long("show-git-info") .help("Show git statuses on files and stats on repo"), ) .arg( - clap::Arg::with_name("no-show-git-info") - .short("G") + clap::Arg::new("no-show-git-info") + .short('G') .long("no-show-git-info") .help("Don't show git statuses on files"), ) .arg( - clap::Arg::with_name("git-status") + clap::Arg::new("git-status") .long("git-status") .help("Only show files having an interesting git status, including hidden ones"), ) .arg( - clap::Arg::with_name("hidden") - .short("h") + clap::Arg::new("hidden") + .short('h') .long("hidden") .help("Show hidden files"), ) .arg( - clap::Arg::with_name("no-hidden") - .short("H") + clap::Arg::new("no-hidden") + .short('H') .long("no-hidden") .help("Don't show hidden files"), ) .arg( - clap::Arg::with_name("show-gitignored") - .short("i") + clap::Arg::new("show-gitignored") + .short('i') .long("show-gitignored") .help("Show files which should be ignored according to git"), ) .arg( - clap::Arg::with_name("no-show-gitignored") - .short("I") + clap::Arg::new("no-show-gitignored") + .short('I') .long("no-show-gitignored") .help("Don't show gitignored files"), ) .arg( - clap::Arg::with_name("permissions") - .short("p") + clap::Arg::new("permissions") + .short('p') .long("permissions") .help("Show permissions, with owner and group"), ) .arg( - clap::Arg::with_name("no-permissions") - .short("P") + clap::Arg::new("no-permissions") + .short('P') .long("no-permissions") .help("Don't show permissions"), ) .arg( - clap::Arg::with_name("sizes") - .short("s") + clap::Arg::new("sizes") + .short('s') .long("sizes") .help("Show the size of files and directories"), ) .arg( - clap::Arg::with_name("no-sizes") - .short("S") + clap::Arg::new("no-sizes") + .short('S') .long("no-sizes") .help("Don't show sizes"), ) .arg( - clap::Arg::with_name("sort-by-count") + clap::Arg::new("sort-by-count") .long("sort-by-count") .help("Sort by count (only show one level of the tree)"), ) .arg( - clap::Arg::with_name("sort-by-date") + clap::Arg::new("sort-by-date") .long("sort-by-date") .help("Sort by date (only show one level of the tree)"), ) .arg( - clap::Arg::with_name("sort-by-size") + clap::Arg::new("sort-by-size") .long("sort-by-size") .help("Sort by size (only show one level of the tree)"), ) .arg( - clap::Arg::with_name("whale-spotting") - .short("w") + clap::Arg::new("whale-spotting") + .short('w') .long("whale-spotting") .help("Sort by size, show ignored and hidden files"), ) .arg( - clap::Arg::with_name("no-sort") + clap::Arg::new("no-sort") .long("no-sort") .help("Don't sort"), ) .arg( - clap::Arg::with_name("trim-root") - .short("t") + clap::Arg::new("trim-root") + .short('t') .long("trim-root") .help("Trim the root too and don't show a scrollbar"), ) .arg( - clap::Arg::with_name("no-trim-root") - .short("T") + clap::Arg::new("no-trim-root") + .short('T') .long("no-trim-root") .help("Don't trim the root level, show a scrollbar"), ) // other options .arg( - clap::Arg::with_name("cmd-export-path") + clap::Arg::new("cmd-export-path") .long("outcmd") .takes_value(true) .help("Where to write the produced cmd (if any)"), ) .arg( - clap::Arg::with_name("commands") - .short("c") + clap::Arg::new("commands") + .short('c') .long("cmd") .takes_value(true) .help("Semicolon separated commands to execute"), ) .arg( - clap::Arg::with_name("color") + clap::Arg::new("color") .long("color") .takes_value(true) .possible_values(&["yes", "no", "auto"]) @@ -168,32 +167,32 @@ pub fn clap_app() -> clap::App<'static, 'static> { .help("Whether to have styles and colors (auto is default and usually OK)"), ) .arg( - clap::Arg::with_name("conf") + clap::Arg::new("conf") .long("conf") .takes_value(true) .help("Semicolon separated paths to specific config files"), ) .arg( - clap::Arg::with_name("height") + clap::Arg::new("height") .long("height") .help("Height (if you don't want to fill the screen or for file export)") .takes_value(true), ) .arg( - clap::Arg::with_name("file-export-path") // deprecated since broot 1.6 - .short("o") + clap::Arg::new("file-export-path") // deprecated since broot 1.6 + .short('o') .long("out") .takes_value(true) - .hidden(true) + .hide(true) .help("Where to write the produced path (if any)"), ) .arg( - clap::Arg::with_name("install") + clap::Arg::new("install") .long("install") .help("Install or reinstall the br shell function"), ) .arg( - clap::Arg::with_name("set-install-state") + clap::Arg::new("set-install-state") .long("set-install-state") .takes_value(true) .value_name("state") @@ -201,7 +200,7 @@ pub fn clap_app() -> clap::App<'static, 'static> { .help("Set the installation state (for use in install script)"), ) .arg( - clap::Arg::with_name("print-shell-function") + clap::Arg::new("print-shell-function") .long("print-shell-function") .takes_value(true) .value_name("shell") @@ -211,21 +210,26 @@ pub fn clap_app() -> clap::App<'static, 'static> { #[cfg(unix)] let app = app .arg( - clap::Arg::with_name("listen") + clap::Arg::new("listen") .long("listen") .takes_value(true) .help("Listen for commands") ) .arg( - clap::Arg::with_name("get-root") + clap::Arg::new("get-root") .long("get-root") .help("Ask for the current root of the remote broot") ) .arg( - clap::Arg::with_name("send") + clap::Arg::new("send") .long("send") .takes_value(true) .help("send commands to a remote broot then quits") ); app } + +#[test] +fn verify_app() { + clap_app().debug_assert(); +} diff --git a/src/cli/install_launch_args.rs b/src/cli/install_launch_args.rs index 5b8ef39..c688e12 100644 --- a/src/cli/install_launch_args.rs +++ b/src/cli/install_launch_args.rs @@ -21,7 +21,7 @@ pub struct InstallLaunchArgs { pub print_shell_function: Option<String>, // shell function to print on stdout } impl InstallLaunchArgs { - pub fn from(cli_args: &ArgMatches<'_>) -> Result<Self, ProgramError> { + pub fn from(cli_args: &ArgMatches) -> Result<Self, ProgramError> { let mut install = None; if let Ok(s) = env::var("BR_INSTALL") { if s == "yes" { diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 3bc64c5..29c5152 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -50,7 +50,7 @@ fn canonicalize_root(root: &Path) -> io::Result<PathBuf> { }) } -fn get_root_path(cli_args: &ArgMatches<'_>) -> Result<PathBuf, ProgramError> { +fn get_root_path(cli_args: &ArgMatches) -> Result<PathBuf, ProgramError> { let mut root = cli_args .value_of("ROOT") .map_or(env::current_dir()?, PathBuf::from); diff --git a/src/tree/tree_options.rs b/src/tree/tree_options.rs index 97d9c9c..f1f5353 100644 --- a/src/tree/tree_options.rs +++ b/src/tree/tree_options.rs @@ -8,7 +8,6 @@ use { pattern::*, }, clap::ArgMatches, - crossterm::style::Stylize, std::convert::TryFrom, }; @@ -80,20 +79,9 @@ impl TreeOptions { /// change tree options according to configuration pub fn apply_config(&mut self, config: &Conf) -> Result<(), ConfError> { if let Some(default_flags) = &config.default_flags { - let clap_app = clap_args::clap_app().setting(clap::AppSettings::NoBinaryName); + let clap_app = clap_args::clap_app().no_binary_name(true); let flags_args = format!("-{}", default_flags); - let conf_matches = match clap_app.get_matches_from_safe(vec![&flags_args]) { - Ok(cm) => cm, - Err(e) => { - error!("bad default_flags in conf: {:?}", default_flags); - eprintln!( - "{} Invalid default_flags in configuration file: \"{}\"", - "error:".red(), - default_flags.to_string().red(), - ); - e.exit(); - } - }; + let conf_matches = clap_app.get_matches_from(vec![&flags_args]); self.apply_launch_args(&conf_matches); } if let Some(b) = &config.show_selection_mark { @@ -111,7 +99,7 @@ impl TreeOptions { Ok(()) } /// change tree options according to broot launch arguments - pub fn apply_launch_args(&mut self, cli_args: &ArgMatches<'_>) { + pub fn apply_launch_args(&mut self, cli_args: &ArgMatches) { if cli_args.is_present("sizes") { self.show_sizes = true; self.show_root_fs = true; |