[Fix] ensure `--help` is intercepted on any command
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Naomi Quinones · committed by Jordan Harband · parent a01deb1 · Browse files · 2 files·+97 added−82 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Co-authored-by: Naomi Quinones <52065567+naomiquinones@users.noreply.github.com>
- Co-authored-by: Dena Burd <me@Denas-MacBook-Air.local>
Diff stats
2 files+97 added−82 removed
- tests:+9 added−0 removed
- other:+88 added−82 removed
Provenance
- Commit
1bf567b- Tree
4bc8a0f- Author
Naomi Quinones <52065567+naomiquinones@users.noreply.github.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
a01deb1
2 files changed+97 added−82 removed
added:test/fast/Unit tests/nvm_check_for_help+9 added
1+#!/bin/sh2+3+die () { echo "$@" ; exit 1; }4+5+\. ../../../nvm.sh6+7+TERM=dumb nvm clear-cache --help | grep 'Usage:' || die 'did not print help menu'8+TERM=dumb nvm cache help version | grep 'Usage:' || die 'did not print help menu'9+TERM=dumb nvm cache -h version| grep 'Usage:' || die 'did not print help menu'modified:nvm.sh+88 added-82 removed
2343 unmodified lines2344 IFS="${DEFAULT_IFS}" nvm "$@"2345 return $?2346 fi2347 2348+ for i in "$@"2349+ do2350+ case $i in2351+ '-h'|'help'|'--help')2352+ local NVM_IOJS_PREFIX2353+ NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"2354+ local NVM_NODE_PREFIX2355+ NVM_NODE_PREFIX="$(nvm_node_prefix)"2356+ NVM_VERSION="$(nvm --version)"2357+ nvm_echo2358+ nvm_echo "Node Version Manager (v${NVM_VERSION})"2359+ nvm_echo2360+ nvm_echo 'Note: <version> refers to any version-like string nvm understands. This includes:'2361+ nvm_echo ' - full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)'2362+ nvm_echo " - default (built-in) aliases: ${NVM_NODE_PREFIX}, stable, unstable, ${NVM_IOJS_PREFIX}, system"2363+ nvm_echo ' - custom aliases you define with `nvm alias foo`'2364+ nvm_echo2365+ nvm_echo ' Any options that produce colorized output should respect the `--no-colors` option.'2366+ nvm_echo2367+ nvm_echo 'Usage:'2368+ nvm_echo ' nvm --help Show this message'2369+ nvm_echo ' nvm --version Print out the installed version of nvm'2370+ nvm_echo ' nvm install [-s] [<version>] Download and install a <version>, [-s] from source. Uses .nvmrc if available'2371+ nvm_echo ' --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>'2372+ nvm_echo ' --lts When installing, only select from LTS (long-term support) versions'2373+ nvm_echo ' --lts=<LTS name> When installing, only select from versions for a specific LTS line'2374+ nvm_echo ' --skip-default-packages When installing, skip the default-packages file if it exists'2375+ nvm_echo ' --latest-npm After installing, attempt to upgrade to the latest working npm on the given node version'2376+ nvm_echo ' --no-progress Disable the progress bar on any downloads'2377+ nvm_echo ' --alias=<name> After installing, set the alias specified to the version specified. (same as: nvm alias <name> <version>)'2378+ nvm_echo ' --default After installing, set default alias to the version specified. (same as: nvm alias default <version>)'2379+ nvm_echo ' nvm uninstall <version> Uninstall a version'2380+ nvm_echo ' nvm uninstall --lts Uninstall using automatic LTS (long-term support) alias `lts/*`, if available.'2381+ nvm_echo ' nvm uninstall --lts=<LTS name> Uninstall using automatic alias for provided LTS line, if available.'2382+ nvm_echo ' nvm use [--silent] [<version>] Modify PATH to use <version>. Uses .nvmrc if available'2383+ nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'2384+ nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'2385+ nvm_echo ' nvm exec [--silent] [<version>] [<command>] Run <command> on <version>. Uses .nvmrc if available'2386+ nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'2387+ nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'2388+ nvm_echo ' nvm run [--silent] [<version>] [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available'2389+ nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'2390+ nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'2391+ nvm_echo ' nvm current Display currently activated version of Node'2392+ nvm_echo ' nvm ls [<version>] List installed versions, matching a given <version> if provided'2393+ nvm_echo ' --no-colors Suppress colored output'2394+ nvm_echo ' --no-alias Suppress `nvm alias` output'2395+ nvm_echo ' nvm ls-remote [<version>] List remote versions available for install, matching a given <version> if provided'2396+ nvm_echo ' --lts When listing, only show LTS (long-term support) versions'2397+ nvm_echo ' --lts=<LTS name> When listing, only show versions for a specific LTS line'2398+ nvm_echo ' --no-colors Suppress colored output'2399+ nvm_echo ' nvm version <version> Resolve the given description to a single local version'2400+ nvm_echo ' nvm version-remote <version> Resolve the given description to a single remote version'2401+ nvm_echo ' --lts When listing, only select from LTS (long-term support) versions'2402+ nvm_echo ' --lts=<LTS name> When listing, only select from versions for a specific LTS line'2403+ nvm_echo ' nvm deactivate Undo effects of `nvm` on current shell'2404+ nvm_echo ' nvm alias [<pattern>] Show all aliases beginning with <pattern>'2405+ nvm_echo ' --no-colors Suppress colored output'2406+ nvm_echo ' nvm alias <name> <version> Set an alias named <name> pointing to <version>'2407+ nvm_echo ' nvm unalias <name> Deletes the alias named <name>'2408+ nvm_echo ' nvm install-latest-npm Attempt to upgrade to the latest working `npm` on the current node version'2409+ nvm_echo ' nvm reinstall-packages <version> Reinstall global `npm` packages contained in <version> to current version'2410+ nvm_echo ' nvm unload Unload `nvm` from shell'2411+ nvm_echo ' nvm which [current | <version>] Display path to installed node version. Uses .nvmrc if available'2412+ nvm_echo ' nvm cache dir Display path to the cache directory for nvm'2413+ nvm_echo ' nvm cache clear Empty cache directory for nvm'2414+ nvm_echo2415+ nvm_echo 'Example:'2416+ nvm_echo ' nvm install 8.0.0 Install a specific version number'2417+ nvm_echo ' nvm use 8.0 Use the latest available 8.0.x release'2418+ nvm_echo ' nvm run 6.10.3 app.js Run app.js using node 6.10.3'2419+ nvm_echo ' nvm exec 4.8.3 node app.js Run `node app.js` with the PATH pointing to node 4.8.3'2420+ nvm_echo ' nvm alias default 8.1.0 Set default node version on a shell'2421+ nvm_echo ' nvm alias default node Always default to the latest available node version on a shell'2422+ nvm_echo2423+ nvm_echo ' nvm install node Install the latest available version'2424+ nvm_echo ' nvm use node Use the latest version'2425+ nvm_echo ' nvm install --lts Install the latest LTS version'2426+ nvm_echo ' nvm use --lts Use the latest LTS version'2427+ nvm_echo2428+ nvm_echo 'Note:'2429+ nvm_echo ' to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)'2430+ nvm_echo2431+ return 0;2432+ ;;2433+ esac2434+ done2435+2436 local COMMAND2437 COMMAND="${1-}"2438 shift2439 1 unmodified line2441 local VERSION2442 local ADDITIONAL_PARAMETERS2443 2444 case $COMMAND in2357- 'help' | '--help')2358- local NVM_IOJS_PREFIX2359- NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"2360- local NVM_NODE_PREFIX2361- NVM_NODE_PREFIX="$(nvm_node_prefix)"2362- NVM_VERSION="$(nvm --version)"2363- nvm_echo2364- nvm_echo "Node Version Manager (v${NVM_VERSION})"2365- nvm_echo2366- nvm_echo 'Note: <version> refers to any version-like string nvm understands. This includes:'2367- nvm_echo ' - full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)'2368- nvm_echo " - default (built-in) aliases: ${NVM_NODE_PREFIX}, stable, unstable, ${NVM_IOJS_PREFIX}, system"2369- nvm_echo ' - custom aliases you define with `nvm alias foo`'2370- nvm_echo2371- nvm_echo ' Any options that produce colorized output should respect the `--no-colors` option.'2372- nvm_echo2373- nvm_echo 'Usage:'2374- nvm_echo ' nvm --help Show this message'2375- nvm_echo ' nvm --version Print out the installed version of nvm'2376- nvm_echo ' nvm install [-s] [<version>] Download and install a <version>, [-s] from source. Uses .nvmrc if available'2377- nvm_echo ' --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>'2378- nvm_echo ' --lts When installing, only select from LTS (long-term support) versions'2379- nvm_echo ' --lts=<LTS name> When installing, only select from versions for a specific LTS line'2380- nvm_echo ' --skip-default-packages When installing, skip the default-packages file if it exists'2381- nvm_echo ' --latest-npm After installing, attempt to upgrade to the latest working npm on the given node version'2382- nvm_echo ' --no-progress Disable the progress bar on any downloads'2383- nvm_echo ' --alias=<name> After installing, set the alias specified to the version specified. (same as: nvm alias <name> <version>)'2384- nvm_echo ' --default After installing, set default alias to the version specified. (same as: nvm alias default <version>)'2385- nvm_echo ' nvm uninstall <version> Uninstall a version'2386- nvm_echo ' nvm uninstall --lts Uninstall using automatic LTS (long-term support) alias `lts/*`, if available.'2387- nvm_echo ' nvm uninstall --lts=<LTS name> Uninstall using automatic alias for provided LTS line, if available.'2388- nvm_echo ' nvm use [--silent] [<version>] Modify PATH to use <version>. Uses .nvmrc if available'2389- nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'2390- nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'2391- nvm_echo ' nvm exec [--silent] [<version>] [<command>] Run <command> on <version>. Uses .nvmrc if available'2392- nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'2393- nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'2394- nvm_echo ' nvm run [--silent] [<version>] [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available'2395- nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'2396- nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'2397- nvm_echo ' nvm current Display currently activated version of Node'2398- nvm_echo ' nvm ls [<version>] List installed versions, matching a given <version> if provided'2399- nvm_echo ' --no-colors Suppress colored output'2400- nvm_echo ' --no-alias Suppress `nvm alias` output'2401- nvm_echo ' nvm ls-remote [<version>] List remote versions available for install, matching a given <version> if provided'2402- nvm_echo ' --lts When listing, only show LTS (long-term support) versions'2403- nvm_echo ' --lts=<LTS name> When listing, only show versions for a specific LTS line'2404- nvm_echo ' --no-colors Suppress colored output'2405- nvm_echo ' nvm version <version> Resolve the given description to a single local version'2406- nvm_echo ' nvm version-remote <version> Resolve the given description to a single remote version'2407- nvm_echo ' --lts When listing, only select from LTS (long-term support) versions'2408- nvm_echo ' --lts=<LTS name> When listing, only select from versions for a specific LTS line'2409- nvm_echo ' nvm deactivate Undo effects of `nvm` on current shell'2410- nvm_echo ' nvm alias [<pattern>] Show all aliases beginning with <pattern>'2411- nvm_echo ' --no-colors Suppress colored output'2412- nvm_echo ' nvm alias <name> <version> Set an alias named <name> pointing to <version>'2413- nvm_echo ' nvm unalias <name> Deletes the alias named <name>'2414- nvm_echo ' nvm install-latest-npm Attempt to upgrade to the latest working `npm` on the current node version'2415- nvm_echo ' nvm reinstall-packages <version> Reinstall global `npm` packages contained in <version> to current version'2416- nvm_echo ' nvm unload Unload `nvm` from shell'2417- nvm_echo ' nvm which [current | <version>] Display path to installed node version. Uses .nvmrc if available'2418- nvm_echo ' nvm cache dir Display path to the cache directory for nvm'2419- nvm_echo ' nvm cache clear Empty cache directory for nvm'2420- nvm_echo2421- nvm_echo 'Example:'2422- nvm_echo ' nvm install 8.0.0 Install a specific version number'2423- nvm_echo ' nvm use 8.0 Use the latest available 8.0.x release'2424- nvm_echo ' nvm run 6.10.3 app.js Run app.js using node 6.10.3'2425- nvm_echo ' nvm exec 4.8.3 node app.js Run `node app.js` with the PATH pointing to node 4.8.3'2426- nvm_echo ' nvm alias default 8.1.0 Set default node version on a shell'2427- nvm_echo ' nvm alias default node Always default to the latest available node version on a shell'2428- nvm_echo2429- nvm_echo ' nvm install node Install the latest available version'2430- nvm_echo ' nvm use node Use the latest version'2431- nvm_echo ' nvm install --lts Install the latest LTS version'2432- nvm_echo ' nvm use --lts Use the latest LTS version'2433- nvm_echo2434- nvm_echo 'Note:'2435- nvm_echo ' to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)'2436- nvm_echo2437- ;;2438-2445 "cache")2446 case "${1-}" in2447 dir) nvm_cache_dir ;;2448 clear)1359 unmodified lines