Update clap to v3

This commit is contained in:
James 2022-08-23 11:48:31 +01:00 committed by Abin Simon
parent 7d523103ec
commit 0f42e725f9
6 changed files with 118 additions and 104 deletions

74
Cargo.lock generated
View file

@ -11,15 +11,6 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "ansi_term" name = "ansi_term"
version = "0.12.1" version = "0.12.1"
@ -121,18 +112,36 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "2.33.4" version = "3.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826bf7bc84f9435630275cb8e802a4a0ec792b615969934bd16d42ffed10f207" checksum = "29e724a68d9319343bb3328c9cc2dfde263f4b3142ee1059a9980580171c954b"
dependencies = [ dependencies = [
"ansi_term 0.11.0",
"atty", "atty",
"bitflags", "bitflags",
"clap_lex",
"indexmap",
"strsim", "strsim",
"term_size", "termcolor",
"terminal_size",
"textwrap", "textwrap",
"unicode-width", ]
"vec_map",
[[package]]
name = "clap_complete"
version = "3.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4179da71abd56c26b54dd0c248cc081c1f43b0a1a7e8448e28e57a29baa993d"
dependencies = [
"clap",
]
[[package]]
name = "clap_lex"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
dependencies = [
"os_str_bytes",
] ]
[[package]] [[package]]
@ -400,7 +409,7 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e9323b3525d4efad2dead1837a105e313253bfdbad1d470994038eededa4d62" checksum = "4e9323b3525d4efad2dead1837a105e313253bfdbad1d470994038eededa4d62"
dependencies = [ dependencies = [
"ansi_term 0.12.1", "ansi_term",
] ]
[[package]] [[package]]
@ -412,6 +421,7 @@ dependencies = [
"chrono", "chrono",
"chrono-humanize", "chrono-humanize",
"clap", "clap",
"clap_complete",
"crossterm", "crossterm",
"dirs", "dirs",
"globset", "globset",
@ -491,6 +501,12 @@ version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
[[package]]
name = "os_str_bytes"
version = "6.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.11.2" version = "0.11.2"
@ -768,9 +784,9 @@ checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.8.0" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "syn" name = "syn"
@ -807,13 +823,12 @@ dependencies = [
] ]
[[package]] [[package]]
name = "term_size" name = "termcolor"
version = "0.3.2" version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9" checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [ dependencies = [
"libc", "winapi-util",
"winapi",
] ]
[[package]] [[package]]
@ -834,12 +849,11 @@ checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b"
[[package]] [[package]]
name = "textwrap" name = "textwrap"
version = "0.11.0" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
dependencies = [ dependencies = [
"term_size", "terminal_size",
"unicode-width",
] ]
[[package]] [[package]]
@ -944,12 +958,6 @@ dependencies = [
"log", "log",
] ]
[[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

@ -16,7 +16,8 @@ name = "lsd"
path = "src/main.rs" path = "src/main.rs"
[build-dependencies] [build-dependencies]
clap = "2.33.*" clap = "3.2.17"
clap_complete = "3.2.4"
version_check = "0.9.*" version_check = "0.9.*"
[dependencies] [dependencies]
@ -47,7 +48,7 @@ winapi = {version = "0.3.*", features = ["aclapi", "accctrl", "winnt", "winerror
[dependencies.clap] [dependencies.clap]
features = ["suggestions", "color", "wrap_help"] features = ["suggestions", "color", "wrap_help"]
version = "2.33.*" version = "3.2.17"
[dev-dependencies] [dev-dependencies]
assert_cmd = "1" assert_cmd = "1"

View file

@ -6,11 +6,11 @@
// notice may not be copied, modified, or distributed except // notice may not be copied, modified, or distributed except
// according to those terms. // according to those terms.
#[macro_use]
extern crate clap; extern crate clap;
extern crate version_check; extern crate version_check;
use clap::Shell; use clap_complete::generate_to;
use clap_complete::shells::*;
use std::fs; use std::fs;
use std::process::exit; use std::process::exit;
@ -30,8 +30,10 @@ fn main() {
fs::create_dir_all(&outdir).unwrap(); fs::create_dir_all(&outdir).unwrap();
let mut app = build(); let mut app = build();
app.gen_completions("lsd", Shell::Bash, &outdir); let bin_name = "lsd";
app.gen_completions("lsd", Shell::Fish, &outdir); generate_to(Bash, &mut app, bin_name, &outdir).expect("Failed to generate Bash completions");
app.gen_completions("lsd", Shell::Zsh, &outdir); generate_to(Fish, &mut app, bin_name, &outdir).expect("Failed to generate Fish completions");
app.gen_completions("lsd", Shell::PowerShell, &outdir); generate_to(Zsh, &mut app, bin_name, &outdir).expect("Failed to generate Zsh completions");
generate_to(PowerShell, &mut app, bin_name, &outdir)
.expect("Failed to generate PowerShell completions");
} }

View file

@ -1,24 +1,24 @@
use clap::{App, Arg}; use clap::{App, Arg};
pub fn build() -> App<'static, 'static> { pub fn build() -> App<'static> {
App::new("lsd") App::new("lsd")
.version(crate_version!()) .version(env!("CARGO_PKG_VERSION"))
.about(crate_description!()) .about(env!("CARGO_PKG_DESCRIPTION"))
.arg(Arg::with_name("FILE").multiple(true).default_value(".")) .arg(Arg::with_name("FILE").multiple(true).default_value("."))
.arg( .arg(
Arg::with_name("all") Arg::with_name("all")
.short("a") .short('a')
.overrides_with("almost-all") .overrides_with("almost-all")
.long("all") .long("all")
.multiple(true) .multiple_occurrences(true)
.help("Do not ignore entries starting with ."), .help("Do not ignore entries starting with ."),
) )
.arg( .arg(
Arg::with_name("almost-all") Arg::with_name("almost-all")
.short("A") .short('A')
.overrides_with("all") .overrides_with("all")
.long("almost-all") .long("almost-all")
.multiple(true) .multiple_occurrences(true)
.help("Do not list implied . and .."), .help("Do not list implied . and .."),
) )
.arg( .arg(
@ -28,7 +28,8 @@ pub fn build() -> App<'static, 'static> {
.possible_value("auto") .possible_value("auto")
.possible_value("never") .possible_value("never")
.default_value("auto") .default_value("auto")
.multiple(true) .multiple_occurrences(true)
.takes_value(true)
.number_of_values(1) .number_of_values(1)
.help("When to use terminal colours"), .help("When to use terminal colours"),
) )
@ -39,7 +40,8 @@ pub fn build() -> App<'static, 'static> {
.possible_value("auto") .possible_value("auto")
.possible_value("never") .possible_value("never")
.default_value("auto") .default_value("auto")
.multiple(true) .multiple_occurrences(true)
.takes_value(true)
.number_of_values(1) .number_of_values(1)
.help("When to print the icons"), .help("When to print the icons"),
) )
@ -49,22 +51,23 @@ pub fn build() -> App<'static, 'static> {
.possible_value("fancy") .possible_value("fancy")
.possible_value("unicode") .possible_value("unicode")
.default_value("fancy") .default_value("fancy")
.multiple(true) .multiple_occurrences(true)
.takes_value(true)
.number_of_values(1) .number_of_values(1)
.help("Whether to use fancy or unicode icons"), .help("Whether to use fancy or unicode icons"),
) )
.arg( .arg(
Arg::with_name("indicators") Arg::with_name("indicators")
.short("F") .short('F')
.long("classify") .long("classify")
.multiple(true) .multiple_occurrences(true)
.help("Append indicator (one of */=>@|) at the end of the file names"), .help("Append indicator (one of */=>@|) at the end of the file names"),
) )
.arg( .arg(
Arg::with_name("long") Arg::with_name("long")
.short("l") .short('l')
.long("long") .long("long")
.multiple(true) .multiple_occurrences(true)
.help("Display extended file metadata as a table"), .help("Display extended file metadata as a table"),
) )
.arg( .arg(
@ -81,44 +84,44 @@ pub fn build() -> App<'static, 'static> {
) )
.arg( .arg(
Arg::with_name("oneline") Arg::with_name("oneline")
.short("1") .short('1')
.long("oneline") .long("oneline")
.multiple(true) .multiple_occurrences(true)
.help("Display one entry per line"), .help("Display one entry per line"),
) )
.arg( .arg(
Arg::with_name("recursive") Arg::with_name("recursive")
.short("R") .short('R')
.long("recursive") .long("recursive")
.multiple(true) .multiple_occurrences(true)
.conflicts_with("tree") .conflicts_with("tree")
.help("Recurse into directories"), .help("Recurse into directories"),
) )
.arg( .arg(
Arg::with_name("human_readable") Arg::with_name("human_readable")
.short("h") .short('h')
.long("human-readable") .long("human-readable")
.multiple(true) .multiple_occurrences(true)
.help("For ls compatibility purposes ONLY, currently set by default"), .help("For ls compatibility purposes ONLY, currently set by default"),
) )
.arg( .arg(
Arg::with_name("tree") Arg::with_name("tree")
.long("tree") .long("tree")
.multiple(true) .multiple_occurrences(true)
.conflicts_with("recursive") .conflicts_with("recursive")
.help("Recurse into directories and present the result as a tree"), .help("Recurse into directories and present the result as a tree"),
) )
.arg( .arg(
Arg::with_name("depth") Arg::with_name("depth")
.long("depth") .long("depth")
.multiple(true) .multiple_occurrences(true)
.takes_value(true) .takes_value(true)
.value_name("num") .value_name("num")
.help("Stop recursing into directories after reaching specified depth"), .help("Stop recursing into directories after reaching specified depth"),
) )
.arg( .arg(
Arg::with_name("directory-only") Arg::with_name("directory-only")
.short("d") .short('d')
.long("directory-only") .long("directory-only")
.conflicts_with("depth") .conflicts_with("depth")
.conflicts_with("recursive") .conflicts_with("recursive")
@ -130,7 +133,8 @@ pub fn build() -> App<'static, 'static> {
.default_value("rwx") .default_value("rwx")
.possible_value("rwx") .possible_value("rwx")
.possible_value("octal") .possible_value("octal")
.multiple(true) .multiple_occurrences(true)
.takes_value(true)
.number_of_values(1) .number_of_values(1)
.help("How to display permissions"), .help("How to display permissions"),
) )
@ -141,14 +145,15 @@ pub fn build() -> App<'static, 'static> {
.possible_value("short") .possible_value("short")
.possible_value("bytes") .possible_value("bytes")
.default_value("default") .default_value("default")
.multiple(true) .multiple_occurrences(true)
.takes_value(true)
.number_of_values(1) .number_of_values(1)
.help("How to display size"), .help("How to display size"),
) )
.arg( .arg(
Arg::with_name("total-size") Arg::with_name("total-size")
.long("total-size") .long("total-size")
.multiple(true) .multiple_occurrences(true)
.help("Display the total size of directories"), .help("Display the total size of directories"),
) )
.arg( .arg(
@ -156,51 +161,52 @@ pub fn build() -> App<'static, 'static> {
.long("date") .long("date")
.validator(validate_date_argument) .validator(validate_date_argument)
.default_value("date") .default_value("date")
.multiple(true) .multiple_occurrences(true)
.takes_value(true)
.number_of_values(1) .number_of_values(1)
.help("How to display date [possible values: date, relative, +date-time-format]"), .help("How to display date [possible values: date, relative, +date-time-format]"),
) )
.arg( .arg(
Arg::with_name("timesort") Arg::with_name("timesort")
.short("t") .short('t')
.long("timesort") .long("timesort")
.overrides_with("sizesort") .overrides_with("sizesort")
.overrides_with("extensionsort") .overrides_with("extensionsort")
.overrides_with("versionsort") .overrides_with("versionsort")
.overrides_with("sort") .overrides_with("sort")
.overrides_with("no-sort") .overrides_with("no-sort")
.multiple(true) .multiple_occurrences(true)
.help("Sort by time modified"), .help("Sort by time modified"),
) )
.arg( .arg(
Arg::with_name("sizesort") Arg::with_name("sizesort")
.short("S") .short('S')
.long("sizesort") .long("sizesort")
.overrides_with("timesort") .overrides_with("timesort")
.overrides_with("extensionsort") .overrides_with("extensionsort")
.overrides_with("versionsort") .overrides_with("versionsort")
.overrides_with("sort") .overrides_with("sort")
.overrides_with("no-sort") .overrides_with("no-sort")
.multiple(true) .multiple_occurrences(true)
.help("Sort by size"), .help("Sort by size"),
) )
.arg( .arg(
Arg::with_name("extensionsort") Arg::with_name("extensionsort")
.short("X") .short('X')
.long("extensionsort") .long("extensionsort")
.overrides_with("sizesort") .overrides_with("sizesort")
.overrides_with("timesort") .overrides_with("timesort")
.overrides_with("versionsort") .overrides_with("versionsort")
.overrides_with("sort") .overrides_with("sort")
.overrides_with("no-sort") .overrides_with("no-sort")
.multiple(true) .multiple_occurrences(true)
.help("Sort by file extension"), .help("Sort by file extension"),
) )
.arg( .arg(
Arg::with_name("versionsort") Arg::with_name("versionsort")
.short("v") .short('v')
.long("versionsort") .long("versionsort")
.multiple(true) .multiple_occurrences(true)
.overrides_with("timesort") .overrides_with("timesort")
.overrides_with("sizesort") .overrides_with("sizesort")
.overrides_with("extensionsort") .overrides_with("extensionsort")
@ -211,7 +217,7 @@ pub fn build() -> App<'static, 'static> {
.arg( .arg(
Arg::with_name("sort") Arg::with_name("sort")
.long("sort") .long("sort")
.multiple(true) .multiple_occurrences(true)
.possible_values(&["size", "time", "version", "extension", "none"]) .possible_values(&["size", "time", "version", "extension", "none"])
.takes_value(true) .takes_value(true)
.value_name("WORD") .value_name("WORD")
@ -224,9 +230,9 @@ pub fn build() -> App<'static, 'static> {
) )
.arg( .arg(
Arg::with_name("no-sort") Arg::with_name("no-sort")
.short("U") .short('U')
.long("no-sort") .long("no-sort")
.multiple(true) .multiple_occurrences(true)
.overrides_with("timesort") .overrides_with("timesort")
.overrides_with("sizesort") .overrides_with("sizesort")
.overrides_with("extensionsort") .overrides_with("extensionsort")
@ -236,9 +242,9 @@ pub fn build() -> App<'static, 'static> {
) )
.arg( .arg(
Arg::with_name("reverse") Arg::with_name("reverse")
.short("r") .short('r')
.long("reverse") .long("reverse")
.multiple(true) .multiple_occurrences(true)
.help("Reverse the order of the sort"), .help("Reverse the order of the sort"),
) )
.arg( .arg(
@ -247,7 +253,7 @@ pub fn build() -> App<'static, 'static> {
.possible_value("none") .possible_value("none")
.possible_value("first") .possible_value("first")
.possible_value("last") .possible_value("last")
.multiple(true) .multiple_occurrences(true)
.number_of_values(1) .number_of_values(1)
.help("Sort the directories then the files"), .help("Sort the directories then the files"),
) )
@ -259,8 +265,10 @@ pub fn build() -> App<'static, 'static> {
.arg( .arg(
Arg::with_name("blocks") Arg::with_name("blocks")
.long("blocks") .long("blocks")
.multiple(true) .multiple_occurrences(true)
.number_of_values(1) .multiple_values(true)
.takes_value(true)
.use_value_delimiter(true)
.require_delimiter(true) .require_delimiter(true)
.possible_values(&[ .possible_values(&[
"permission", "permission",
@ -283,14 +291,14 @@ pub fn build() -> App<'static, 'static> {
.arg( .arg(
Arg::with_name("no-symlink") Arg::with_name("no-symlink")
.long("no-symlink") .long("no-symlink")
.multiple(true) .multiple_occurrences(true)
.help("Do not display symlink target"), .help("Do not display symlink target"),
) )
.arg( .arg(
Arg::with_name("ignore-glob") Arg::with_name("ignore-glob")
.short("I") .short('I')
.long("ignore-glob") .long("ignore-glob")
.multiple(true) .multiple_occurrences(true)
.number_of_values(1) .number_of_values(1)
.value_name("pattern") .value_name("pattern")
.default_value("") .default_value("")
@ -298,21 +306,21 @@ pub fn build() -> App<'static, 'static> {
) )
.arg( .arg(
Arg::with_name("inode") Arg::with_name("inode")
.short("i") .short('i')
.long("inode") .long("inode")
.multiple(true) .multiple_occurrences(true)
.help("Display the index number of each file"), .help("Display the index number of each file"),
) )
.arg( .arg(
Arg::with_name("dereference") Arg::with_name("dereference")
.short("L") .short('L')
.long("dereference") .long("dereference")
.multiple(true) .multiple_occurrences(true)
.help("When showing file information for a symbolic link, show information for the file the link references rather than for the link itself"), .help("When showing file information for a symbolic link, show information for the file the link references rather than for the link itself"),
) )
.arg( .arg(
Arg::with_name("context") Arg::with_name("context")
.short("Z") .short('Z')
.long("context") .long("context")
.required(false) .required(false)
.takes_value(false) .takes_value(false)
@ -325,7 +333,8 @@ pub fn build() -> App<'static, 'static> {
.possible_value("auto") .possible_value("auto")
.possible_value("never") .possible_value("never")
.default_value("never") .default_value("never")
.multiple(true) .multiple_occurrences(true)
.takes_value(true)
.number_of_values(1) .number_of_values(1)
.help("Attach hyperlink to filenames"), .help("Attach hyperlink to filenames"),
) )
@ -336,7 +345,7 @@ pub fn build() -> App<'static, 'static> {
) )
} }
fn validate_date_argument(arg: String) -> Result<(), String> { fn validate_date_argument(arg: &str) -> Result<(), String> {
if arg.starts_with('+') { if arg.starts_with('+') {
validate_time_format(&arg) validate_time_format(&arg)
} else if arg == "date" || arg == "relative" { } else if arg == "date" || arg == "relative" {

View file

@ -98,10 +98,7 @@ impl IgnoreGlobs {
fn create_glob(pattern: &str) -> Result<Glob, Error> { fn create_glob(pattern: &str) -> Result<Glob, Error> {
match Glob::new(pattern) { match Glob::new(pattern) {
Ok(glob) => Ok(glob), Ok(glob) => Ok(glob),
Err(err) => Err(Error::with_description( Err(err) => Err(Error::raw(ErrorKind::ValueValidation, err)),
&err.to_string(),
ErrorKind::ValueValidation,
)),
} }
} }
@ -111,10 +108,7 @@ impl IgnoreGlobs {
fn create_glob_set(builder: &GlobSetBuilder) -> Result<GlobSet, Error> { fn create_glob_set(builder: &GlobSetBuilder) -> Result<GlobSet, Error> {
match builder.build() { match builder.build() {
Ok(glob_set) => Ok(glob_set), Ok(glob_set) => Ok(glob_set),
Err(err) => Err(Error::with_description( Err(err) => Err(Error::raw(ErrorKind::ValueValidation, err)),
&err.to_string(),
ErrorKind::ValueValidation,
)),
} }
} }
} }

View file

@ -106,9 +106,9 @@ impl Recursion {
match str.parse::<usize>() { match str.parse::<usize>() {
Ok(value) => return Some(Ok(value)), Ok(value) => return Some(Ok(value)),
Err(_) => { Err(_) => {
return Some(Err(Error::with_description( return Some(Err(Error::raw(
"The argument '--depth' requires a valid positive number.",
ErrorKind::ValueValidation, ErrorKind::ValueValidation,
"The argument '--depth' requires a valid positive number.",
))) )))
} }
} }