diff --git a/.ci/print-command-docs.js b/.ci/print-command-docs.js index f5328e1..91b11ba 100755 --- a/.ci/print-command-docs.js +++ b/.ci/print-command-docs.js @@ -112,8 +112,10 @@ async function getCommandHelp(fnmPath, command) { const subcommands = []; if (!command) { for (const row of rows.slice(headerIndex + 1)) { - const words = row.split(/\s+/); - subcommands.push(words[1]); + const [, word] = row.split(/\s+/); + if (word && word[0].toLowerCase() === word[0]) { + subcommands.push(word); + } } } return { diff --git a/Cargo.lock b/Cargo.lock index d5bb613..c1c28ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -207,17 +207,41 @@ dependencies = [ [[package]] name = "clap" -version = "2.34.0" +version = "3.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "f6f34b09b9ee8c7c7b400fe2f8df39cafc9538b03d6ba7f4ae13e4cb90bfbb7d" dependencies = [ - "ansi_term", "atty", "bitflags", + "clap_derive", + "indexmap", + "lazy_static", + "os_str_bytes", "strsim", + "termcolor", "textwrap", - "unicode-width", - "vec_map", +] + +[[package]] +name = "clap_complete" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a394f7ec0715b42a4e52b294984c27c9a61f77c8d82f7774c5198350be143f19" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_derive" +version = "3.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41a0645a430ec9136d2d701e54a95d557de12649a9dd7109ced3187e648ac824" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -483,6 +507,7 @@ dependencies = [ "atty", "chrono", "clap", + "clap_complete", "colored", "csv", "dirs", @@ -501,7 +526,6 @@ dependencies = [ "serde_json", "serial_test", "shell-escape", - "structopt", "sysinfo", "tar", "tempfile", @@ -620,12 +644,9 @@ checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" [[package]] name = "heck" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" @@ -980,6 +1001,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "os_str_bytes" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" +dependencies = [ + "memchr", +] + [[package]] name = "output_vt100" version = "0.1.2" @@ -1452,33 +1482,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - -[[package]] -name = "structopt" -version = "0.3.25" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c" -dependencies = [ - "clap", - "lazy_static", - "structopt-derive", -] - -[[package]] -name = "structopt-derive" -version = "0.4.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" @@ -1563,12 +1569,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.11.0" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] +checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" [[package]] name = "thiserror" @@ -1704,18 +1707,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" - -[[package]] -name = "unicode-width" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" - [[package]] name = "unicode-xid" version = "0.2.2" @@ -1752,12 +1743,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" -[[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.3" diff --git a/Cargo.toml b/Cargo.toml index 56b3f27..b23b4fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,7 @@ description = "Fast and simple Node.js version manager" [dependencies] serde = { version = "1.0.133", features = ["derive"] } -clap = "2.34.0" -structopt = "0.3.25" +clap = { version = "3.0.5", features = ["derive", "env"] } serde_json = "1.0.74" chrono = { version = "0.4.19", features = ["serde"] } tar = "0.4.38" @@ -30,6 +29,7 @@ reqwest = { version = "0.11.8", features = ["blocking", "json", "rustls-tls", "r url = "2.2.2" sysinfo = "0.22.5" thiserror = "1.0.30" +clap_complete = "3.0.2" [dev-dependencies] pretty_assertions = "1.0.0" diff --git a/docs/commands.md b/docs/commands.md index f4efbc7..c1a4009 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -7,286 +7,363 @@ A fast and simple Node.js manager USAGE: fnm [OPTIONS] -FLAGS: +OPTIONS: + --arch + Override the architecture of the installed Node binary. Defaults to arch of fnm binary + + [env: FNM_ARCH] + + --fnm-dir + The root directory of fnm installations + + [env: FNM_DIR] + -h, --help - Prints help information + Print help information - -V, --version - Prints version information + --log-level + The log level of fnm commands + [env: FNM_LOGLEVEL] + [default: info] + [possible values: quiet, info, all, error] -OPTIONS: - --arch - Override the architecture of the installed Node binary. Defaults to arch of fnm binary [env: FNM_ARCH] + --node-dist-mirror + https://nodejs.org/dist/ mirror - --fnm-dir - The root directory of fnm installations [env: FNM_DIR] + [env: FNM_NODE_DIST_MIRROR] + [default: https://nodejs.org/dist] - --log-level - The log level of fnm commands [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, - error] - --node-dist-mirror - https://nodejs.org/dist/ mirror [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] + -V, --version + Print version information - --version-file-strategy - A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a - version, or when `--use-on-cd` is configured on evaluation. + --version-file-strategy + A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` + is called without a version, or when `--use-on-cd` is configured on evaluation. * `local`: Use the local version of Node defined within the current directory - * `recursive`: Use the version of Node defined within the current directory and all parent directories [env: - FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] + * `recursive`: Use the version of Node defined within the current directory and all + parent directories + + [env: FNM_VERSION_FILE_STRATEGY] + [default: local] + [possible values: local, recursive] SUBCOMMANDS: - alias Alias a version to a common name - completions Print shell completions to stdout - current Print the current Node.js version - default Set a version as the default version - env Print and set up required environment variables for fnm - exec Run a command within fnm context - help Prints this message or the help of the given subcommand(s) - install Install a new Node.js version - list List all locally installed Node.js versions [aliases: ls] - list-remote List all remote Node.js versions [aliases: ls-remote] - unalias Remove an alias definition - uninstall Uninstall a Node.js version - use Change Node.js version + alias + Alias a version to a common name + completions + Print shell completions to stdout + current + Print the current Node.js version + default + Set a version as the default version + env + Print and set up required environment variables for fnm + exec + Run a command within fnm context + help + Print this message or the help of the given subcommand(s) + install + Install a new Node.js version + list + List all locally installed Node.js versions [aliases: ls] + list-remote + List all remote Node.js versions [aliases: ls-remote] + unalias + Remove an alias definition + uninstall + Uninstall a Node.js version + use + Change Node.js version ``` # `fnm alias` ``` -fnm-alias 1.29.2 +fnm-alias Alias a version to a common name USAGE: - fnm alias [OPTIONS] + fnm alias [OPTIONS] -FLAGS: - -h, --help - Prints help information +ARGS: + - -V, --version - Prints version information + + OPTIONS: - --arch - Override the architecture of the installed Node binary. Defaults to arch of fnm binary [env: FNM_ARCH] + --arch + Override the architecture of the installed Node binary. Defaults to arch of fnm binary - --fnm-dir - The root directory of fnm installations [env: FNM_DIR] + [env: FNM_ARCH] - --log-level - The log level of fnm commands [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, - error] - --node-dist-mirror - https://nodejs.org/dist/ mirror [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] + --fnm-dir + The root directory of fnm installations - --version-file-strategy - A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a - version, or when `--use-on-cd` is configured on evaluation. + [env: FNM_DIR] - * `local`: Use the local version of Node defined within the current directory + -h, --help + Print help information - * `recursive`: Use the version of Node defined within the current directory and all parent directories [env: - FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] + --log-level + The log level of fnm commands -ARGS: - + [env: FNM_LOGLEVEL] + [default: info] + [possible values: quiet, info, all, error] + + --node-dist-mirror + https://nodejs.org/dist/ mirror + [env: FNM_NODE_DIST_MIRROR] + [default: https://nodejs.org/dist] - + --version-file-strategy + A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` + is called without a version, or when `--use-on-cd` is configured on evaluation. + + * `local`: Use the local version of Node defined within the current directory + * `recursive`: Use the version of Node defined within the current directory and all + parent directories + [env: FNM_VERSION_FILE_STRATEGY] + [default: local] + [possible values: local, recursive] ``` # `fnm completions` ``` -fnm-completions 1.29.2 +fnm-completions Print shell completions to stdout USAGE: fnm completions [OPTIONS] -FLAGS: - -h, --help - Prints help information +OPTIONS: + --arch + Override the architecture of the installed Node binary. Defaults to arch of fnm binary - -V, --version - Prints version information + [env: FNM_ARCH] + --fnm-dir + The root directory of fnm installations -OPTIONS: - --arch - Override the architecture of the installed Node binary. Defaults to arch of fnm binary [env: FNM_ARCH] + [env: FNM_DIR] + + -h, --help + Print help information + + --log-level + The log level of fnm commands + + [env: FNM_LOGLEVEL] + [default: info] + [possible values: quiet, info, all, error] - --fnm-dir - The root directory of fnm installations [env: FNM_DIR] + --node-dist-mirror + https://nodejs.org/dist/ mirror - --log-level - The log level of fnm commands [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, - error] - --node-dist-mirror - https://nodejs.org/dist/ mirror [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] + [env: FNM_NODE_DIST_MIRROR] + [default: https://nodejs.org/dist] - --shell - The shell syntax to use. Infers when missing [possible values: zsh, bash, fish, powershell, elvish] + --shell + The shell syntax to use. Infers when missing - --version-file-strategy - A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a - version, or when `--use-on-cd` is configured on evaluation. + --version-file-strategy + A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` + is called without a version, or when `--use-on-cd` is configured on evaluation. * `local`: Use the local version of Node defined within the current directory - * `recursive`: Use the version of Node defined within the current directory and all parent directories [env: - FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] + * `recursive`: Use the version of Node defined within the current directory and all + parent directories + + [env: FNM_VERSION_FILE_STRATEGY] + [default: local] + [possible values: local, recursive] ``` # `fnm current` ``` -fnm-current 1.29.2 +fnm-current Print the current Node.js version USAGE: fnm current [OPTIONS] -FLAGS: - -h, --help - Prints help information +OPTIONS: + --arch + Override the architecture of the installed Node binary. Defaults to arch of fnm binary - -V, --version - Prints version information + [env: FNM_ARCH] + --fnm-dir + The root directory of fnm installations -OPTIONS: - --arch - Override the architecture of the installed Node binary. Defaults to arch of fnm binary [env: FNM_ARCH] + [env: FNM_DIR] + + -h, --help + Print help information - --fnm-dir - The root directory of fnm installations [env: FNM_DIR] + --log-level + The log level of fnm commands - --log-level - The log level of fnm commands [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, - error] - --node-dist-mirror - https://nodejs.org/dist/ mirror [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] + [env: FNM_LOGLEVEL] + [default: info] + [possible values: quiet, info, all, error] - --version-file-strategy - A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a - version, or when `--use-on-cd` is configured on evaluation. + --node-dist-mirror + https://nodejs.org/dist/ mirror + + [env: FNM_NODE_DIST_MIRROR] + [default: https://nodejs.org/dist] + + --version-file-strategy + A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` + is called without a version, or when `--use-on-cd` is configured on evaluation. * `local`: Use the local version of Node defined within the current directory - * `recursive`: Use the version of Node defined within the current directory and all parent directories [env: - FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] + * `recursive`: Use the version of Node defined within the current directory and all + parent directories + + [env: FNM_VERSION_FILE_STRATEGY] + [default: local] + [possible values: local, recursive] ``` # `fnm default` ``` -fnm-default 1.29.2 +fnm-default Set a version as the default version This is a shorthand for `fnm alias VERSION default` USAGE: - fnm default [OPTIONS] + fnm default [OPTIONS] -FLAGS: - -h, --help - Prints help information - - -V, --version - Prints version information +ARGS: + OPTIONS: - --arch - Override the architecture of the installed Node binary. Defaults to arch of fnm binary [env: FNM_ARCH] + --arch + Override the architecture of the installed Node binary. Defaults to arch of fnm binary - --fnm-dir - The root directory of fnm installations [env: FNM_DIR] + [env: FNM_ARCH] - --log-level - The log level of fnm commands [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, - error] - --node-dist-mirror - https://nodejs.org/dist/ mirror [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] + --fnm-dir + The root directory of fnm installations - --version-file-strategy - A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a - version, or when `--use-on-cd` is configured on evaluation. + [env: FNM_DIR] - * `local`: Use the local version of Node defined within the current directory + -h, --help + Print help information - * `recursive`: Use the version of Node defined within the current directory and all parent directories [env: - FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] + --log-level + The log level of fnm commands -ARGS: - + [env: FNM_LOGLEVEL] + [default: info] + [possible values: quiet, info, all, error] + + --node-dist-mirror + https://nodejs.org/dist/ mirror + + [env: FNM_NODE_DIST_MIRROR] + [default: https://nodejs.org/dist] + --version-file-strategy + A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` + is called without a version, or when `--use-on-cd` is configured on evaluation. + + * `local`: Use the local version of Node defined within the current directory + * `recursive`: Use the version of Node defined within the current directory and all + parent directories + + [env: FNM_VERSION_FILE_STRATEGY] + [default: local] + [possible values: local, recursive] ``` # `fnm env` ``` -fnm-env 1.29.2 +fnm-env Print and set up required environment variables for fnm -This command generates a series of shell commands that should be evaluated by your shell to create a fnm-ready -environment. +This command generates a series of shell commands that should be evaluated by your shell to create a +fnm-ready environment. -Each shell has its own syntax of evaluating a dynamic expression. For example, evaluating fnm on Bash and Zsh would look -like `eval "$(fnm env)"`. In Fish, evaluating would look like `fnm env | source` +Each shell has its own syntax of evaluating a dynamic expression. For example, evaluating fnm on +Bash and Zsh would look like `eval "$(fnm env)"`. In Fish, evaluating would look like `fnm env | +source` USAGE: - fnm env [FLAGS] [OPTIONS] + fnm env [OPTIONS] + +OPTIONS: + --arch + Override the architecture of the installed Node binary. Defaults to arch of fnm binary + + [env: FNM_ARCH] + + --fnm-dir + The root directory of fnm installations + + [env: FNM_DIR] -FLAGS: -h, --help - Prints help information + Print help information - --use-on-cd - Print the script to change Node versions every directory change + --log-level + The log level of fnm commands - -V, --version - Prints version information + [env: FNM_LOGLEVEL] + [default: info] + [possible values: quiet, info, all, error] + --node-dist-mirror + https://nodejs.org/dist/ mirror -OPTIONS: - --arch - Override the architecture of the installed Node binary. Defaults to arch of fnm binary [env: FNM_ARCH] + [env: FNM_NODE_DIST_MIRROR] + [default: https://nodejs.org/dist] - --fnm-dir - The root directory of fnm installations [env: FNM_DIR] + --shell + The shell syntax to use. Infers when missing - --log-level - The log level of fnm commands [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, - error] - --node-dist-mirror - https://nodejs.org/dist/ mirror [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] + [possible values: bash, zsh, fish, powershell] - --shell - The shell syntax to use. Infers when missing [possible values: bash, zsh, fish, powershell] + --use-on-cd + Print the script to change Node versions every directory change - --version-file-strategy - A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a - version, or when `--use-on-cd` is configured on evaluation. + --version-file-strategy + A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` + is called without a version, or when `--use-on-cd` is configured on evaluation. * `local`: Use the local version of Node defined within the current directory - * `recursive`: Use the version of Node defined within the current directory and all parent directories [env: - FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] + * `recursive`: Use the version of Node defined within the current directory and all + parent directories + + [env: FNM_VERSION_FILE_STRATEGY] + [default: local] + [possible values: local, recursive] ``` # `fnm exec` ``` -fnm-exec 1.29.2 +fnm-exec Run a command within fnm context Example: @@ -295,45 +372,54 @@ fnm exec --using=v12.0.0 node --version => v12.0.0 USAGE: - fnm exec [OPTIONS] [arguments]... + fnm exec [OPTIONS] [ARGUMENTS]... -FLAGS: - -h, --help - Prints help information +ARGS: + ... + The command to run - -V, --version - Prints version information +OPTIONS: + --arch + Override the architecture of the installed Node binary. Defaults to arch of fnm binary + [env: FNM_ARCH] -OPTIONS: - --arch - Override the architecture of the installed Node binary. Defaults to arch of fnm binary [env: FNM_ARCH] + --fnm-dir + The root directory of fnm installations + + [env: FNM_DIR] + + -h, --help + Print help information + + --log-level + The log level of fnm commands - --fnm-dir - The root directory of fnm installations [env: FNM_DIR] + [env: FNM_LOGLEVEL] + [default: info] + [possible values: quiet, info, all, error] - --log-level - The log level of fnm commands [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, - error] - --node-dist-mirror - https://nodejs.org/dist/ mirror [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] + --node-dist-mirror + https://nodejs.org/dist/ mirror - --using + [env: FNM_NODE_DIST_MIRROR] + [default: https://nodejs.org/dist] + + --using Either an explicit version, or a filename with the version written in it - --version-file-strategy - A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a - version, or when `--use-on-cd` is configured on evaluation. + --version-file-strategy + A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` + is called without a version, or when `--use-on-cd` is configured on evaluation. * `local`: Use the local version of Node defined within the current directory - * `recursive`: Use the version of Node defined within the current directory and all parent directories [env: - FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] - -ARGS: - ... - The command to run + * `recursive`: Use the version of Node defined within the current directory and all + parent directories + [env: FNM_VERSION_FILE_STRATEGY] + [default: local] + [possible values: local, recursive] ``` # `fnm help` @@ -345,271 +431,328 @@ ARGS: # `fnm install` ``` -fnm-install 1.29.2 +fnm-install Install a new Node.js version USAGE: - fnm install [FLAGS] [OPTIONS] [version] + fnm install [OPTIONS] [VERSION] -FLAGS: - -h, --help - Prints help information +ARGS: + + A version string. Can be a partial semver or a LTS version name by the format lts/NAME - --lts - Install latest LTS +OPTIONS: + --arch + Override the architecture of the installed Node binary. Defaults to arch of fnm binary - -V, --version - Prints version information + [env: FNM_ARCH] + --fnm-dir + The root directory of fnm installations -OPTIONS: - --arch - Override the architecture of the installed Node binary. Defaults to arch of fnm binary [env: FNM_ARCH] + [env: FNM_DIR] - --fnm-dir - The root directory of fnm installations [env: FNM_DIR] + -h, --help + Print help information - --log-level - The log level of fnm commands [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, - error] - --node-dist-mirror - https://nodejs.org/dist/ mirror [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] + --log-level + The log level of fnm commands - --version-file-strategy - A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a - version, or when `--use-on-cd` is configured on evaluation. + [env: FNM_LOGLEVEL] + [default: info] + [possible values: quiet, info, all, error] - * `local`: Use the local version of Node defined within the current directory + --lts + Install latest LTS - * `recursive`: Use the version of Node defined within the current directory and all parent directories [env: - FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] + --node-dist-mirror + https://nodejs.org/dist/ mirror -ARGS: - - A version string. Can be a partial semver or a LTS version name by the format lts/NAME + [env: FNM_NODE_DIST_MIRROR] + [default: https://nodejs.org/dist] + + --version-file-strategy + A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` + is called without a version, or when `--use-on-cd` is configured on evaluation. + * `local`: Use the local version of Node defined within the current directory + + * `recursive`: Use the version of Node defined within the current directory and all + parent directories + + [env: FNM_VERSION_FILE_STRATEGY] + [default: local] + [possible values: local, recursive] ``` # `fnm list` ``` -fnm-list 1.29.2 +fnm-list List all locally installed Node.js versions USAGE: fnm list [OPTIONS] -FLAGS: - -h, --help - Prints help information +OPTIONS: + --arch + Override the architecture of the installed Node binary. Defaults to arch of fnm binary - -V, --version - Prints version information + [env: FNM_ARCH] + --fnm-dir + The root directory of fnm installations -OPTIONS: - --arch - Override the architecture of the installed Node binary. Defaults to arch of fnm binary [env: FNM_ARCH] + [env: FNM_DIR] + + -h, --help + Print help information - --fnm-dir - The root directory of fnm installations [env: FNM_DIR] + --log-level + The log level of fnm commands - --log-level - The log level of fnm commands [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, - error] - --node-dist-mirror - https://nodejs.org/dist/ mirror [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] + [env: FNM_LOGLEVEL] + [default: info] + [possible values: quiet, info, all, error] - --version-file-strategy - A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a - version, or when `--use-on-cd` is configured on evaluation. + --node-dist-mirror + https://nodejs.org/dist/ mirror + + [env: FNM_NODE_DIST_MIRROR] + [default: https://nodejs.org/dist] + + --version-file-strategy + A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` + is called without a version, or when `--use-on-cd` is configured on evaluation. * `local`: Use the local version of Node defined within the current directory - * `recursive`: Use the version of Node defined within the current directory and all parent directories [env: - FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] + * `recursive`: Use the version of Node defined within the current directory and all + parent directories + + [env: FNM_VERSION_FILE_STRATEGY] + [default: local] + [possible values: local, recursive] ``` # `fnm list-remote` ``` -fnm-list-remote 1.29.2 +fnm-list-remote List all remote Node.js versions USAGE: fnm list-remote [OPTIONS] -FLAGS: - -h, --help - Prints help information +OPTIONS: + --arch + Override the architecture of the installed Node binary. Defaults to arch of fnm binary - -V, --version - Prints version information + [env: FNM_ARCH] + --fnm-dir + The root directory of fnm installations -OPTIONS: - --arch - Override the architecture of the installed Node binary. Defaults to arch of fnm binary [env: FNM_ARCH] + [env: FNM_DIR] + + -h, --help + Print help information + + --log-level + The log level of fnm commands - --fnm-dir - The root directory of fnm installations [env: FNM_DIR] + [env: FNM_LOGLEVEL] + [default: info] + [possible values: quiet, info, all, error] - --log-level - The log level of fnm commands [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, - error] - --node-dist-mirror - https://nodejs.org/dist/ mirror [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] + --node-dist-mirror + https://nodejs.org/dist/ mirror - --version-file-strategy - A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a - version, or when `--use-on-cd` is configured on evaluation. + [env: FNM_NODE_DIST_MIRROR] + [default: https://nodejs.org/dist] + + --version-file-strategy + A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` + is called without a version, or when `--use-on-cd` is configured on evaluation. * `local`: Use the local version of Node defined within the current directory - * `recursive`: Use the version of Node defined within the current directory and all parent directories [env: - FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] + * `recursive`: Use the version of Node defined within the current directory and all + parent directories + + [env: FNM_VERSION_FILE_STRATEGY] + [default: local] + [possible values: local, recursive] ``` # `fnm unalias` ``` -fnm-unalias 1.29.2 +fnm-unalias Remove an alias definition USAGE: - fnm unalias [OPTIONS] - -FLAGS: - -h, --help - Prints help information + fnm unalias [OPTIONS] - -V, --version - Prints version information +ARGS: + OPTIONS: - --arch - Override the architecture of the installed Node binary. Defaults to arch of fnm binary [env: FNM_ARCH] + --arch + Override the architecture of the installed Node binary. Defaults to arch of fnm binary - --fnm-dir - The root directory of fnm installations [env: FNM_DIR] + [env: FNM_ARCH] - --log-level - The log level of fnm commands [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, - error] - --node-dist-mirror - https://nodejs.org/dist/ mirror [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] + --fnm-dir + The root directory of fnm installations - --version-file-strategy - A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a - version, or when `--use-on-cd` is configured on evaluation. + [env: FNM_DIR] - * `local`: Use the local version of Node defined within the current directory + -h, --help + Print help information - * `recursive`: Use the version of Node defined within the current directory and all parent directories [env: - FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] + --log-level + The log level of fnm commands -ARGS: - + [env: FNM_LOGLEVEL] + [default: info] + [possible values: quiet, info, all, error] + + --node-dist-mirror + https://nodejs.org/dist/ mirror + + [env: FNM_NODE_DIST_MIRROR] + [default: https://nodejs.org/dist] + + --version-file-strategy + A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` + is called without a version, or when `--use-on-cd` is configured on evaluation. + + * `local`: Use the local version of Node defined within the current directory + * `recursive`: Use the version of Node defined within the current directory and all + parent directories + [env: FNM_VERSION_FILE_STRATEGY] + [default: local] + [possible values: local, recursive] ``` # `fnm uninstall` ``` -fnm-uninstall 1.29.2 +fnm-uninstall Uninstall a Node.js version -> Warning: when providing an alias, it will remove the Node version the alias is pointing to, along with the other -aliases that point to the same version. +> Warning: when providing an alias, it will remove the Node version the alias is pointing to, along +with the other aliases that point to the same version. USAGE: - fnm uninstall [OPTIONS] [version] + fnm uninstall [OPTIONS] [VERSION] -FLAGS: - -h, --help - Prints help information - - -V, --version - Prints version information +ARGS: + OPTIONS: - --arch - Override the architecture of the installed Node binary. Defaults to arch of fnm binary [env: FNM_ARCH] + --arch + Override the architecture of the installed Node binary. Defaults to arch of fnm binary - --fnm-dir - The root directory of fnm installations [env: FNM_DIR] + [env: FNM_ARCH] - --log-level - The log level of fnm commands [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, - error] - --node-dist-mirror - https://nodejs.org/dist/ mirror [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] + --fnm-dir + The root directory of fnm installations - --version-file-strategy - A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a - version, or when `--use-on-cd` is configured on evaluation. + [env: FNM_DIR] - * `local`: Use the local version of Node defined within the current directory + -h, --help + Print help information - * `recursive`: Use the version of Node defined within the current directory and all parent directories [env: - FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] + --log-level + The log level of fnm commands -ARGS: - + [env: FNM_LOGLEVEL] + [default: info] + [possible values: quiet, info, all, error] + + --node-dist-mirror + https://nodejs.org/dist/ mirror + + [env: FNM_NODE_DIST_MIRROR] + [default: https://nodejs.org/dist] + --version-file-strategy + A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` + is called without a version, or when `--use-on-cd` is configured on evaluation. + * `local`: Use the local version of Node defined within the current directory + + * `recursive`: Use the version of Node defined within the current directory and all + parent directories + + [env: FNM_VERSION_FILE_STRATEGY] + [default: local] + [possible values: local, recursive] ``` # `fnm use` ``` -fnm-use 1.29.2 +fnm-use Change Node.js version USAGE: - fnm use [FLAGS] [OPTIONS] [version] + fnm use [OPTIONS] [VERSION] + +ARGS: + + + +OPTIONS: + --arch + Override the architecture of the installed Node binary. Defaults to arch of fnm binary + + [env: FNM_ARCH] + + --fnm-dir + The root directory of fnm installations + + [env: FNM_DIR] -FLAGS: -h, --help - Prints help information + Print help information --install-if-missing Install the version if it isn't installed yet - --silent-if-unchanged - Don't output a message identifying the version being used if it will not change due to execution of this - command - -V, --version - Prints version information + --log-level + The log level of fnm commands + [env: FNM_LOGLEVEL] + [default: info] + [possible values: quiet, info, all, error] -OPTIONS: - --arch - Override the architecture of the installed Node binary. Defaults to arch of fnm binary [env: FNM_ARCH] + --node-dist-mirror + https://nodejs.org/dist/ mirror - --fnm-dir - The root directory of fnm installations [env: FNM_DIR] + [env: FNM_NODE_DIST_MIRROR] + [default: https://nodejs.org/dist] - --log-level - The log level of fnm commands [env: FNM_LOGLEVEL] [default: info] [possible values: quiet, info, all, - error] - --node-dist-mirror - https://nodejs.org/dist/ mirror [env: FNM_NODE_DIST_MIRROR] [default: https://nodejs.org/dist] + --silent-if-unchanged + Don't output a message identifying the version being used if it will not change due to + execution of this command - --version-file-strategy - A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` is called without a - version, or when `--use-on-cd` is configured on evaluation. + --version-file-strategy + A strategy for how to resolve the Node version. Used whenever `fnm use` or `fnm install` + is called without a version, or when `--use-on-cd` is configured on evaluation. * `local`: Use the local version of Node defined within the current directory - * `recursive`: Use the version of Node defined within the current directory and all parent directories [env: - FNM_VERSION_FILE_STRATEGY] [default: local] [possible values: local, recursive] - -ARGS: - - + * `recursive`: Use the version of Node defined within the current directory and all + parent directories + [env: FNM_VERSION_FILE_STRATEGY] + [default: local] + [possible values: local, recursive] ``` diff --git a/src/cli.rs b/src/cli.rs index 4d5c976..ad54ec1 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,24 +1,24 @@ use crate::commands; use crate::commands::command::Command; use crate::config::FnmConfig; -use structopt::StructOpt; +use clap::Parser; -#[derive(StructOpt, Debug)] +#[derive(clap::Parser, Debug)] pub enum SubCommand { /// List all remote Node.js versions - #[structopt(name = "list-remote", visible_aliases = &["ls-remote"])] + #[clap(name = "list-remote", visible_aliases = &["ls-remote"])] LsRemote(commands::ls_remote::LsRemote), /// List all locally installed Node.js versions - #[structopt(name = "list", visible_aliases = &["ls"])] + #[clap(name = "list", visible_aliases = &["ls"])] LsLocal(commands::ls_local::LsLocal), /// Install a new Node.js version - #[structopt(name = "install")] + #[clap(name = "install")] Install(commands::install::Install), /// Change Node.js version - #[structopt(name = "use")] + #[clap(name = "use")] Use(commands::r#use::Use), /// Print and set up required environment variables for fnm @@ -29,29 +29,29 @@ pub enum SubCommand { /// Each shell has its own syntax of evaluating a dynamic expression. /// For example, evaluating fnm on Bash and Zsh would look like `eval "$(fnm env)"`. /// In Fish, evaluating would look like `fnm env | source` - #[structopt(name = "env")] + #[clap(name = "env")] Env(commands::env::Env), /// Print shell completions to stdout - #[structopt(name = "completions")] + #[clap(name = "completions")] Completions(commands::completions::Completions), /// Alias a version to a common name - #[structopt(name = "alias")] + #[clap(name = "alias")] Alias(commands::alias::Alias), /// Remove an alias definition - #[structopt(name = "unalias")] + #[clap(name = "unalias")] Unalias(commands::unalias::Unalias), /// Set a version as the default version /// /// This is a shorthand for `fnm alias VERSION default` - #[structopt(name = "default")] + #[clap(name = "default")] Default(commands::default::Default), /// Print the current Node.js version - #[structopt(name = "current")] + #[clap(name = "current")] Current(commands::current::Current), /// Run a command within fnm context @@ -60,14 +60,14 @@ pub enum SubCommand { /// -------- /// fnm exec --using=v12.0.0 node --version /// => v12.0.0 - #[structopt(name = "exec", verbatim_doc_comment)] + #[clap(name = "exec", verbatim_doc_comment)] Exec(commands::exec::Exec), /// Uninstall a Node.js version /// /// > Warning: when providing an alias, it will remove the Node version the alias /// is pointing to, along with the other aliases that point to the same version. - #[structopt(name = "uninstall")] + #[clap(name = "uninstall")] Uninstall(commands::uninstall::Uninstall), } @@ -91,15 +91,15 @@ impl SubCommand { } /// A fast and simple Node.js manager. -#[derive(StructOpt, Debug)] -#[structopt(name = "fnm")] +#[derive(clap::Parser, Debug)] +#[clap(name = "fnm", version = env!("CARGO_PKG_VERSION"))] pub struct Cli { - #[structopt(flatten)] + #[clap(flatten)] pub config: FnmConfig, - #[structopt(subcommand)] + #[clap(subcommand)] pub subcmd: SubCommand, } pub fn parse() -> Cli { - Cli::from_args() + Cli::parse() } diff --git a/src/commands/alias.rs b/src/commands/alias.rs index 6f6f5cb..cbee361 100644 --- a/src/commands/alias.rs +++ b/src/commands/alias.rs @@ -5,10 +5,9 @@ use crate::choose_version_for_user_input::{ }; use crate::config::FnmConfig; use crate::user_version::UserVersion; -use structopt::StructOpt; use thiserror::Error; -#[derive(StructOpt, Debug)] +#[derive(clap::Parser, Debug)] pub struct Alias { pub(crate) to_version: UserVersion, pub(crate) name: String, diff --git a/src/commands/completions.rs b/src/commands/completions.rs index b63a248..47ca885 100644 --- a/src/commands/completions.rs +++ b/src/commands/completions.rs @@ -2,14 +2,14 @@ use super::command::Command; use crate::cli::Cli; use crate::config::FnmConfig; use crate::shell::{infer_shell, AVAILABLE_SHELLS}; -use structopt::clap::Shell; -use structopt::StructOpt; +use clap::{IntoApp, Parser}; +use clap_complete::{Generator, Shell}; use thiserror::Error; -#[derive(StructOpt, Debug)] +#[derive(Parser, Debug)] pub struct Completions { /// The shell syntax to use. Infers when missing. - #[structopt(long, possible_values = &Shell::variants())] + #[clap(long)] shell: Option, } @@ -22,7 +22,8 @@ impl Command for Completions { .shell .or_else(|| infer_shell().map(Into::into)) .ok_or(Error::CantInferShell)?; - Cli::clap().gen_completions_to(env!("CARGO_PKG_NAME"), shell, &mut stdio); + let app = Cli::into_app(); + shell.generate(&app, &mut stdio); Ok(()) } } diff --git a/src/commands/current.rs b/src/commands/current.rs index 74cb7e1..1081f72 100644 --- a/src/commands/current.rs +++ b/src/commands/current.rs @@ -1,9 +1,8 @@ use super::command::Command; use crate::config::FnmConfig; use crate::current_version::{current_version, Error}; -use structopt::StructOpt; -#[derive(StructOpt, Debug)] +#[derive(clap::Parser, Debug)] pub struct Current {} impl Command for Current { diff --git a/src/commands/default.rs b/src/commands/default.rs index a24d208..496522c 100644 --- a/src/commands/default.rs +++ b/src/commands/default.rs @@ -2,9 +2,8 @@ use super::alias::Alias; use super::command::Command; use crate::config::FnmConfig; use crate::user_version::UserVersion; -use structopt::StructOpt; -#[derive(StructOpt, Debug)] +#[derive(clap::Parser, Debug)] pub struct Default { version: UserVersion, } diff --git a/src/commands/env.rs b/src/commands/env.rs index 06af10c..6fda72a 100644 --- a/src/commands/env.rs +++ b/src/commands/env.rs @@ -6,20 +6,19 @@ use crate::path_ext::PathExt; use crate::shell::{infer_shell, Shell, AVAILABLE_SHELLS}; use colored::Colorize; use std::fmt::Debug; -use structopt::StructOpt; use thiserror::Error; -#[derive(StructOpt, Debug, Default)] +#[derive(clap::Parser, Debug, Default)] pub struct Env { /// The shell syntax to use. Infers when missing. - #[structopt(long)] - #[structopt(possible_values = AVAILABLE_SHELLS)] + #[clap(long)] + #[clap(possible_values = AVAILABLE_SHELLS)] shell: Option>, /// Deprecated. This is the default now. - #[structopt(long, hidden = true)] + #[clap(long, hide = true)] multi: bool, /// Print the script to change Node versions every directory change - #[structopt(long)] + #[clap(long)] use_on_cd: bool, } diff --git a/src/commands/exec.rs b/src/commands/exec.rs index dbe2cfd..3203b01 100644 --- a/src/commands/exec.rs +++ b/src/commands/exec.rs @@ -8,17 +8,16 @@ use crate::user_version::UserVersion; use crate::user_version_reader::UserVersionReader; use colored::Colorize; use std::process::{Command, Stdio}; -use structopt::StructOpt; use thiserror::Error; -#[derive(Debug, StructOpt)] -#[structopt(setting = structopt::clap::AppSettings::TrailingVarArg)] +#[derive(Debug, clap::Parser)] +#[clap(setting = clap::AppSettings::TrailingVarArg)] pub struct Exec { /// Either an explicit version, or a filename with the version written in it - #[structopt(long = "using")] + #[clap(long = "using")] version: Option, /// Deprecated. This is the default now. - #[structopt(long = "using-file", hidden = true)] + #[clap(long = "using-file", hide = true)] using_file: bool, /// The command to run arguments: Vec, diff --git a/src/commands/install.rs b/src/commands/install.rs index a247bd6..7b37d1c 100644 --- a/src/commands/install.rs +++ b/src/commands/install.rs @@ -10,16 +10,15 @@ use crate::version::Version; use crate::version_files::get_user_version_for_directory; use colored::Colorize; use log::debug; -use structopt::StructOpt; use thiserror::Error; -#[derive(StructOpt, Debug, Default)] +#[derive(clap::Parser, Debug, Default)] pub struct Install { /// A version string. Can be a partial semver or a LTS version name by the format lts/NAME pub version: Option, /// Install latest LTS - #[structopt(long, conflicts_with = "version")] + #[clap(long, conflicts_with = "version")] pub lts: bool, } diff --git a/src/commands/ls_local.rs b/src/commands/ls_local.rs index b614a7e..e0f003c 100644 --- a/src/commands/ls_local.rs +++ b/src/commands/ls_local.rs @@ -4,10 +4,9 @@ use crate::current_version::current_version; use crate::version::Version; use colored::Colorize; use std::collections::HashMap; -use structopt::StructOpt; use thiserror::Error; -#[derive(StructOpt, Debug)] +#[derive(clap::Parser, Debug)] pub struct LsLocal {} impl super::command::Command for LsLocal { diff --git a/src/commands/ls_remote.rs b/src/commands/ls_remote.rs index 1090e38..15cccc1 100644 --- a/src/commands/ls_remote.rs +++ b/src/commands/ls_remote.rs @@ -1,9 +1,8 @@ use crate::config::FnmConfig; use crate::remote_node_index; -use structopt::StructOpt; use thiserror::Error; -#[derive(StructOpt, Debug)] +#[derive(clap::Parser, Debug)] pub struct LsRemote {} impl super::command::Command for LsRemote { diff --git a/src/commands/unalias.rs b/src/commands/unalias.rs index e6bc99e..6cab4af 100644 --- a/src/commands/unalias.rs +++ b/src/commands/unalias.rs @@ -3,10 +3,9 @@ use crate::fs::remove_symlink_dir; use crate::user_version::UserVersion; use crate::version::Version; use crate::{choose_version_for_user_input, config::FnmConfig}; -use structopt::StructOpt; use thiserror::Error; -#[derive(StructOpt, Debug)] +#[derive(clap::Parser, Debug)] pub struct Unalias { pub(crate) requested_alias: String, } diff --git a/src/commands/uninstall.rs b/src/commands/uninstall.rs index 700e881..b254260 100644 --- a/src/commands/uninstall.rs +++ b/src/commands/uninstall.rs @@ -8,10 +8,9 @@ use crate::version::Version; use crate::version_files::get_user_version_for_directory; use colored::Colorize; use log::debug; -use structopt::StructOpt; use thiserror::Error; -#[derive(StructOpt, Debug)] +#[derive(clap::Parser, Debug)] pub struct Uninstall { version: Option, } diff --git a/src/commands/use.rs b/src/commands/use.rs index 279dbee..28a353b 100644 --- a/src/commands/use.rs +++ b/src/commands/use.rs @@ -11,19 +11,18 @@ use crate::version_file_strategy::VersionFileStrategy; use crate::{config::FnmConfig, user_version_reader::UserVersionReader}; use colored::Colorize; use std::path::Path; -use structopt::StructOpt; use thiserror::Error; -#[derive(StructOpt, Debug)] +#[derive(clap::Parser, Debug)] pub struct Use { version: Option, /// Install the version if it isn't installed yet - #[structopt(long)] + #[clap(long)] install_if_missing: bool, /// Don't output a message identifying the version being used /// if it will not change due to execution of this command - #[structopt(long)] + #[clap(long)] silent_if_unchanged: bool, } diff --git a/src/config.rs b/src/config.rs index e05ddda..f064415 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,13 +3,12 @@ use crate::log_level::LogLevel; use crate::path_ext::PathExt; use crate::version_file_strategy::VersionFileStrategy; use dirs::{data_dir, home_dir}; -use structopt::StructOpt; use url::Url; -#[derive(StructOpt, Debug)] +#[derive(clap::Parser, Debug)] pub struct FnmConfig { /// https://nodejs.org/dist/ mirror - #[structopt( + #[clap( long, env = "FNM_NODE_DIST_MIRROR", default_value = "https://nodejs.org/dist", @@ -19,7 +18,7 @@ pub struct FnmConfig { pub node_dist_mirror: Url, /// The root directory of fnm installations. - #[structopt( + #[clap( long = "fnm-dir", env = "FNM_DIR", global = true, @@ -30,16 +29,11 @@ pub struct FnmConfig { /// Where the current node version link is stored. /// This value will be populated automatically by evaluating /// `fnm env` in your shell profile. Read more about it using `fnm help env` - #[structopt( - long, - env = "FNM_MULTISHELL_PATH", - hide_env_values = true, - hidden = true - )] + #[clap(long, env = "FNM_MULTISHELL_PATH", hide_env_values = true, hide = true)] multishell_path: Option, /// The log level of fnm commands - #[structopt( + #[clap( long, env = "FNM_LOGLEVEL", default_value = "info", @@ -51,10 +45,10 @@ pub struct FnmConfig { /// Override the architecture of the installed Node binary. /// Defaults to arch of fnm binary. - #[structopt( + #[clap( long, env = "FNM_ARCH", - default_value, + default_value_t, global = true, hide_env_values = true, hide_default_value = true @@ -67,7 +61,7 @@ pub struct FnmConfig { /// * `local`: Use the local version of Node defined within the current directory /// /// * `recursive`: Use the version of Node defined within the current directory and all parent directories - #[structopt( + #[clap( long, env = "FNM_VERSION_FILE_STRATEGY", possible_values = VersionFileStrategy::possible_values(), diff --git a/src/shell/bash.rs b/src/shell/bash.rs index 81ae55e..4d9151e 100644 --- a/src/shell/bash.rs +++ b/src/shell/bash.rs @@ -8,8 +8,8 @@ use std::path::Path; pub struct Bash; impl Shell for Bash { - fn to_structopt_shell(&self) -> structopt::clap::Shell { - structopt::clap::Shell::Bash + fn to_clap_shell(&self) -> clap_complete::Shell { + clap_complete::Shell::Bash } fn path(&self, path: &Path) -> String { diff --git a/src/shell/fish.rs b/src/shell/fish.rs index 6eef262..554ae66 100644 --- a/src/shell/fish.rs +++ b/src/shell/fish.rs @@ -8,8 +8,8 @@ use std::path::Path; pub struct Fish; impl Shell for Fish { - fn to_structopt_shell(&self) -> structopt::clap::Shell { - structopt::clap::Shell::Fish + fn to_clap_shell(&self) -> clap_complete::Shell { + clap_complete::Shell::Fish } fn path(&self, path: &Path) -> String { diff --git a/src/shell/powershell.rs b/src/shell/powershell.rs index 663fd3e..43dad72 100644 --- a/src/shell/powershell.rs +++ b/src/shell/powershell.rs @@ -41,7 +41,7 @@ impl Shell for PowerShell { autoload_hook = autoload_hook ) } - fn to_structopt_shell(&self) -> clap::Shell { - clap::Shell::PowerShell + fn to_clap_shell(&self) -> clap_complete::Shell { + clap_complete::Shell::PowerShell } } diff --git a/src/shell/shell.rs b/src/shell/shell.rs index 8d48824..6220c87 100644 --- a/src/shell/shell.rs +++ b/src/shell/shell.rs @@ -8,7 +8,7 @@ pub trait Shell: Debug { fn rehash(&self) -> Option { None } - fn to_structopt_shell(&self) -> structopt::clap::Shell; + fn to_clap_shell(&self) -> clap_complete::Shell; } #[cfg(windows)] @@ -32,8 +32,8 @@ impl std::str::FromStr for Box { } } -impl From> for structopt::clap::Shell { +impl From> for clap_complete::Shell { fn from(shell: Box) -> Self { - shell.to_structopt_shell() + shell.to_clap_shell() } } diff --git a/src/shell/windows_cmd/mod.rs b/src/shell/windows_cmd/mod.rs index f1f6d4c..69bbe1d 100644 --- a/src/shell/windows_cmd/mod.rs +++ b/src/shell/windows_cmd/mod.rs @@ -5,7 +5,8 @@ use std::path::Path; pub struct WindowsCmd; impl Shell for WindowsCmd { - fn to_structopt_shell(&self) -> structopt::clap::Shell { + fn to_clap_shell(&self) -> clap_complete::Shell { + // TODO: move to Option panic!("Shell completion is not supported for Windows Command Prompt. Maybe try using PowerShell for a better experience?"); } diff --git a/src/shell/zsh.rs b/src/shell/zsh.rs index 59a87f1..a87c11d 100644 --- a/src/shell/zsh.rs +++ b/src/shell/zsh.rs @@ -8,8 +8,8 @@ use std::path::Path; pub struct Zsh; impl Shell for Zsh { - fn to_structopt_shell(&self) -> structopt::clap::Shell { - structopt::clap::Shell::Zsh + fn to_clap_shell(&self) -> clap_complete::Shell { + clap_complete::Shell::Zsh } fn path(&self, path: &Path) -> String {