From 9fe0df5b5d7606e5841288d9931be6c04767c9ca Mon Sep 17 00:00:00 2001 From: Gar Date: Wed, 3 Mar 2021 20:26:33 -0800 Subject: fix(usage): clean up usage declarations Small refactor of commands to allow usage to be more programmatically generated, leading us in the direction of more tighly coupling each command to the params it accepts. PR-URL: https://github.com/npm/cli/pull/2821 Credit: @wraithgar Close: #2821 Reviewed-by: @isaacs --- tap-snapshots/test-lib-dist-tag.js-TAP.test.js | 25 ++ tap-snapshots/test-lib-publish.js-TAP.test.js | 6 +- .../test-lib-utils-npm-usage.js-TAP.test.js | 472 +++++++++++++++++---- 3 files changed, 415 insertions(+), 88 deletions(-) (limited to 'tap-snapshots') diff --git a/tap-snapshots/test-lib-dist-tag.js-TAP.test.js b/tap-snapshots/test-lib-dist-tag.js-TAP.test.js index b135b1001..46aa6ce91 100644 --- a/tap-snapshots/test-lib-dist-tag.js-TAP.test.js +++ b/tap-snapshots/test-lib-dist-tag.js-TAP.test.js @@ -6,19 +6,29 @@ */ 'use strict' exports[`test/lib/dist-tag.js TAP add missing args > should exit usage error message 1`] = ` +npm dist-tag + +Usage: npm dist-tag add @ [] npm dist-tag rm npm dist-tag ls [] alias: dist-tags + +Run "npm dist-tag help" for more info ` exports[`test/lib/dist-tag.js TAP add missing pkg name > should exit usage error message 1`] = ` +npm dist-tag + +Usage: npm dist-tag add @ [] npm dist-tag rm npm dist-tag ls [] alias: dist-tags + +Run "npm dist-tag help" for more info ` exports[`test/lib/dist-tag.js TAP add new tag > should return success msg 1`] = ` @@ -31,11 +41,16 @@ dist-tag add 1.0.0 to @scoped/another@7.7.7 ` exports[`test/lib/dist-tag.js TAP borked cmd usage > should show usage error 1`] = ` +npm dist-tag + +Usage: npm dist-tag add @ [] npm dist-tag rm npm dist-tag ls [] alias: dist-tags + +Run "npm dist-tag help" for more info ` exports[`test/lib/dist-tag.js TAP ls in current package > should list available tags for current package 1`] = ` @@ -45,11 +60,16 @@ latest: 1.0.0 ` exports[`test/lib/dist-tag.js TAP ls on missing name in current package > should throw usage error message 1`] = ` +npm dist-tag + +Usage: npm dist-tag add @ [] npm dist-tag rm npm dist-tag ls [] alias: dist-tags + +Run "npm dist-tag help" for more info ` exports[`test/lib/dist-tag.js TAP ls on missing package > should log no dist-tag found msg 1`] = ` @@ -89,11 +109,16 @@ exports[`test/lib/dist-tag.js TAP remove existing tag > should return success ms ` exports[`test/lib/dist-tag.js TAP remove missing pkg name > should exit usage error message 1`] = ` +npm dist-tag + +Usage: npm dist-tag add @ [] npm dist-tag rm npm dist-tag ls [] alias: dist-tags + +Run "npm dist-tag help" for more info ` exports[`test/lib/dist-tag.js TAP remove non-existing tag > should log error msg 1`] = ` diff --git a/tap-snapshots/test-lib-publish.js-TAP.test.js b/tap-snapshots/test-lib-publish.js-TAP.test.js index 6af6c13f5..6fad3e26b 100644 --- a/tap-snapshots/test-lib-publish.js-TAP.test.js +++ b/tap-snapshots/test-lib-publish.js-TAP.test.js @@ -6,8 +6,10 @@ */ 'use strict' exports[`test/lib/publish.js TAP shows usage with wrong set of arguments > should print usage 1`] = ` +npm publish + +Usage: npm publish [] [--tag ] [--access ] [--dry-run] -Publishes '.' if no argument supplied -Sets tag \`latest\` if no --tag specified +Run "npm publish help" for more info ` diff --git a/tap-snapshots/test-lib-utils-npm-usage.js-TAP.test.js b/tap-snapshots/test-lib-utils-npm-usage.js-TAP.test.js index 8e1603eb4..3ff008d07 100644 --- a/tap-snapshots/test-lib-utils-npm-usage.js-TAP.test.js +++ b/tap-snapshots/test-lib-utils-npm-usage.js-TAP.test.js @@ -207,7 +207,10 @@ npm help npm more involved overview All commands: - access npm access public [] + access npm access + + Usage: + npm access public [] npm access restricted [] npm access grant [] npm access revoke [] @@ -216,121 +219,226 @@ All commands: npm access ls-packages [||] npm access ls-collaborators [ []] npm access edit [] + + Run "npm access help" for more info - adduser npm adduser [--registry=url] [--scope=@orgname] [--always-auth] + adduser npm adduser + + Usage: + npm adduser [--registry=url] [--scope=@orgname] [--always-auth] aliases: login, add-user + + Run "npm adduser help" for more info - audit npm audit [--json] [--production] + audit npm audit + + Usage: + npm audit [--json] [--production] npm audit fix [--force|--package-lock-only|--dry-run|--production|--only=(dev|prod)] + + Run "npm audit help" for more info - bin npm bin [-g] + bin npm bin + + Usage: + npm bin [-g] + + Run "npm bin help" for more info - bugs npm bugs [] + bugs npm bugs + + Usage: + npm bugs [] alias: issues + + Run "npm bugs help" for more info - cache npm cache add + cache npm cache + + Usage: + npm cache add npm cache add npm cache add npm cache add npm cache add @ npm cache clean npm cache verify + + Run "npm cache help" for more info ci npm ci + Usage: + npm ci + aliases: clean-install, ic, install-clean, isntall-clean + + Run "npm ci help" for more info - completion source <(npm completion) + completion npm completion + + npm command completion script. save to ~/.bashrc or ~/.zshrc + + Usage: + npm completion + + Run "npm completion help" for more info - config npm config set = [= ...] + config npm config + + Usage: + npm config set = [= ...] npm config get [ [ ...]] npm config delete [ ...] npm config list [--json] npm config edit - npm set = [= ...] - npm get [ [ ...]] alias: c + + Run "npm config help" for more info dedupe npm dedupe + Usage: + npm dedupe + alias: ddp + + Run "npm dedupe help" for more info - deprecate npm deprecate [@] + deprecate npm deprecate + + Usage: + npm deprecate [@] + + Run "npm deprecate help" for more info - diff npm diff [...] + diff npm diff + + Usage: + npm diff [...] npm diff --diff= [...] npm diff --diff= [--diff=] [...] npm diff --diff= [--diff=] [...] npm diff [--diff-ignore-all-space] [--diff-name-only] [...] [...] + + Run "npm diff help" for more info - dist-tag npm dist-tag add @ [] + dist-tag npm dist-tag + + Usage: + npm dist-tag add @ [] npm dist-tag rm npm dist-tag ls [] alias: dist-tags + + Run "npm dist-tag help" for more info docs npm docs [ [ ...]] alias: home doctor npm doctor + + Usage: + npm doctor + + Run "npm doctor help" for more info - edit npm edit [/...] + edit npm edit + + Usage: + npm edit [/...] + + Run "npm edit help" for more info - exec Run a command from a local or remote npm package. + exec npm exec + Run a command from a local or remote npm package. + + Usage: npm exec -- [@] [args...] npm exec --package=[@] -- [args...] npm exec -c ' [args...]' npm exec --package=foo -c ' [args...]' - npx [@] [args...] - npx -p [@] [args...] - npx -c ' [args...]' - npx -p [@] -c ' [args...]' - Run without --call or positional args to open interactive subshell - - alias: x - common options: - --package= (may be specified multiple times) - -p is a shorthand for --package only when using npx executable - -c --call= (may not be mixed with positional arguments) + + Run "npm exec help" for more info - explain npm explain + explain npm explain + + Usage: + npm explain alias: why + + Run "npm explain help" for more info - explore npm explore [ -- ] + explore npm explore + + Usage: + npm explore [ -- ] + + Run "npm explore help" for more info find-dupes npm find-dupes + + Usage: + npm find-dupes + + Run "npm find-dupes help" for more info fund npm fund - common options: npm fund [--json] [--browser] [--unicode] [[<@scope>/] [--which=] + Usage: + npm fund [--json] [--browser] [--unicode] [[<@scope>/] [--which=] + + Run "npm fund help" for more info - get npm get [ ...] (See \`npm config\`) + get npm get + + Usage: + npm get [ ...] (See \`npm config\`) + + Run "npm get help" for more info - help npm help [] + help npm help + + Usage: + npm help [] alias: hlep + + Run "npm help help" for more info - hook npm hook add [--type=] + hook npm hook + + Usage: + npm hook add [--type=] npm hook ls [pkg] npm hook rm npm hook update + + Run "npm hook help" for more info - init + init npm init + + Usage: npm init [--force|-f|--yes|-y|--scope] npm init <@scope> (same as \`npx <@scope>/create\`) npm init [<@scope>/] (same as \`npx [<@scope>/]create-\`) aliases: create, innit + + Run "npm init help" for more info - install npm install (with no args, in package dir) + install npm install + + Usage: npm install [<@scope>/] npm install [<@scope>/]@ npm install [<@scope>/]@ @@ -340,151 +448,343 @@ All commands: npm install npm install npm install - npm install / + npm install / [--save-prod|--save-dev|--save-optional|--save-peer] [--save-exact] [--no-save] aliases: i, in, ins, inst, insta, instal, isnt, isnta, isntal, add - common options: [--save-prod|--save-dev|--save-optional|--save-peer] [--save-exact] [--no-save] + + Run "npm install help" for more info - install-ci-test npm install-ci-test [args] - Same args as \`npm ci\` + install-ci-test npm install-ci-test + + Usage: + npm install-ci-test alias: cit + + Run "npm install-ci-test help" for more info - install-test npm install-test [args] - Same args as \`npm install\` + install-test npm install-test + + Usage: + npm install-test [<@scope>/] + npm install-test [<@scope>/]@ + npm install-test [<@scope>/]@ + npm install-test [<@scope>/]@ + npm install-test @npm: + npm install-test + npm install-test + npm install-test + npm install-test + npm install-test / [--save-prod|--save-dev|--save-optional|--save-peer] [--save-exact] [--no-save] alias: it + + Run "npm install-test help" for more info - link npm link (in package dir) + link npm link + + Usage: + npm link (in package dir) npm link [<@scope>/][@] alias: ln + + Run "npm link help" for more info - ll npm ll [[<@scope>/] ...] + ll npm ll + + Usage: + npm ll [[<@scope>/] ...] alias: la + + Run "npm ll help" for more info - login npm adduser [--registry=url] [--scope=@orgname] [--always-auth] + login npm adduser + + Usage: + npm adduser [--registry=url] [--scope=@orgname] [--always-auth] aliases: login, add-user + + Run "npm adduser help" for more info - logout npm logout [--registry=] [--scope=<@scope>] + logout npm logout + + Usage: + npm logout [--registry=] [--scope=<@scope>] + + Run "npm logout help" for more info - ls npm ls [[<@scope>/] ...] + ls npm ls + + Usage: + npm ls npm ls [[<@scope>/] ...] alias: list + + Run "npm ls help" for more info - org npm org set orgname username [developer | admin | owner] + org npm org + + Usage: + npm org set orgname username [developer | admin | owner] npm org rm orgname username npm org ls orgname [] alias: ogr + + Run "npm org help" for more info - outdated npm outdated [[<@scope>/] ...] + outdated npm outdated + + Usage: + npm outdated [[<@scope>/] ...] + + Run "npm outdated help" for more info - owner npm owner add [<@scope>/] + owner npm owner + + Usage: + npm owner add [<@scope>/] npm owner rm [<@scope>/] npm owner ls [<@scope>/] alias: author + + Run "npm owner help" for more info - pack npm pack [[<@scope>/]...] [--dry-run] + pack npm pack + + Usage: + npm pack [[<@scope>/]...] [--dry-run] + + Run "npm pack help" for more info ping npm ping + ping registry + + Usage: + npm ping + + Run "npm ping help" for more info - prefix npm prefix [-g] - - profile npm profile enable-2fa [auth-only|auth-and-writes] + prefix npm prefix + Usage: + npm prefix [-g] - common options: npm profile disable-2fa + Run "npm prefix help" for more info + + profile npm profile + + Usage: + npm profile enable-2fa [auth-only|auth-and-writes] + npm profile disable-2fa + npm profile get [] + npm profile set + Run "npm profile help" for more info - prune npm prune [[<@scope>/]...] [--production] + prune npm prune + + Usage: + npm prune [[<@scope>/]...] [--production] + + Run "npm prune help" for more info - publish npm publish [] [--tag ] [--access ] [--dry-run] + publish npm publish - Publishes '.' if no argument supplied - Sets tag \`latest\` if no --tag specified + Usage: + npm publish [] [--tag ] [--access ] [--dry-run] + + Run "npm publish help" for more info - rebuild npm rebuild [[<@scope>/][@] ...] + rebuild npm rebuild + + Usage: + npm rebuild [[<@scope>/][@] ...] alias: rb + + Run "npm rebuild help" for more info - repo npm repo [ [ ...]] + repo npm repo + + Usage: + npm repo [ [ ...]] + + Run "npm repo help" for more info - restart npm restart [-- ] + restart npm restart + + Usage: + npm restart [-- ] + + Run "npm restart help" for more info - root npm root [-g] + root npm root + + Usage: + npm root [-g] + + Run "npm root help" for more info - run-script npm run-script [-- ] + run-script npm run-script + + Usage: + npm run-script [-- ] aliases: run, rum, urn + + Run "npm run-script help" for more info - search npm search [-l|--long] [--json] [--parseable] [--no-description] [search terms ...] + search npm search + + Usage: + npm search [-l|--long] [--json] [--parseable] [--no-description] [search terms ...] aliases: s, se, find + + Run "npm search help" for more info - set npm set = [= ...] (See \`npm config\`) + set npm set + + Usage: + npm set = [= ...] (See \`npm config\`) + + Run "npm set help" for more info - set-script npm set-script [