Updated clap to version 4.0 (#476)

Co-authored-by: Ajeet D'Souza <98ajeet@gmail.com>
This commit is contained in:
Elbert Ronnie 2022-10-29 19:46:10 +05:30 committed by GitHub
parent 1c947110db
commit b7d6b1eea7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 37 deletions

59
Cargo.lock generated
View File

@ -131,8 +131,8 @@ checksum = "a3dbbb6653e7c55cc8595ad3e1f7be8f32aba4eb7ff7f0fd1163d4f3d137c0a9"
dependencies = [ dependencies = [
"atty", "atty",
"bitflags", "bitflags",
"clap_derive", "clap_derive 3.2.15",
"clap_lex", "clap_lex 0.2.4",
"indexmap", "indexmap",
"once_cell", "once_cell",
"strsim", "strsim",
@ -141,21 +141,36 @@ dependencies = [
] ]
[[package]] [[package]]
name = "clap_complete" name = "clap"
version = "3.2.3" version = "4.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ead064480dfc4880a10764488415a97fdd36a4cf1bb022d372f02e8faf8386e1" checksum = "335867764ed2de42325fafe6d18b8af74ba97ee0c590fa016f157535b42ab04b"
dependencies = [ dependencies = [
"clap", "atty",
"bitflags",
"clap_derive 4.0.18",
"clap_lex 0.3.0",
"once_cell",
"strsim",
"termcolor",
]
[[package]]
name = "clap_complete"
version = "4.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfe581a2035db4174cdbdc91265e1aba50f381577f0510d0ad36c7bc59cc84a3"
dependencies = [
"clap 4.0.18",
] ]
[[package]] [[package]]
name = "clap_complete_fig" name = "clap_complete_fig"
version = "3.2.4" version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed37b4c0c1214673eba6ad8ea31666626bf72be98ffb323067d973c48b4964b9" checksum = "b36d1abc7184a737efc9f589e6e783e8b56c72e71fca748cf9947ed0a6f46d44"
dependencies = [ dependencies = [
"clap", "clap 4.0.18",
"clap_complete", "clap_complete",
] ]
@ -172,6 +187,19 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "clap_derive"
version = "4.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16a1b0f6422af32d5da0c58e2703320f379216ee70198241c84173a8c5ac28f3"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "clap_lex" name = "clap_lex"
version = "0.2.4" version = "0.2.4"
@ -181,6 +209,15 @@ dependencies = [
"os_str_bytes", "os_str_bytes",
] ]
[[package]]
name = "clap_lex"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
dependencies = [
"os_str_bytes",
]
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.11" version = "0.8.11"
@ -809,7 +846,7 @@ name = "xtask"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap 3.2.16",
"ignore", "ignore",
"shell-words", "shell-words",
] ]
@ -822,7 +859,7 @@ dependencies = [
"askama", "askama",
"assert_cmd", "assert_cmd",
"bincode", "bincode",
"clap", "clap 4.0.18",
"clap_complete", "clap_complete",
"clap_complete_fig", "clap_complete_fig",
"dirs", "dirs",

View File

@ -22,7 +22,7 @@ members = ["xtask/"]
anyhow = "1.0.32" anyhow = "1.0.32"
askama = { version = "0.11.0", default-features = false } askama = { version = "0.11.0", default-features = false }
bincode = "1.3.1" bincode = "1.3.1"
clap = { version = "3.1.0", features = ["derive"] } clap = { version = "4.0.0", features = ["derive"] }
dirs = "4.0.0" dirs = "4.0.0"
dunce = "1.0.1" dunce = "1.0.1"
fastrand = "1.7.0" fastrand = "1.7.0"
@ -39,9 +39,9 @@ nix = { version = "0.24.1", default-features = false, features = [
which = "4.2.5" which = "4.2.5"
[build-dependencies] [build-dependencies]
clap = { version = "3.1.0", features = ["derive"] } clap = { version = "4.0.0", features = ["derive"] }
clap_complete = "3.1.0" clap_complete = "4.0.0"
clap_complete_fig = "3.1.0" clap_complete_fig = "4.0.0"
[dev-dependencies] [dev-dependencies]
assert_cmd = "2.0.0" assert_cmd = "2.0.0"

View File

@ -8,24 +8,24 @@ _zoxide() {
for i in ${COMP_WORDS[@]} for i in ${COMP_WORDS[@]}
do do
case "${i}" in case "${cmd},${i}" in
"$1") ",$1")
cmd="zoxide" cmd="zoxide"
;; ;;
add) zoxide,add)
cmd+="__add" cmd="zoxide__add"
;; ;;
import) zoxide,import)
cmd+="__import" cmd="zoxide__import"
;; ;;
init) zoxide,init)
cmd+="__init" cmd="zoxide__init"
;; ;;
query) zoxide,query)
cmd+="__query" cmd="zoxide__query"
;; ;;
remove) zoxide,remove)
cmd+="__remove" cmd="zoxide__remove"
;; ;;
*) *)
;; ;;
@ -102,7 +102,7 @@ _zoxide() {
return 0 return 0
;; ;;
zoxide__query) zoxide__query)
opts="-i -l -s -h -V --all --interactive --list --score --exclude --help --version <KEYWORDS>..." opts="-i -l -s -h -V --all --interactive --list --score --exclude --help --version [KEYWORDS]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0 return 0
@ -120,7 +120,7 @@ _zoxide() {
return 0 return 0
;; ;;
zoxide__remove) zoxide__remove)
opts="-i -h -V --interactive --help --version <PATHS>..." opts="-i -h -V --interactive --help --version [PATHS]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0 return 0

View File

@ -28,6 +28,7 @@ const completion: Fig.Spec = {
{ {
name: "--from", name: "--from",
description: "Application to import from", description: "Application to import from",
isRepeatable: true,
args: { args: {
name: "from", name: "from",
suggestions: [ suggestions: [
@ -61,6 +62,7 @@ const completion: Fig.Spec = {
{ {
name: "--cmd", name: "--cmd",
description: "Changes the prefix of the `z` and `zi` commands", description: "Changes the prefix of the `z` and `zi` commands",
isRepeatable: true,
args: { args: {
name: "cmd", name: "cmd",
isOptional: true, isOptional: true,
@ -69,6 +71,7 @@ const completion: Fig.Spec = {
{ {
name: "--hook", name: "--hook",
description: "Changes how often zoxide increments a directory's score", description: "Changes how often zoxide increments a directory's score",
isRepeatable: true,
args: { args: {
name: "hook", name: "hook",
isOptional: true, isOptional: true,
@ -113,6 +116,7 @@ const completion: Fig.Spec = {
{ {
name: "--exclude", name: "--exclude",
description: "Exclude a path from results", description: "Exclude a path from results",
isRepeatable: true,
args: { args: {
name: "exclude", name: "exclude",
isOptional: true, isOptional: true,
@ -154,6 +158,7 @@ const completion: Fig.Spec = {
], ],
args: { args: {
name: "keywords", name: "keywords",
isVariadic: true,
isOptional: true, isOptional: true,
}, },
}, },
@ -176,6 +181,7 @@ const completion: Fig.Spec = {
], ],
args: { args: {
name: "paths", name: "paths",
isVariadic: true,
isOptional: true, isOptional: true,
template: "folders", template: "folders",
}, },

View File

@ -2,7 +2,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use clap::{ArgEnum, Parser, ValueHint}; use clap::{Parser, ValueEnum, ValueHint};
const ENV_HELP: &str = "ENVIRONMENT VARIABLES: const ENV_HELP: &str = "ENVIRONMENT VARIABLES:
_ZO_DATA_DIR Path for zoxide data files _ZO_DATA_DIR Path for zoxide data files
@ -33,7 +33,7 @@ pub enum Cmd {
/// Add a new directory or increment its rank /// Add a new directory or increment its rank
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
pub struct Add { pub struct Add {
#[clap(min_values = 1, required = true, value_hint = ValueHint::DirPath)] #[clap(num_args = 1.., required = true, value_hint = ValueHint::DirPath)]
pub paths: Vec<PathBuf>, pub paths: Vec<PathBuf>,
} }
@ -44,7 +44,7 @@ pub struct Import {
pub path: PathBuf, pub path: PathBuf,
/// Application to import from /// Application to import from
#[clap(arg_enum, long)] #[clap(value_enum, long)]
pub from: ImportFrom, pub from: ImportFrom,
/// Merge into existing database /// Merge into existing database
@ -52,7 +52,7 @@ pub struct Import {
pub merge: bool, pub merge: bool,
} }
#[derive(ArgEnum, Clone, Debug)] #[derive(ValueEnum, Clone, Debug)]
pub enum ImportFrom { pub enum ImportFrom {
Autojump, Autojump,
Z, Z,
@ -61,7 +61,7 @@ pub enum ImportFrom {
/// Generate shell configuration /// Generate shell configuration
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
pub struct Init { pub struct Init {
#[clap(arg_enum)] #[clap(value_enum)]
pub shell: InitShell, pub shell: InitShell,
/// Prevents zoxide from defining the `z` and `zi` commands /// Prevents zoxide from defining the `z` and `zi` commands
@ -73,18 +73,18 @@ pub struct Init {
pub cmd: String, pub cmd: String,
/// Changes how often zoxide increments a directory's score /// Changes how often zoxide increments a directory's score
#[clap(arg_enum, long, default_value = "pwd")] #[clap(value_enum, long, default_value = "pwd")]
pub hook: InitHook, pub hook: InitHook,
} }
#[derive(ArgEnum, Clone, Copy, Debug, Eq, PartialEq)] #[derive(ValueEnum, Clone, Copy, Debug, Eq, PartialEq)]
pub enum InitHook { pub enum InitHook {
None, None,
Prompt, Prompt,
Pwd, Pwd,
} }
#[derive(ArgEnum, Clone, Debug)] #[derive(ValueEnum, Clone, Debug)]
pub enum InitShell { pub enum InitShell {
Bash, Bash,
Elvish, Elvish,