Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGar <gar+gh@danger.computer>2021-03-04 07:26:33 +0300
committerGar <gar+gh@danger.computer>2021-03-09 22:10:06 +0300
commit9fe0df5b5d7606e5841288d9931be6c04767c9ca (patch)
tree50b916523fe4a5ebab6010b137cc931cc2a9ce70 /lib
parent85a8694dd9b4a924a474ba75261914511a216868 (diff)
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
Diffstat (limited to 'lib')
-rw-r--r--lib/access.js46
-rw-r--r--lib/adduser.js16
-rw-r--r--lib/audit.js21
-rw-r--r--lib/base-command.js38
-rw-r--r--lib/bin.js13
-rw-r--r--lib/bugs.js13
-rw-r--r--lib/cache.js30
-rw-r--r--lib/ci.js12
-rw-r--r--lib/completion.js13
-rw-r--r--lib/config.js33
-rw-r--r--lib/dedupe.js11
-rw-r--r--lib/deprecate.js23
-rw-r--r--lib/diff.js27
-rw-r--r--lib/dist-tag.js23
-rw-r--r--lib/doctor.js12
-rw-r--r--lib/edit.js13
-rw-r--r--lib/exec.js42
-rw-r--r--lib/explain.js13
-rw-r--r--lib/explore.js13
-rw-r--r--lib/find-dupes.js12
-rw-r--r--lib/fund.js18
-rw-r--r--lib/get.js16
-rw-r--r--lib/help-search.js14
-rw-r--r--lib/help.js13
-rw-r--r--lib/hook.js22
-rw-r--r--lib/init.js22
-rw-r--r--lib/install-ci-test.js17
-rw-r--r--lib/install-test.js21
-rw-r--r--lib/install.js38
-rw-r--r--lib/link.js20
-rw-r--r--lib/ll.js13
-rw-r--r--lib/logout.js16
-rw-r--r--lib/ls.js16
-rw-r--r--lib/org.js23
-rw-r--r--lib/outdated.js15
-rw-r--r--lib/owner.js39
-rw-r--r--lib/pack.js13
-rw-r--r--lib/ping.js13
-rw-r--r--lib/prefix.js13
-rw-r--r--lib/profile.js25
-rw-r--r--lib/prune.js15
-rw-r--r--lib/publish.js19
-rw-r--r--lib/rebuild.js13
-rw-r--r--lib/repo.js13
-rw-r--r--lib/restart.js5
-rw-r--r--lib/root.js14
-rw-r--r--lib/run-script.js16
-rw-r--r--lib/search.js16
-rw-r--r--lib/set-script.js13
-rw-r--r--lib/set.js17
-rw-r--r--lib/shrinkwrap.js13
-rw-r--r--lib/star.js18
-rw-r--r--lib/stars.js13
-rw-r--r--lib/start.js5
-rw-r--r--lib/stop.js5
-rw-r--r--lib/team.js27
-rw-r--r--lib/test.js5
-rw-r--r--lib/token.js28
-rw-r--r--lib/uninstall.js17
-rw-r--r--lib/unpublish.js14
-rw-r--r--lib/unstar.js5
-rw-r--r--lib/update.js16
-rw-r--r--lib/utils/lifecycle-cmd.js15
-rw-r--r--lib/version.js21
-rw-r--r--lib/view.js17
-rw-r--r--lib/whoami.js22
66 files changed, 575 insertions, 618 deletions
diff --git a/lib/access.js b/lib/access.js
index 3bc211190..0df36beea 100644
--- a/lib/access.js
+++ b/lib/access.js
@@ -4,8 +4,8 @@ const libaccess = require('libnpmaccess')
const readPackageJson = require('read-package-json-fast')
const otplease = require('./utils/otplease.js')
-const usageUtil = require('./utils/usage.js')
const getIdentity = require('./utils/get-identity.js')
+const BaseCommand = require('./base-command.js')
const subcommands = [
'public',
@@ -19,24 +19,23 @@ const subcommands = [
'2fa-not-required',
]
-class Access {
- constructor (npm) {
- this.npm = npm
+class Access extends BaseCommand {
+ static get name () {
+ return 'access'
}
- get usage () {
- return usageUtil(
- 'access',
- 'npm access public [<package>]\n' +
- 'npm access restricted [<package>]\n' +
- 'npm access grant <read-only|read-write> <scope:team> [<package>]\n' +
- 'npm access revoke <scope:team> [<package>]\n' +
- 'npm access 2fa-required [<package>]\n' +
- 'npm access 2fa-not-required [<package>]\n' +
- 'npm access ls-packages [<user>|<scope>|<scope:team>]\n' +
- 'npm access ls-collaborators [<package> [<user>]]\n' +
- 'npm access edit [<package>]'
- )
+ static get usage () {
+ return [
+ 'public [<package>]',
+ 'restricted [<package>]',
+ 'grant <read-only|read-write> <scope:team> [<package>]',
+ 'revoke <scope:team> [<package>]',
+ '2fa-required [<package>]',
+ '2fa-not-required [<package>]',
+ 'ls-packages [<user>|<scope>|<scope:team>]',
+ 'ls-collaborators [<package> [<user>]]',
+ 'edit [<package>]',
+ ]
}
async completion (opts) {
@@ -66,12 +65,7 @@ class Access {
}
exec (args, cb) {
- this.access(args)
- .then(x => cb(null, x))
- .catch(err => err.code === 'EUSAGE'
- ? cb(err.message)
- : cb(err)
- )
+ this.access(args).then(() => cb()).catch(cb)
}
async access ([cmd, ...args]) {
@@ -202,12 +196,6 @@ class Access {
return name
}
}
-
- usageError (msg) {
- return Object.assign(new Error(`\nUsage: ${msg}\n\n` + this.usage), {
- code: 'EUSAGE',
- })
- }
}
module.exports = Access
diff --git a/lib/adduser.js b/lib/adduser.js
index 45d602fd2..da318a1f3 100644
--- a/lib/adduser.js
+++ b/lib/adduser.js
@@ -1,6 +1,6 @@
const log = require('npmlog')
-const usageUtil = require('./utils/usage.js')
const replaceInfo = require('./utils/replace-info.js')
+const BaseCommand = require('./base-command.js')
const authTypes = {
legacy: require('./auth/legacy.js'),
oauth: require('./auth/oauth.js'),
@@ -8,17 +8,13 @@ const authTypes = {
sso: require('./auth/sso.js'),
}
-class AddUser {
- constructor (npm) {
- this.npm = npm
+class AddUser extends BaseCommand {
+ static get name () {
+ return 'adduser'
}
- /* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil(
- 'adduser',
- 'npm adduser [--registry=url] [--scope=@orgname] [--always-auth]'
- )
+ static get usage () {
+ return ['[--registry=url] [--scope=@orgname] [--always-auth]']
}
exec (args, cb) {
diff --git a/lib/audit.js b/lib/audit.js
index b8c85605d..6e64987b6 100644
--- a/lib/audit.js
+++ b/lib/audit.js
@@ -2,21 +2,20 @@ const Arborist = require('@npmcli/arborist')
const auditReport = require('npm-audit-report')
const reifyFinish = require('./utils/reify-finish.js')
const auditError = require('./utils/audit-error.js')
-const usageUtil = require('./utils/usage.js')
+const BaseCommand = require('./base-command.js')
-class Audit {
- constructor (npm) {
- this.npm = npm
+class Audit extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'audit'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil(
- 'audit',
- 'npm audit [--json] [--production]' +
- '\nnpm audit fix ' +
- '[--force|--package-lock-only|--dry-run|--production|--only=(dev|prod)]'
- )
+ static get usage () {
+ return [
+ '[--json] [--production]',
+ 'fix [--force|--package-lock-only|--dry-run|--production|--only=(dev|prod)]',
+ ]
}
async completion (opts) {
diff --git a/lib/base-command.js b/lib/base-command.js
new file mode 100644
index 000000000..c31e4a4d7
--- /dev/null
+++ b/lib/base-command.js
@@ -0,0 +1,38 @@
+// Base class for npm.commands[cmd]
+const usageUtil = require('./utils/usage.js')
+
+class BaseCommand {
+ constructor (npm) {
+ this.npm = npm
+ }
+
+ get usage () {
+ let usage = `npm ${this.constructor.name}\n\n`
+ if (this.constructor.description)
+ usage = `${usage}${this.constructor.description}\n\n`
+
+ usage = `${usage}Usage:\n`
+ if (!this.constructor.usage)
+ usage = `${usage}npm ${this.constructor.name}`
+ else
+ usage = `${usage}${this.constructor.usage.map(u => `npm ${this.constructor.name} ${u}`).join('\n')}`
+
+ // Mostly this just appends aliases, this could be more clear
+ usage = usageUtil(this.constructor.name, usage)
+ usage = `${usage}\n\nRun "npm ${this.constructor.name} help" for more info`
+ return usage
+ }
+
+ usageError (msg) {
+ if (!msg) {
+ return Object.assign(new Error(`\nUsage: ${this.usage}`), {
+ code: 'EUSAGE',
+ })
+ }
+
+ return Object.assign(new Error(`\nUsage: ${msg}\n\n${this.usage}`), {
+ code: 'EUSAGE',
+ })
+ }
+}
+module.exports = BaseCommand
diff --git a/lib/bin.js b/lib/bin.js
index f540cc57c..1450fb539 100644
--- a/lib/bin.js
+++ b/lib/bin.js
@@ -1,14 +1,13 @@
const envPath = require('./utils/path.js')
-const usageUtil = require('./utils/usage.js')
+const BaseCommand = require('./base-command.js')
-class Bin {
- constructor (npm) {
- this.npm = npm
+class Bin extends BaseCommand {
+ static get name () {
+ return 'bin'
}
- /* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('bin', 'npm bin [-g]')
+ static get usage () {
+ return ['[-g]']
}
exec (args, cb) {
diff --git a/lib/bugs.js b/lib/bugs.js
index fb0d7c927..1814dd7bc 100644
--- a/lib/bugs.js
+++ b/lib/bugs.js
@@ -1,17 +1,16 @@
const log = require('npmlog')
const pacote = require('pacote')
const openUrl = require('./utils/open-url.js')
-const usageUtil = require('./utils/usage.js')
const hostedFromMani = require('./utils/hosted-git-info-from-manifest.js')
+const BaseCommand = require('./base-command.js')
-class Bugs {
- constructor (npm) {
- this.npm = npm
+class Bugs extends BaseCommand {
+ static get name () {
+ return 'bugs'
}
- /* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('bugs', 'npm bugs [<pkgname>]')
+ static get usage () {
+ return ['[<pkgname>]']
}
exec (args, cb) {
diff --git a/lib/cache.js b/lib/cache.js
index 3ca99fd25..80a5c68eb 100644
--- a/lib/cache.js
+++ b/lib/cache.js
@@ -4,23 +4,25 @@ const log = require('npmlog')
const pacote = require('pacote')
const path = require('path')
const rimraf = promisify(require('rimraf'))
+const BaseCommand = require('./base-command.js')
-const usageUtil = require('./utils/usage.js')
-class Cache {
- constructor (npm) {
- this.npm = npm
+class Cache extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'cache'
}
- get usage () {
- return usageUtil('cache',
- 'npm cache add <tarball file>' +
- '\nnpm cache add <folder>' +
- '\nnpm cache add <tarball url>' +
- '\nnpm cache add <git url>' +
- '\nnpm cache add <name>@<version>' +
- '\nnpm cache clean' +
- '\nnpm cache verify'
- )
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return [
+ 'add <tarball file>',
+ 'add <folder>',
+ 'add <tarball url>',
+ 'add <git url>',
+ 'add <name>@<version>',
+ 'clean',
+ 'verify',
+ ]
}
async completion (opts) {
diff --git a/lib/ci.js b/lib/ci.js
index 03a91a604..3ea199376 100644
--- a/lib/ci.js
+++ b/lib/ci.js
@@ -7,7 +7,6 @@ const fs = require('fs')
const readdir = util.promisify(fs.readdir)
const log = require('npmlog')
-const usageUtil = require('./utils/usage.js')
const removeNodeModules = async where => {
const rimrafOpts = { glob: false }
@@ -18,15 +17,12 @@ const removeNodeModules = async where => {
await Promise.all(entries.map(f => rimraf(`${path}/${f}`, rimrafOpts)))
process.emit('timeEnd', 'npm-ci:rm')
}
+const BaseCommand = require('./base-command.js')
-class CI {
- constructor (npm) {
- this.npm = npm
- }
-
+class CI extends BaseCommand {
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('ci', 'npm ci')
+ static get name () {
+ return 'ci'
}
exec (args, cb) {
diff --git a/lib/completion.js b/lib/completion.js
index 5baf17665..3ee68cdac 100644
--- a/lib/completion.js
+++ b/lib/completion.js
@@ -41,17 +41,18 @@ const allConfs = configNames.concat(shorthandNames)
const isWindowsShell = require('./utils/is-windows-shell.js')
const fileExists = require('./utils/file-exists.js')
-const usageUtil = require('./utils/usage.js')
const { promisify } = require('util')
+const BaseCommand = require('./base-command.js')
-class Completion {
- constructor (npm) {
- this.npm = npm
+class Completion extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'completion'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('completion', 'source <(npm completion)')
+ static get description () {
+ return 'npm command completion script. save to ~/.bashrc or ~/.zshrc'
}
// completion for the completion command
diff --git a/lib/config.js b/lib/config.js
index 7009f4601..c29253e43 100644
--- a/lib/config.js
+++ b/lib/config.js
@@ -1,5 +1,4 @@
const { defaults, types } = require('./utils/config.js')
-const usageUtil = require('./utils/usage.js')
const mkdirp = require('mkdirp-infer-owner')
const { dirname } = require('path')
@@ -28,22 +27,22 @@ const keyValues = args => {
const publicVar = k => !/^(\/\/[^:]+:)?_/.test(k)
-class Config {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Config extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'config'
}
- get usage () {
- return usageUtil(
- 'config',
- 'npm config set <key>=<value> [<key>=<value> ...]' +
- '\nnpm config get [<key> [<key> ...]]' +
- '\nnpm config delete <key> [<key> ...]' +
- '\nnpm config list [--json]' +
- '\nnpm config edit' +
- '\nnpm set <key>=<value> [<key>=<value> ...]' +
- '\nnpm get [<key> [<key> ...]]'
- )
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return [
+ 'set <key>=<value> [<key>=<value> ...]',
+ 'get [<key> [<key> ...]]',
+ 'delete <key> [<key> ...]',
+ 'list [--json]',
+ 'edit',
+ ]
}
async completion (opts) {
@@ -253,10 +252,6 @@ ${defData}
}
this.npm.output(JSON.stringify(publicConf, null, 2))
}
-
- usageError () {
- return Object.assign(new Error(this.usage), { code: 'EUSAGE' })
- }
}
module.exports = Config
diff --git a/lib/dedupe.js b/lib/dedupe.js
index 59978895e..50a56211f 100644
--- a/lib/dedupe.js
+++ b/lib/dedupe.js
@@ -1,16 +1,13 @@
// dedupe duplicated packages, or find them in the tree
const Arborist = require('@npmcli/arborist')
-const usageUtil = require('./utils/usage.js')
const reifyFinish = require('./utils/reify-finish.js')
-class Dedupe {
- constructor (npm) {
- this.npm = npm
- }
+const BaseCommand = require('./base-command.js')
+class Dedupe extends BaseCommand {
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('dedupe', 'npm dedupe')
+ static get name () {
+ return 'dedupe'
}
exec (args, cb) {
diff --git a/lib/deprecate.js b/lib/deprecate.js
index 48f27ab6c..a0c67f805 100644
--- a/lib/deprecate.js
+++ b/lib/deprecate.js
@@ -4,18 +4,17 @@ const npa = require('npm-package-arg')
const semver = require('semver')
const getIdentity = require('./utils/get-identity.js')
const libaccess = require('libnpmaccess')
-const usageUtil = require('./utils/usage.js')
+const BaseCommand = require('./base-command.js')
-class Deprecate {
- constructor (npm) {
- this.npm = npm
+class Deprecate extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'deprecate'
}
- get usage () {
- return usageUtil(
- 'deprecate',
- 'npm deprecate <pkg>[@<version>] <message>'
- )
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return ['<pkg>[@<version>] <message>']
}
async completion (opts) {
@@ -71,12 +70,6 @@ class Deprecate {
ignoreBody: true,
}))
}
-
- usageError () {
- return Object.assign(new Error(`\nUsage: ${this.usage}`), {
- code: 'EUSAGE',
- })
- }
}
module.exports = Deprecate
diff --git a/lib/diff.js b/lib/diff.js
index ed36a3067..0e322ec64 100644
--- a/lib/diff.js
+++ b/lib/diff.js
@@ -8,23 +8,24 @@ const npmlog = require('npmlog')
const pacote = require('pacote')
const pickManifest = require('npm-pick-manifest')
-const usageUtil = require('./utils/usage.js')
const readLocalPkg = require('./utils/read-local-package.js')
+const BaseCommand = require('./base-command.js')
-class Diff {
- constructor (npm) {
- this.npm = npm
+class Diff extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'diff'
}
- get usage () {
- return usageUtil(
- 'diff',
- 'npm diff [...<paths>]' +
- '\nnpm diff --diff=<pkg-name> [...<paths>]' +
- '\nnpm diff --diff=<version-a> [--diff=<version-b>] [...<paths>]' +
- '\nnpm diff --diff=<spec-a> [--diff=<spec-b>] [...<paths>]' +
- '\nnpm diff [--diff-ignore-all-space] [--diff-name-only] [...<paths>] [...<paths>]'
- )
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return [
+ '[...<paths>]',
+ '--diff=<pkg-name> [...<paths>]',
+ '--diff=<version-a> [--diff=<version-b>] [...<paths>]',
+ '--diff=<spec-a> [--diff=<spec-b>] [...<paths>]',
+ '[--diff-ignore-all-space] [--diff-name-only] [...<paths>] [...<paths>]',
+ ]
}
get where () {
diff --git a/lib/dist-tag.js b/lib/dist-tag.js
index 4b7e26020..cdc95ac6f 100644
--- a/lib/dist-tag.js
+++ b/lib/dist-tag.js
@@ -5,20 +5,21 @@ const semver = require('semver')
const otplease = require('./utils/otplease.js')
const readLocalPkgName = require('./utils/read-local-package.js')
-const usageUtil = require('./utils/usage.js')
+const BaseCommand = require('./base-command.js')
-class DistTag {
- constructor (npm) {
- this.npm = npm
+class DistTag extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'dist-tag'
}
- get usage () {
- return usageUtil(
- 'dist-tag',
- 'npm dist-tag add <pkg>@<version> [<tag>]' +
- '\nnpm dist-tag rm <pkg> <tag>' +
- '\nnpm dist-tag ls [<pkg>]'
- )
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return [
+ 'add <pkg>@<version> [<tag>]',
+ 'rm <pkg> <tag>',
+ 'ls [<pkg>]',
+ ]
}
async completion (opts) {
diff --git a/lib/doctor.js b/lib/doctor.js
index 63619d0cf..fbe447141 100644
--- a/lib/doctor.js
+++ b/lib/doctor.js
@@ -11,7 +11,6 @@ const { promisify } = require('util')
const ansiTrim = require('./utils/ansi-trim.js')
const isWindows = require('./utils/is-windows.js')
const ping = require('./utils/ping.js')
-const usageUtil = require('./utils/usage.js')
const { defaults: { registry: defaultRegistry } } = require('./utils/config.js')
const lstat = promisify(fs.lstat)
const readdir = promisify(fs.readdir)
@@ -31,14 +30,11 @@ const maskLabel = mask => {
return label.join(', ')
}
-class Doctor {
- constructor (npm) {
- this.npm = npm
- }
-
+const BaseCommand = require('./base-command.js')
+class Doctor extends BaseCommand {
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('doctor', 'npm doctor')
+ static get name () {
+ return 'doctor'
}
exec (args, cb) {
diff --git a/lib/edit.js b/lib/edit.js
index a7dbb3820..1dbe8e4c1 100644
--- a/lib/edit.js
+++ b/lib/edit.js
@@ -4,18 +4,19 @@
const { resolve } = require('path')
const fs = require('graceful-fs')
const { spawn } = require('child_process')
-const usageUtil = require('./utils/usage.js')
const splitPackageNames = require('./utils/split-package-names.js')
const completion = require('./utils/completion/installed-shallow.js')
+const BaseCommand = require('./base-command.js')
-class Edit {
- constructor (npm) {
- this.npm = npm
+class Edit extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'edit'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('edit', 'npm edit <pkg>[/<subpkg>...]')
+ static get usage () {
+ return ['<pkg>[/<subpkg>...]']
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
diff --git a/lib/exec.js b/lib/exec.js
index 69c3cfe75..b2443b17a 100644
--- a/lib/exec.js
+++ b/lib/exec.js
@@ -1,4 +1,3 @@
-const usageUtil = require('./utils/usage.js')
const { promisify } = require('util')
const read = promisify(require('read'))
const mkdirp = require('mkdirp-infer-owner')
@@ -12,6 +11,7 @@ const pacote = require('pacote')
const npa = require('npm-package-arg')
const fileExists = require('./utils/file-exists.js')
const PATH = require('./utils/path.js')
+const BaseCommand = require('./base-command.js')
// it's like this:
//
@@ -38,31 +38,25 @@ const PATH = require('./utils/path.js')
// runScript({ pkg, event: 'npx', ... })
// process.env.npm_lifecycle_event = 'npx'
-class Exec {
- constructor (npm) {
- this.npm = npm
+class Exec extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'exec'
}
- get usage () {
- return usageUtil('exec',
- 'Run a command from a local or remote npm package.\n\n' +
-
- 'npm exec -- <pkg>[@<version>] [args...]\n' +
- 'npm exec --package=<pkg>[@<version>] -- <cmd> [args...]\n' +
- 'npm exec -c \'<cmd> [args...]\'\n' +
- 'npm exec --package=foo -c \'<cmd> [args...]\'\n' +
- '\n' +
- 'npx <pkg>[@<specifier>] [args...]\n' +
- 'npx -p <pkg>[@<specifier>] <cmd> [args...]\n' +
- 'npx -c \'<cmd> [args...]\'\n' +
- 'npx -p <pkg>[@<specifier>] -c \'<cmd> [args...]\'' +
- '\n' +
- 'Run without --call or positional args to open interactive subshell\n',
-
- '\n--package=<pkg> (may be specified multiple times)\n' +
- '-p is a shorthand for --package only when using npx executable\n' +
- '-c <cmd> --call=<cmd> (may not be mixed with positional arguments)'
- )
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get description () {
+ return 'Run a command from a local or remote npm package.'
+ }
+
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return [
+ '-- <pkg>[@<version>] [args...]',
+ '--package=<pkg>[@<version>] -- <cmd> [args...]',
+ '-c \'<cmd> [args...]\'',
+ '--package=foo -c \'<cmd> [args...]\'',
+ ]
}
exec (args, cb) {
diff --git a/lib/explain.js b/lib/explain.js
index f46d3b507..6af761186 100644
--- a/lib/explain.js
+++ b/lib/explain.js
@@ -1,4 +1,3 @@
-const usageUtil = require('./utils/usage.js')
const { explainNode } = require('./utils/explain-dep.js')
const completion = require('./utils/completion/installed-deep.js')
const Arborist = require('@npmcli/arborist')
@@ -6,15 +5,17 @@ const npa = require('npm-package-arg')
const semver = require('semver')
const { relative, resolve } = require('path')
const validName = require('validate-npm-package-name')
+const BaseCommand = require('./base-command.js')
-class Explain {
- constructor (npm) {
- this.npm = npm
+class Explain extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'explain'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('explain', 'npm explain <folder | specifier>')
+ static get usage () {
+ return ['<folder | specifier>']
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
diff --git a/lib/explore.js b/lib/explore.js
index e09e86740..34f6d1079 100644
--- a/lib/explore.js
+++ b/lib/explore.js
@@ -5,16 +5,17 @@ const rpj = require('read-package-json-fast')
const runScript = require('@npmcli/run-script')
const { join, resolve, relative } = require('path')
const completion = require('./utils/completion/installed-shallow.js')
-const usageUtil = require('./utils/usage.js')
+const BaseCommand = require('./base-command.js')
-class Explore {
- constructor (npm) {
- this.npm = npm
+class Explore extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'explore'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('explore', 'npm explore <pkg> [ -- <command>]')
+ static get usage () {
+ return ['<pkg> [ -- <command>]']
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
diff --git a/lib/find-dupes.js b/lib/find-dupes.js
index 5061be9cc..ecb945f47 100644
--- a/lib/find-dupes.js
+++ b/lib/find-dupes.js
@@ -1,14 +1,10 @@
// dedupe duplicated packages, or find them in the tree
-const usageUtil = require('./utils/usage.js')
-
-class FindDupes {
- constructor (npm) {
- this.npm = npm
- }
+const BaseCommand = require('./base-command.js')
+class FindDupes extends BaseCommand {
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('find-dupes', 'npm find-dupes')
+ static get name () {
+ return 'find-dupes'
}
exec (args, cb) {
diff --git a/lib/fund.js b/lib/fund.js
index 826c3170e..a723c62d2 100644
--- a/lib/fund.js
+++ b/lib/fund.js
@@ -13,25 +13,23 @@ const {
const completion = require('./utils/completion/installed-deep.js')
const openUrl = require('./utils/open-url.js')
-const usageUtil = require('./utils/usage.js')
const getPrintableName = ({ name, version }) => {
const printableVersion = version ? `@${version}` : ''
return `${name}${printableVersion}`
}
-class Fund {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+
+class Fund extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'fund'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil(
- 'fund',
- 'npm fund',
- 'npm fund [--json] [--browser] [--unicode] [[<@scope>/]<pkg> [--which=<fundingSourceNumber>]'
- )
+ static get usage () {
+ return ['[--json] [--browser] [--unicode] [[<@scope>/]<pkg> [--which=<fundingSourceNumber>]']
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
diff --git a/lib/get.js b/lib/get.js
index a5b2f5514..a5d58accc 100644
--- a/lib/get.js
+++ b/lib/get.js
@@ -1,16 +1,14 @@
-const usageUtil = require('./utils/usage.js')
+const BaseCommand = require('./base-command.js')
-class Get {
- constructor (npm) {
- this.npm = npm
+class Get extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'get'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil(
- 'get',
- 'npm get [<key> ...] (See `npm config`)'
- )
+ static get usage () {
+ return ['[<key> ...] (See `npm config`)']
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
diff --git a/lib/help-search.js b/lib/help-search.js
index 9648e3b14..4e727c3e7 100644
--- a/lib/help-search.js
+++ b/lib/help-search.js
@@ -1,21 +1,23 @@
const fs = require('fs')
const path = require('path')
const color = require('ansicolors')
-const usageUtil = require('./utils/usage.js')
const npmUsage = require('./utils/npm-usage.js')
const { promisify } = require('util')
const glob = promisify(require('glob'))
const readFile = promisify(fs.readFile)
const didYouMean = require('./utils/did-you-mean.js')
const { cmdList } = require('./utils/cmd-list.js')
+const BaseCommand = require('./base-command.js')
-class HelpSearch {
- constructor (npm) {
- this.npm = npm
+class HelpSearch extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'help-search'
}
- get usage () {
- return usageUtil('help-search', 'npm help-search <text>')
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return ['<text>']
}
exec (args, cb) {
diff --git a/lib/help.js b/lib/help.js
index ef7e3bfd0..93abf878b 100644
--- a/lib/help.js
+++ b/lib/help.js
@@ -5,16 +5,17 @@ const log = require('npmlog')
const openUrl = require('./utils/open-url.js')
const glob = require('glob')
-const usage = require('./utils/usage.js')
+const BaseCommand = require('./base-command.js')
-class Help {
- constructor (npm) {
- this.npm = npm
+class Help extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'help'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usage('help', 'npm help <term> [<terms..>]')
+ static get usage () {
+ return ['<term> [<terms..>]']
}
async completion (opts) {
diff --git a/lib/hook.js b/lib/hook.js
index a6f04d653..6cda3504f 100644
--- a/lib/hook.js
+++ b/lib/hook.js
@@ -2,20 +2,20 @@ const hookApi = require('libnpmhook')
const otplease = require('./utils/otplease.js')
const relativeDate = require('tiny-relative-date')
const Table = require('cli-table3')
-const usageUtil = require('./utils/usage.js')
-class Hook {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Hook extends BaseCommand {
+ static get name () {
+ return 'hook'
}
- get usage () {
- return usageUtil('hook', [
- 'npm hook add <pkg> <url> <secret> [--type=<type>]',
- 'npm hook ls [pkg]',
- 'npm hook rm <id>',
- 'npm hook update <id> <url> <secret>',
- ].join('\n'))
+ static get usage () {
+ return [
+ 'add <pkg> <url> <secret> [--type=<type>]',
+ 'ls [pkg]',
+ 'rm <id>',
+ 'update <id> <url> <secret>',
+ ]
}
exec (args, cb) {
diff --git a/lib/init.js b/lib/init.js
index 3f9abbcdd..42b02dfdc 100644
--- a/lib/init.js
+++ b/lib/init.js
@@ -1,21 +1,21 @@
const initJson = require('init-package-json')
const npa = require('npm-package-arg')
-const usageUtil = require('./utils/usage.js')
+const BaseCommand = require('./base-command.js')
-class Init {
- constructor (npm) {
- this.npm = npm
+class Init extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'init'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil(
- 'init',
- '\nnpm init [--force|-f|--yes|-y|--scope]' +
- '\nnpm init <@scope> (same as `npx <@scope>/create`)' +
- '\nnpm init [<@scope>/]<name> (same as `npx [<@scope>/]create-<name>`)'
- )
+ static get usage () {
+ return [
+ '[--force|-f|--yes|-y|--scope]',
+ '<@scope> (same as `npx <@scope>/create`)',
+ '[<@scope>/]<name> (same as `npx [<@scope>/]create-<name>`)',
+ ]
}
exec (args, cb) {
diff --git a/lib/install-ci-test.js b/lib/install-ci-test.js
index d1740999d..c52b5c9e8 100644
--- a/lib/install-ci-test.js
+++ b/lib/install-ci-test.js
@@ -1,19 +1,12 @@
// npm install-ci-test
// Runs `npm ci` and then runs `npm test`
-const usageUtil = require('./utils/usage.js')
+const CI = require('./ci.js')
-class InstallCITest {
- constructor (npm) {
- this.npm = npm
- }
-
- get usage () {
- return usageUtil(
- 'install-ci-test',
- 'npm install-ci-test [args]' +
- '\nSame args as `npm ci`'
- )
+class InstallCITest extends CI {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'install-ci-test'
}
exec (args, cb) {
diff --git a/lib/install-test.js b/lib/install-test.js
index 487f8da00..76c6f367d 100644
--- a/lib/install-test.js
+++ b/lib/install-test.js
@@ -1,23 +1,12 @@
// npm install-test
// Runs `npm install` and then runs `npm test`
-const usageUtil = require('./utils/usage.js')
+const Install = require('./install.js')
-class InstallTest {
- constructor (npm) {
- this.npm = npm
- }
-
- get usage () {
- return usageUtil(
- 'install-test',
- 'npm install-test [args]' +
- '\nSame args as `npm install`'
- )
- }
-
- async completion (opts) {
- return this.npm.commands.install.completion(opts)
+class InstallTest extends Install {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'install-test'
}
exec (args, cb) {
diff --git a/lib/install.js b/lib/install.js
index d7fd384d5..8df63a219 100644
--- a/lib/install.js
+++ b/lib/install.js
@@ -3,35 +3,33 @@
const fs = require('fs')
const util = require('util')
const readdir = util.promisify(fs.readdir)
-const usageUtil = require('./utils/usage.js')
const reifyFinish = require('./utils/reify-finish.js')
const log = require('npmlog')
const { resolve, join } = require('path')
const Arborist = require('@npmcli/arborist')
const runScript = require('@npmcli/run-script')
-class Install {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Install extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'install'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil(
- 'install',
- 'npm install (with no args, in package dir)' +
- '\nnpm install [<@scope>/]<pkg>' +
- '\nnpm install [<@scope>/]<pkg>@<tag>' +
- '\nnpm install [<@scope>/]<pkg>@<version>' +
- '\nnpm install [<@scope>/]<pkg>@<version range>' +
- '\nnpm install <alias>@npm:<name>' +
- '\nnpm install <folder>' +
- '\nnpm install <tarball file>' +
- '\nnpm install <tarball url>' +
- '\nnpm install <git:// url>' +
- '\nnpm install <github username>/<github project>',
- '[--save-prod|--save-dev|--save-optional|--save-peer] [--save-exact] [--no-save]'
- )
+ static get usage () {
+ return [
+ '[<@scope>/]<pkg>',
+ '[<@scope>/]<pkg>@<tag>',
+ '[<@scope>/]<pkg>@<version>',
+ '[<@scope>/]<pkg>@<version range>',
+ '<alias>@npm:<name>',
+ '<folder>',
+ '<tarball file>',
+ '<tarball url>',
+ '<git:// url>',
+ '<github username>/<github project> [--save-prod|--save-dev|--save-optional|--save-peer] [--save-exact] [--no-save]',
+ ]
}
async completion (opts) {
diff --git a/lib/link.js b/lib/link.js
index 6d5e20710..66f83d9f5 100644
--- a/lib/link.js
+++ b/lib/link.js
@@ -8,21 +8,21 @@ const npa = require('npm-package-arg')
const rpj = require('read-package-json-fast')
const semver = require('semver')
-const usageUtil = require('./utils/usage.js')
const reifyFinish = require('./utils/reify-finish.js')
-class Link {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Link extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'link'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil(
- 'link',
- 'npm link (in package dir)' +
- '\nnpm link [<@scope>/]<pkg>[@<version>]'
- )
+ static get usage () {
+ return [
+ '(in package dir)',
+ '[<@scope>/]<pkg>[@<version>]',
+ ]
}
async completion (opts) {
diff --git a/lib/ll.js b/lib/ll.js
index 7915f5d27..3e3428a7f 100644
--- a/lib/ll.js
+++ b/lib/ll.js
@@ -1,13 +1,14 @@
const LS = require('./ls.js')
-const usageUtil = require('./utils/usage.js')
class LL extends LS {
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil(
- 'll',
- 'npm ll [[<@scope>/]<pkg> ...]'
- )
+ static get name () {
+ return 'll'
+ }
+
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return ['[[<@scope>/]<pkg> ...]']
}
exec (args, cb) {
diff --git a/lib/logout.js b/lib/logout.js
index 9fb1eab21..b3f64f671 100644
--- a/lib/logout.js
+++ b/lib/logout.js
@@ -1,19 +1,17 @@
const log = require('npmlog')
const getAuth = require('npm-registry-fetch/auth.js')
const npmFetch = require('npm-registry-fetch')
-const usageUtil = require('./utils/usage.js')
+const BaseCommand = require('./base-command.js')
-class Logout {
- constructor (npm) {
- this.npm = npm
+class Logout extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'logout'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil(
- 'logout',
- 'npm logout [--registry=<url>] [--scope=<@scope>]'
- )
+ static get usage () {
+ return ['[--registry=<url>] [--scope=<@scope>]']
}
exec (args, cb) {
diff --git a/lib/ls.js b/lib/ls.js
index b94684401..9ff2761c2 100644
--- a/lib/ls.js
+++ b/lib/ls.js
@@ -7,7 +7,6 @@ const Arborist = require('@npmcli/arborist')
const { breadth } = require('treeverse')
const npa = require('npm-package-arg')
-const usageUtil = require('./utils/usage.js')
const completion = require('./utils/completion/installed-deep.js')
const _depth = Symbol('depth')
@@ -21,18 +20,17 @@ const _parent = Symbol('parent')
const _problems = Symbol('problems')
const _required = Symbol('required')
const _type = Symbol('type')
+const BaseCommand = require('./base-command.js')
-class LS {
- constructor (npm) {
- this.npm = npm
+class LS extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'ls'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil(
- 'ls',
- 'npm ls [[<@scope>/]<pkg> ...]'
- )
+ static get usage () {
+ return ['npm ls [[<@scope>/]<pkg> ...]']
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
diff --git a/lib/org.js b/lib/org.js
index 2a08941a8..b9f84b060 100644
--- a/lib/org.js
+++ b/lib/org.js
@@ -1,20 +1,21 @@
const liborg = require('libnpmorg')
-const usageUtil = require('./utils/usage.js')
const otplease = require('./utils/otplease.js')
const Table = require('cli-table3')
+const BaseCommand = require('./base-command.js')
-class Org {
- constructor (npm) {
- this.npm = npm
+class Org extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'org'
}
- get usage () {
- return usageUtil(
- 'org',
- 'npm org set orgname username [developer | admin | owner]\n' +
- 'npm org rm orgname username\n' +
- 'npm org ls orgname [<username>]'
- )
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return [
+ 'set orgname username [developer | admin | owner]',
+ 'rm orgname username',
+ 'ls orgname [<username>]',
+ ]
}
async completion (opts) {
diff --git a/lib/outdated.js b/lib/outdated.js
index be5820870..7225577ea 100644
--- a/lib/outdated.js
+++ b/lib/outdated.js
@@ -9,19 +9,18 @@ const pickManifest = require('npm-pick-manifest')
const Arborist = require('@npmcli/arborist')
-const usageUtil = require('./utils/usage.js')
const ansiTrim = require('./utils/ansi-trim.js')
+const BaseCommand = require('./base-command.js')
-class Outdated {
- constructor (npm) {
- this.npm = npm
+class Outdated extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'outdated'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('outdated',
- 'npm outdated [[<@scope>/]<pkg> ...]'
- )
+ static get usage () {
+ return ['[[<@scope>/]<pkg> ...]']
}
exec (args, cb) {
diff --git a/lib/owner.js b/lib/owner.js
index cd387e94d..b62f125ac 100644
--- a/lib/owner.js
+++ b/lib/owner.js
@@ -5,24 +5,21 @@ const pacote = require('pacote')
const otplease = require('./utils/otplease.js')
const readLocalPkg = require('./utils/read-local-package.js')
-const usageUtil = require('./utils/usage.js')
+const BaseCommand = require('./base-command.js')
-class Owner {
- constructor (npm) {
- this.npm = npm
+class Owner extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'owner'
}
- get usage () {
- return usageUtil(
- 'owner',
- 'npm owner add <user> [<@scope>/]<pkg>' +
- '\nnpm owner rm <user> [<@scope>/]<pkg>' +
- '\nnpm owner ls [<@scope>/]<pkg>'
- )
- }
-
- get usageError () {
- return Object.assign(new Error(this.usage), { code: 'EUSAGE' })
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return [
+ 'add <user> [<@scope>/]<pkg>',
+ 'rm <user> [<@scope>/]<pkg>',
+ 'ls [<@scope>/]<pkg>',
+ ]
}
async completion (opts) {
@@ -69,7 +66,7 @@ class Owner {
case 'remove':
return this.rm(args[0], args[1], opts)
default:
- throw this.usageError
+ throw this.usageError()
}
}
@@ -77,7 +74,7 @@ class Owner {
if (!pkg) {
const pkgName = await readLocalPkg(this.npm)
if (!pkgName)
- throw this.usageError
+ throw this.usageError()
pkg = pkgName
}
@@ -101,12 +98,12 @@ class Owner {
async add (user, pkg, opts) {
if (!user)
- throw this.usageError
+ throw this.usageError()
if (!pkg) {
const pkgName = await readLocalPkg(this.npm)
if (!pkgName)
- throw this.usageError
+ throw this.usageError()
pkg = pkgName
}
@@ -119,12 +116,12 @@ class Owner {
async rm (user, pkg, opts) {
if (!user)
- throw this.usageError
+ throw this.usageError()
if (!pkg) {
const pkgName = await readLocalPkg(this.npm)
if (!pkgName)
- throw this.usageError
+ throw this.usageError()
pkg = pkgName
}
diff --git a/lib/pack.js b/lib/pack.js
index 7ffe3138e..326fcc0cd 100644
--- a/lib/pack.js
+++ b/lib/pack.js
@@ -8,16 +8,17 @@ const { getContents, logTar } = require('./utils/tar.js')
const writeFile = util.promisify(require('fs').writeFile)
-const usageUtil = require('./utils/usage.js')
+const BaseCommand = require('./base-command.js')
-class Pack {
- constructor (npm) {
- this.npm = npm
+class Pack extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'pack'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('pack', 'npm pack [[<@scope>/]<pkg>...] [--dry-run]')
+ static get usage () {
+ return ['[[<@scope>/]<pkg>...] [--dry-run]']
}
exec (args, cb) {
diff --git a/lib/ping.js b/lib/ping.js
index 3643fe3b6..e60b1f1de 100644
--- a/lib/ping.js
+++ b/lib/ping.js
@@ -1,15 +1,16 @@
const log = require('npmlog')
-const usageUtil = require('./utils/usage.js')
const pingUtil = require('./utils/ping.js')
+const BaseCommand = require('./base-command.js')
-class Ping {
- constructor (npm) {
- this.npm = npm
+class Ping extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'ping'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('ping', 'npm ping\nping registry')
+ static get description () {
+ return 'ping registry'
}
exec (args, cb) {
diff --git a/lib/prefix.js b/lib/prefix.js
index 8ec5ab9ef..5ade87f64 100644
--- a/lib/prefix.js
+++ b/lib/prefix.js
@@ -1,13 +1,14 @@
-const usageUtil = require('./utils/usage.js')
+const BaseCommand = require('./base-command.js')
-class Prefix {
- constructor (npm) {
- this.npm = npm
+class Prefix extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'prefix'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('prefix', 'npm prefix [-g]')
+ static get usage () {
+ return ['[-g]']
}
exec (args, cb) {
diff --git a/lib/profile.js b/lib/profile.js
index a0a860601..1c0df4988 100644
--- a/lib/profile.js
+++ b/lib/profile.js
@@ -9,7 +9,6 @@ const Table = require('cli-table3')
const otplease = require('./utils/otplease.js')
const pulseTillDone = require('./utils/pulse-till-done.js')
const readUserInfo = require('./utils/read-user-info.js')
-const usageUtil = require('./utils/usage.js')
const qrcode = url =>
new Promise((resolve) => qrcodeTerminal.generate(url, resolve))
@@ -37,19 +36,21 @@ const writableProfileKeys = [
'github',
]
-class Profile {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Profile extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'profile'
}
- get usage () {
- return usageUtil(
- 'profile',
- 'npm profile enable-2fa [auth-only|auth-and-writes]\n',
- 'npm profile disable-2fa\n',
- 'npm profile get [<key>]\n',
- 'npm profile set <key> <value>'
- )
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return [
+ 'enable-2fa [auth-only|auth-and-writes]',
+ 'disable-2fa',
+ 'get [<key>]',
+ 'set <key> <value>',
+ ]
}
async completion (opts) {
diff --git a/lib/prune.js b/lib/prune.js
index b839301d5..c2cddb1a2 100644
--- a/lib/prune.js
+++ b/lib/prune.js
@@ -1,18 +1,17 @@
// prune extraneous packages
const Arborist = require('@npmcli/arborist')
-const usageUtil = require('./utils/usage.js')
const reifyFinish = require('./utils/reify-finish.js')
-class Prune {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Prune extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'prune'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('prune',
- 'npm prune [[<@scope>/]<pkg>...] [--production]'
- )
+ static get usage () {
+ return ['[[<@scope>/]<pkg>...] [--production]']
}
exec (args, cb) {
diff --git a/lib/publish.js b/lib/publish.js
index b0bf92213..f8e0eafe1 100644
--- a/lib/publish.js
+++ b/lib/publish.js
@@ -10,7 +10,6 @@ const npmFetch = require('npm-registry-fetch')
const { flatten } = require('./utils/flat-options.js')
const otplease = require('./utils/otplease.js')
-const usageUtil = require('./utils/usage.js')
const { getContents, logTar } = require('./utils/tar.js')
// this is the only case in the CLI where we use the old full slow
@@ -18,16 +17,18 @@ const { getContents, logTar } = require('./utils/tar.js')
// defaults and metadata, like git sha's and default scripts and all that.
const readJson = util.promisify(require('read-package-json'))
-class Publish {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Publish extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'publish'
}
- get usage () {
- return usageUtil('publish',
- 'npm publish [<folder>] [--tag <tag>] [--access <public|restricted>] [--dry-run]' +
- '\n\nPublishes \'.\' if no argument supplied' +
- '\nSets tag `latest` if no --tag specified')
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return [
+ '[<folder>] [--tag <tag>] [--access <public|restricted>] [--dry-run]',
+ ]
}
exec (args, cb) {
diff --git a/lib/rebuild.js b/lib/rebuild.js
index ffbdebc21..74f5ae5f6 100644
--- a/lib/rebuild.js
+++ b/lib/rebuild.js
@@ -2,17 +2,18 @@ const { resolve } = require('path')
const Arborist = require('@npmcli/arborist')
const npa = require('npm-package-arg')
const semver = require('semver')
-const usageUtil = require('./utils/usage.js')
const completion = require('./utils/completion/installed-deep.js')
-class Rebuild {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Rebuild extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'rebuild'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('rebuild', 'npm rebuild [[<@scope>/]<name>[@<version>] ...]')
+ static get usage () {
+ return ['[[<@scope>/]<name>[@<version>] ...]']
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
diff --git a/lib/repo.js b/lib/repo.js
index f0be99d4d..aa07e07a8 100644
--- a/lib/repo.js
+++ b/lib/repo.js
@@ -4,16 +4,17 @@ const { URL } = require('url')
const hostedFromMani = require('./utils/hosted-git-info-from-manifest.js')
const openUrl = require('./utils/open-url.js')
-const usageUtil = require('./utils/usage.js')
-class Repo {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Repo extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'repo'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('repo', 'npm repo [<pkgname> [<pkgname> ...]]')
+ static get usage () {
+ return ['[<pkgname> [<pkgname> ...]]']
}
exec (args, cb) {
diff --git a/lib/restart.js b/lib/restart.js
index d5a7789ca..1f3eb5af9 100644
--- a/lib/restart.js
+++ b/lib/restart.js
@@ -2,8 +2,9 @@ const LifecycleCmd = require('./utils/lifecycle-cmd.js')
// This ends up calling run-script(['restart', ...args])
class Restart extends LifecycleCmd {
- constructor (npm) {
- super(npm, 'restart')
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'restart'
}
}
module.exports = Restart
diff --git a/lib/root.js b/lib/root.js
index 7c3fa2bbb..1fe82c6fa 100644
--- a/lib/root.js
+++ b/lib/root.js
@@ -1,13 +1,13 @@
-const usageUtil = require('./utils/usage.js')
-
-class Root {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Root extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'root'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('root', 'npm root [-g]')
+ static get usage () {
+ return ['[-g]']
}
exec (args, cb) {
diff --git a/lib/run-script.js b/lib/run-script.js
index dc822668d..3ea85b79f 100644
--- a/lib/run-script.js
+++ b/lib/run-script.js
@@ -3,7 +3,6 @@ const { isServerPackage } = runScript
const readJson = require('read-package-json-fast')
const { resolve } = require('path')
const log = require('npmlog')
-const usageUtil = require('./utils/usage.js')
const didYouMean = require('./utils/did-you-mean.js')
const isWindowsShell = require('./utils/is-windows-shell.js')
@@ -18,17 +17,16 @@ const cmdList = [
'version',
].reduce((l, p) => l.concat(['pre' + p, p, 'post' + p]), [])
-class RunScript {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class RunScript extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'run-script'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil(
- 'run-script',
- 'npm run-script <command> [-- <args>]'
- )
+ static get usage () {
+ return ['<command> [-- <args>]']
}
async completion (opts) {
diff --git a/lib/search.js b/lib/search.js
index 35e3eeb0e..c24000156 100644
--- a/lib/search.js
+++ b/lib/search.js
@@ -5,7 +5,6 @@ const log = require('npmlog')
const formatPackageStream = require('./search/format-package-stream.js')
const packageFilter = require('./search/package-filter.js')
-const usageUtil = require('./utils/usage.js')
function prepareIncludes (args) {
return args
@@ -25,17 +24,16 @@ function prepareExcludes (searchexclude) {
.filter(s => s)
}
-class Search {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Search extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'search'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil(
- 'search',
- 'npm search [-l|--long] [--json] [--parseable] [--no-description] [search terms ...]'
- )
+ static get usage () {
+ return ['[-l|--long] [--json] [--parseable] [--no-description] [search terms ...]']
}
exec (args, cb) {
diff --git a/lib/set-script.js b/lib/set-script.js
index 25545898e..624198132 100644
--- a/lib/set-script.js
+++ b/lib/set-script.js
@@ -1,17 +1,18 @@
const log = require('npmlog')
-const usageUtil = require('./utils/usage.js')
const fs = require('fs')
const parseJSON = require('json-parse-even-better-errors')
const rpj = require('read-package-json-fast')
-class SetScript {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class SetScript extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'set-script'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('set-script', 'npm set-script [<script>] [<command>]')
+ static get usage () {
+ return ['[<script>] [<command>]']
}
exec (args, cb) {
diff --git a/lib/set.js b/lib/set.js
index cbce1547e..787a8012c 100644
--- a/lib/set.js
+++ b/lib/set.js
@@ -1,15 +1,14 @@
-const usageUtil = require('./utils/usage.js')
+const BaseCommand = require('./base-command.js')
-class Set {
- constructor (npm) {
- this.npm = npm
+class Set extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'set'
}
- get usage () {
- return usageUtil(
- 'set',
- 'npm set <key>=<value> [<key>=<value> ...] (See `npm config`)'
- )
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return ['<key>=<value> [<key>=<value> ...] (See `npm config`)']
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
diff --git a/lib/shrinkwrap.js b/lib/shrinkwrap.js
index a7516131d..b52cf4195 100644
--- a/lib/shrinkwrap.js
+++ b/lib/shrinkwrap.js
@@ -5,16 +5,11 @@ const { unlink } = fs.promises || { unlink: util.promisify(fs.unlink) }
const Arborist = require('@npmcli/arborist')
const log = require('npmlog')
-const usageUtil = require('./utils/usage.js')
-
-class Shrinkwrap {
- constructor (npm) {
- this.npm = npm
- }
-
+const BaseCommand = require('./base-command.js')
+class Shrinkwrap extends BaseCommand {
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('shrinkwrap', 'npm shrinkwrap')
+ static get name () {
+ return 'shrinkwrap'
}
exec (args, cb) {
diff --git a/lib/star.js b/lib/star.js
index 073c93a89..27a304190 100644
--- a/lib/star.js
+++ b/lib/star.js
@@ -2,20 +2,18 @@ const fetch = require('npm-registry-fetch')
const log = require('npmlog')
const npa = require('npm-package-arg')
-const usageUtil = require('./utils/usage.js')
const getIdentity = require('./utils/get-identity')
-class Star {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Star extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'star'
}
- get usage () {
- return usageUtil(
- 'star',
- 'npm star [<pkg>...]\n' +
- 'npm unstar [<pkg>...]'
- )
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return ['[<pkg>...]']
}
exec (args, cb) {
diff --git a/lib/stars.js b/lib/stars.js
index e0a6a0003..758a3130d 100644
--- a/lib/stars.js
+++ b/lib/stars.js
@@ -2,16 +2,17 @@ const log = require('npmlog')
const fetch = require('npm-registry-fetch')
const getIdentity = require('./utils/get-identity.js')
-const usageUtil = require('./utils/usage.js')
-class Stars {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Stars extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'stars'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil('stars', 'npm stars [<user>]')
+ static get usage () {
+ return ['[<user>]']
}
exec (args, cb) {
diff --git a/lib/start.js b/lib/start.js
index 3d46a3a7b..8987bc293 100644
--- a/lib/start.js
+++ b/lib/start.js
@@ -2,8 +2,9 @@ const LifecycleCmd = require('./utils/lifecycle-cmd.js')
// This ends up calling run-script(['start', ...args])
class Start extends LifecycleCmd {
- constructor (npm) {
- super(npm, 'start')
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'start'
}
}
module.exports = Start
diff --git a/lib/stop.js b/lib/stop.js
index d7df5887e..a3857ab13 100644
--- a/lib/stop.js
+++ b/lib/stop.js
@@ -2,8 +2,9 @@ const LifecycleCmd = require('./utils/lifecycle-cmd.js')
// This ends up calling run-script(['stop', ...args])
class Stop extends LifecycleCmd {
- constructor (npm) {
- super(npm, 'stop')
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'stop'
}
}
module.exports = Stop
diff --git a/lib/team.js b/lib/team.js
index 3ba2c023d..f84660af4 100644
--- a/lib/team.js
+++ b/lib/team.js
@@ -2,22 +2,23 @@ const columns = require('cli-columns')
const libteam = require('libnpmteam')
const otplease = require('./utils/otplease.js')
-const usageUtil = require('./utils/usage.js')
-class Team {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Team extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'team'
}
- get usage () {
- return usageUtil(
- 'team',
- 'npm team create <scope:team> [--otp <otpcode>]\n' +
- 'npm team destroy <scope:team> [--otp <otpcode>]\n' +
- 'npm team add <scope:team> <user> [--otp <otpcode>]\n' +
- 'npm team rm <scope:team> <user> [--otp <otpcode>]\n' +
- 'npm team ls <scope>|<scope:team>\n'
- )
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return [
+ 'create <scope:team> [--otp <otpcode>]',
+ 'destroy <scope:team> [--otp <otpcode>]',
+ 'add <scope:team> <user> [--otp <otpcode>]',
+ 'rm <scope:team> <user> [--otp <otpcode>]',
+ 'ls <scope>|<scope:team>',
+ ]
}
async completion (opts) {
diff --git a/lib/test.js b/lib/test.js
index 12292d292..991d1c873 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -2,8 +2,9 @@ const LifecycleCmd = require('./utils/lifecycle-cmd.js')
// This ends up calling run-script(['test', ...args])
class Test extends LifecycleCmd {
- constructor (npm) {
- super(npm, 'test')
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'test'
}
exec (args, cb) {
diff --git a/lib/token.js b/lib/token.js
index ad634c0b0..3d7952ccf 100644
--- a/lib/token.js
+++ b/lib/token.js
@@ -7,19 +7,21 @@ const profile = require('npm-profile')
const otplease = require('./utils/otplease.js')
const pulseTillDone = require('./utils/pulse-till-done.js')
const readUserInfo = require('./utils/read-user-info.js')
-const usageUtil = require('./utils/usage.js')
-class Token {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Token extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'token'
}
- get usage () {
- return usageUtil('token',
- 'npm token list\n' +
- 'npm token revoke <id|token>\n' +
- 'npm token create [--read-only] [--cidr=list]'
- )
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return [
+ 'list',
+ 'revoke <id|token>',
+ 'create [--read-only] [--cidr=list]',
+ ]
}
async completion (opts) {
@@ -188,12 +190,6 @@ class Token {
return conf
}
- usageError (msg) {
- return Object.assign(new Error(`\nUsage: ${msg}\n\n` + this.usage), {
- code: 'EUSAGE',
- })
- }
-
invalidCIDRError (msg) {
return Object.assign(new Error(msg), { code: 'EINVALIDCIDR' })
}
diff --git a/lib/uninstall.js b/lib/uninstall.js
index d7116e4c2..ee0f338e9 100644
--- a/lib/uninstall.js
+++ b/lib/uninstall.js
@@ -2,20 +2,19 @@ const { resolve } = require('path')
const Arborist = require('@npmcli/arborist')
const rpj = require('read-package-json-fast')
-const usageUtil = require('./utils/usage.js')
const reifyFinish = require('./utils/reify-finish.js')
const completion = require('./utils/completion/installed-shallow.js')
-class Uninstall {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Uninstall extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'uninstall'
}
- get usage () {
- return usageUtil(
- 'uninstall',
- 'npm uninstall [<@scope>/]<pkg>[@<version>]... [-S|--save|--no-save]'
- )
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return ['[<@scope>/]<pkg>[@<version>]... [-S|--save|--no-save]']
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
diff --git a/lib/unpublish.js b/lib/unpublish.js
index acba6ea52..68a9a0ae6 100644
--- a/lib/unpublish.js
+++ b/lib/unpublish.js
@@ -7,17 +7,19 @@ const npmFetch = require('npm-registry-fetch')
const libunpub = require('libnpmpublish').unpublish
const readJson = util.promisify(require('read-package-json'))
-const usageUtil = require('./utils/usage.js')
const otplease = require('./utils/otplease.js')
const getIdentity = require('./utils/get-identity.js')
-class Unpublish {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Unpublish extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'unpublish'
}
- get usage () {
- return usageUtil('unpublish', 'npm unpublish [<@scope>/]<pkg>[@<version>]')
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return ['[<@scope>/]<pkg>[@<version>]']
}
async completion (args) {
diff --git a/lib/unstar.js b/lib/unstar.js
index c814ef2b6..5786cfce6 100644
--- a/lib/unstar.js
+++ b/lib/unstar.js
@@ -1,6 +1,11 @@
const Star = require('./star.js')
class Unstar extends Star {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'unstar'
+ }
+
exec (args, cb) {
this.npm.config.set('star.unstar', true)
super.exec(args, cb)
diff --git a/lib/update.js b/lib/update.js
index 98043e09c..87540b96e 100644
--- a/lib/update.js
+++ b/lib/update.js
@@ -3,21 +3,19 @@ const path = require('path')
const Arborist = require('@npmcli/arborist')
const log = require('npmlog')
-const usageUtil = require('./utils/usage.js')
const reifyFinish = require('./utils/reify-finish.js')
const completion = require('./utils/completion/installed-deep.js')
-class Update {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Update extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'update'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil(
- 'update',
- 'npm update [-g] [<pkg>...]'
- )
+ static get usage () {
+ return ['[-g] [<pkg>...]']
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
diff --git a/lib/utils/lifecycle-cmd.js b/lib/utils/lifecycle-cmd.js
index 8be9b5a12..1917bef36 100644
--- a/lib/utils/lifecycle-cmd.js
+++ b/lib/utils/lifecycle-cmd.js
@@ -1,19 +1,14 @@
// The implementation of commands that are just "run a script"
// restart, start, stop, test
-const usageUtil = require('./usage.js')
-class LifecycleCmd {
- constructor (npm, stage) {
- this.npm = npm
- this.stage = stage
- }
-
- get usage () {
- return usageUtil(this.stage, `npm ${this.stage} [-- <args>]`)
+const BaseCommand = require('../base-command.js')
+class LifecycleCmd extends BaseCommand {
+ static get usage () {
+ return ['[-- <args>]']
}
exec (args, cb) {
- this.npm.commands['run-script']([this.stage, ...args], cb)
+ this.npm.commands['run-script']([this.constructor.name, ...args], cb)
}
}
module.exports = LifecycleCmd
diff --git a/lib/version.js b/lib/version.js
index a7c0c1955..2eda9d11b 100644
--- a/lib/version.js
+++ b/lib/version.js
@@ -1,20 +1,15 @@
const libversion = require('libnpmversion')
-const usageUtil = require('./utils/usage.js')
-class Version {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Version extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'version'
}
- get usage () {
- return usageUtil(
- 'version',
- 'npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]\n' +
- '(run in package dir)\n\n' +
- `'npm -v' or 'npm --version' to print npm version (${this.npm.version})\n` +
- `'npm view <pkg> version' to view a package's published version\n` +
- `'npm ls' to inspect current package/dependency versions\n`
- )
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get usage () {
+ return ['[<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]']
}
async completion (opts) {
diff --git a/lib/view.js b/lib/view.js
index d0d5fa59d..0a6688fc2 100644
--- a/lib/view.js
+++ b/lib/view.js
@@ -14,22 +14,19 @@ const style = require('ansistyles')
const { inspect, promisify } = require('util')
const { packument } = require('pacote')
-const usageUtil = require('./utils/usage.js')
-
const readFile = promisify(fs.readFile)
const readJson = async file => jsonParse(await readFile(file, 'utf8'))
-class View {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class View extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'view'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil(
- 'view',
- 'npm view [<@scope>/]<pkg>[@<version>] [<field>[.subfield]...]'
- )
+ static get usage () {
+ return ['[<@scope>/]<pkg>[@<version>] [<field>[.subfield]...]']
}
async completion (opts) {
diff --git a/lib/whoami.js b/lib/whoami.js
index 7ce877104..2322c5fd8 100644
--- a/lib/whoami.js
+++ b/lib/whoami.js
@@ -1,18 +1,20 @@
const getIdentity = require('./utils/get-identity.js')
-const usageUtil = require('./utils/usage.js')
-class Whoami {
- constructor (npm) {
- this.npm = npm
+const BaseCommand = require('./base-command.js')
+class Whoami extends BaseCommand {
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get name () {
+ return 'whoami'
+ }
+
+ /* istanbul ignore next - see test/lib/load-all-commands.js */
+ static get description () {
+ return 'prints username according to given registry'
}
/* istanbul ignore next - see test/lib/load-all-commands.js */
- get usage () {
- return usageUtil(
- 'whoami',
- 'npm whoami [--registry <registry>]\n' +
- '(just prints username according to given registry)'
- )
+ static get usage () {
+ return ['[--registry <registry>]']
}
exec (args, cb) {