Skip to content

Commit 89483e8

Browse files
committed
fix(usage): better audit/boolean flag usage output
This adds the `audit` config item to the usage output of `npm ci`, and also tweaks how usage flags are shown for boolean options that do not default to false. Their usage is shown as the `--no-x` form of the flag to better communicate that the flag is needed to turn that normally true option OFF. The description of `audit` was also updated to reflect that it runs on many different npm commands, not just install. Because this flag is included in the usage of those commands it's best to let the assocation happen there instead of trying to be comprehensive in the description itself. A small fix to make `install-ci-test` not try to redefine its own usage, but to inherit from `ci` was also included. PR-URL: #3497 Credit: @wraithgar Close: #3497 Reviewed-by: @nlf
1 parent c3bd10e commit 89483e8

18 files changed

+135
-87
lines changed

docs/content/commands/npm-ci.md

+10
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ cache:
6969

7070
<!-- AUTOGENERATED CONFIG DESCRIPTIONS START -->
7171
<!-- automatically generated, do not edit manually -->
72+
#### `audit`
73+
74+
* Default: true
75+
* Type: Boolean
76+
77+
When "true" submit audit reports alongside the current npm command to the
78+
default registry and all registries configured for scopes. See the
79+
documentation for [`npm audit`](/commands/npm-audit) for details on what is
80+
submitted.
81+
7282
#### `ignore-scripts`
7383

7484
* Default: false

docs/content/commands/npm-dedupe.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ will *not* run any pre- or post-scripts.
164164
* Default: true
165165
* Type: Boolean
166166
167-
When "true" submit audit reports alongside `npm install` runs to the default
168-
registry and all registries configured for scopes. See the documentation for
169-
[`npm audit`](/commands/npm-audit) for details on what is submitted.
167+
When "true" submit audit reports alongside the current npm command to the
168+
default registry and all registries configured for scopes. See the
169+
documentation for [`npm audit`](/commands/npm-audit) for details on what is
170+
submitted.
170171
171172
#### `bin-links`
172173

docs/content/commands/npm-find-dupes.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ will *not* run any pre- or post-scripts.
107107
* Default: true
108108
* Type: Boolean
109109

110-
When "true" submit audit reports alongside `npm install` runs to the default
111-
registry and all registries configured for scopes. See the documentation for
112-
[`npm audit`](/commands/npm-audit) for details on what is submitted.
110+
When "true" submit audit reports alongside the current npm command to the
111+
default registry and all registries configured for scopes. See the
112+
documentation for [`npm audit`](/commands/npm-audit) for details on what is
113+
submitted.
113114

114115
#### `bin-links`
115116

docs/content/commands/npm-install-ci-test.md

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ This command runs `npm ci` followed immediately by `npm test`.
2020

2121
<!-- AUTOGENERATED CONFIG DESCRIPTIONS START -->
2222
<!-- automatically generated, do not edit manually -->
23+
#### `audit`
24+
25+
* Default: true
26+
* Type: Boolean
27+
28+
When "true" submit audit reports alongside the current npm command to the
29+
default registry and all registries configured for scopes. See the
30+
documentation for [`npm audit`](/commands/npm-audit) for details on what is
31+
submitted.
32+
2333
#### `ignore-scripts`
2434

2535
* Default: false

docs/content/commands/npm-install-test.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,10 @@ will *not* run any pre- or post-scripts.
149149
* Default: true
150150
* Type: Boolean
151151

152-
When "true" submit audit reports alongside `npm install` runs to the default
153-
registry and all registries configured for scopes. See the documentation for
154-
[`npm audit`](/commands/npm-audit) for details on what is submitted.
152+
When "true" submit audit reports alongside the current npm command to the
153+
default registry and all registries configured for scopes. See the
154+
documentation for [`npm audit`](/commands/npm-audit) for details on what is
155+
submitted.
155156

156157
#### `bin-links`
157158

docs/content/commands/npm-install.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,10 @@ will *not* run any pre- or post-scripts.
533533
* Default: true
534534
* Type: Boolean
535535
536-
When "true" submit audit reports alongside `npm install` runs to the default
537-
registry and all registries configured for scopes. See the documentation for
538-
[`npm audit`](/commands/npm-audit) for details on what is submitted.
536+
When "true" submit audit reports alongside the current npm command to the
537+
default registry and all registries configured for scopes. See the
538+
documentation for [`npm audit`](/commands/npm-audit) for details on what is
539+
submitted.
539540
540541
#### `bin-links`
541542

docs/content/commands/npm-link.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,10 @@ will *not* run any pre- or post-scripts.
233233
* Default: true
234234
* Type: Boolean
235235

236-
When "true" submit audit reports alongside `npm install` runs to the default
237-
registry and all registries configured for scopes. See the documentation for
238-
[`npm audit`](/commands/npm-audit) for details on what is submitted.
236+
When "true" submit audit reports alongside the current npm command to the
237+
default registry and all registries configured for scopes. See the
238+
documentation for [`npm audit`](/commands/npm-audit) for details on what is
239+
submitted.
239240

240241
#### `bin-links`
241242

docs/content/commands/npm-update.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,10 @@ will *not* run any pre- or post-scripts.
255255
* Default: true
256256
* Type: Boolean
257257

258-
When "true" submit audit reports alongside `npm install` runs to the default
259-
registry and all registries configured for scopes. See the documentation for
260-
[`npm audit`](/commands/npm-audit) for details on what is submitted.
258+
When "true" submit audit reports alongside the current npm command to the
259+
default registry and all registries configured for scopes. See the
260+
documentation for [`npm audit`](/commands/npm-audit) for details on what is
261+
submitted.
261262

262263
#### `bin-links`
263264

docs/content/using-npm/config.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ to the same value as the current version.
170170
* Default: true
171171
* Type: Boolean
172172

173-
When "true" submit audit reports alongside `npm install` runs to the default
174-
registry and all registries configured for scopes. See the documentation for
175-
[`npm audit`](/commands/npm-audit) for details on what is submitted.
173+
When "true" submit audit reports alongside the current npm command to the
174+
default registry and all registries configured for scopes. See the
175+
documentation for [`npm audit`](/commands/npm-audit) for details on what is
176+
submitted.
176177

177178
#### `audit-level`
178179

lib/ci.js

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class CI extends ArboristWorkspaceCmd {
3333
/* istanbul ignore next - see test/lib/load-all-commands.js */
3434
static get params () {
3535
return [
36+
'audit',
3637
'ignore-scripts',
3738
'script-shell',
3839
]

lib/install-ci-test.js

-8
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ class InstallCITest extends CI {
1313
return 'install-ci-test'
1414
}
1515

16-
/* istanbul ignore next - see test/lib/load-all-commands.js */
17-
static get params () {
18-
return [
19-
'ignore-scripts',
20-
'script-shell',
21-
]
22-
}
23-
2416
exec (args, cb) {
2517
this.npm.commands.ci(args, (er) => {
2618
if (er)

lib/utils/config/definition.js

+25-7
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,27 @@ ${noEnvExport}`)
9191
}
9292

9393
const describeUsage = (def) => {
94-
let key = `--${def.key}`
95-
if (def.short && typeof def.short === 'string')
96-
key = `-${def.short}|${key}`
94+
let key = ''
9795

9896
// Single type
99-
if (!Array.isArray(def.type))
100-
return `${key}${def.type === Boolean ? '' : ' ' + def.hint}`
97+
if (!Array.isArray(def.type)) {
98+
if (def.short)
99+
key = `-${def.short}|`
100+
101+
if (def.type === Boolean && def.default !== false)
102+
key = `${key}--no-${def.key}`
103+
else
104+
key = `${key}--${def.key}`
105+
106+
if (def.type !== Boolean)
107+
key = `${key} ${def.hint}`
108+
109+
return key
110+
}
111+
112+
key = `--${def.key}`
113+
if (def.short)
114+
key = `-${def.short}|--${def.key}`
101115

102116
// Multiple types
103117
let types = def.type
@@ -120,8 +134,12 @@ const describeUsage = (def) => {
120134
description = def.hint
121135
}
122136

123-
if (bool)
124-
key = `${key}|${key}`
137+
if (bool) {
138+
// Currently none of our multi-type configs with boolean values default to
139+
// false so all their hints should show `--no-`, if we ever add ones that
140+
// default to false we can branch the logic here
141+
key = `--no-${def.key}|${key}`
142+
}
125143

126144
const usage = `${key} ${description}`
127145
if (multiple)

lib/utils/config/definitions.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ define('audit', {
203203
default: true,
204204
type: Boolean,
205205
description: `
206-
When "true" submit audit reports alongside \`npm install\` runs to the
206+
When "true" submit audit reports alongside the current npm command to the
207207
default registry and all registries configured for scopes. See the
208-
documentation for [\`npm audit\`](/commands/npm-audit) for details on
209-
what is submitted.
208+
documentation for [\`npm audit\`](/commands/npm-audit) for details on what
209+
is submitted.
210210
`,
211211
flatten,
212212
})
@@ -440,6 +440,7 @@ define('cidr', {
440440

441441
define('color', {
442442
default: !process.env.NO_COLOR || process.env.NO_COLOR === '0',
443+
usage: '--color|--no-color|--color always',
443444
defaultDescription: `
444445
true unless the NO_COLOR environ is set to something other than '0'
445446
`,

tap-snapshots/test/lib/load-all-commands.js.test.cjs

+21-21
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Usage:
8484
npm bugs [<pkgname>]
8585
8686
Options:
87-
[--browser|--browser <browser>] [--registry <registry>]
87+
[--no-browser|--browser <browser>] [--registry <registry>]
8888
8989
alias: issues
9090
@@ -120,7 +120,7 @@ Usage:
120120
npm ci
121121
122122
Options:
123-
[--ignore-scripts] [--script-shell <script-shell>]
123+
[--no-audit] [--ignore-scripts] [--script-shell <script-shell>]
124124
125125
aliases: clean-install, ic, install-clean, isntall-clean
126126
@@ -167,9 +167,9 @@ Usage:
167167
npm dedupe
168168
169169
Options:
170-
[--global-style] [--legacy-bundling] [--strict-peer-deps] [--package-lock]
170+
[--global-style] [--legacy-bundling] [--strict-peer-deps] [--no-package-lock]
171171
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--ignore-scripts]
172-
[--audit] [--bin-links] [--fund] [--dry-run]
172+
[--no-audit] [--no-bin-links] [--no-fund] [--dry-run]
173173
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
174174
[-ws|--workspaces]
175175
@@ -239,7 +239,7 @@ Usage:
239239
npm docs [<pkgname> [<pkgname> ...]]
240240
241241
Options:
242-
[--browser|--browser <browser>] [--registry <registry>]
242+
[--no-browser|--browser <browser>] [--registry <registry>]
243243
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
244244
[-ws|--workspaces]
245245
@@ -337,9 +337,9 @@ Usage:
337337
npm find-dupes
338338
339339
Options:
340-
[--global-style] [--legacy-bundling] [--strict-peer-deps] [--package-lock]
340+
[--global-style] [--legacy-bundling] [--strict-peer-deps] [--no-package-lock]
341341
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--ignore-scripts]
342-
[--audit] [--bin-links] [--fund]
342+
[--no-audit] [--no-bin-links] [--no-fund]
343343
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
344344
[-ws|--workspaces]
345345
@@ -355,7 +355,7 @@ Usage:
355355
npm fund [[<@scope>/]<pkg>]
356356
357357
Options:
358-
[--json] [--browser|--browser <browser>] [--unicode]
358+
[--json] [--no-browser|--browser <browser>] [--unicode]
359359
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
360360
[--which <fundingSourceNumber>]
361361
@@ -446,9 +446,9 @@ npm install <github username>/<github project>
446446
Options:
447447
[-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer]
448448
[-E|--save-exact] [-g|--global] [--global-style] [--legacy-bundling]
449-
[--strict-peer-deps] [--package-lock]
449+
[--strict-peer-deps] [--no-package-lock]
450450
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--ignore-scripts]
451-
[--audit] [--bin-links] [--fund] [--dry-run]
451+
[--no-audit] [--no-bin-links] [--no-fund] [--dry-run]
452452
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
453453
[-ws|--workspaces]
454454
@@ -466,7 +466,7 @@ Usage:
466466
npm install-ci-test
467467
468468
Options:
469-
[--ignore-scripts] [--script-shell <script-shell>]
469+
[--no-audit] [--ignore-scripts] [--script-shell <script-shell>]
470470
471471
alias: cit
472472
@@ -493,9 +493,9 @@ npm install-test <github username>/<github project>
493493
Options:
494494
[-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer]
495495
[-E|--save-exact] [-g|--global] [--global-style] [--legacy-bundling]
496-
[--strict-peer-deps] [--package-lock]
496+
[--strict-peer-deps] [--no-package-lock]
497497
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--ignore-scripts]
498-
[--audit] [--bin-links] [--fund] [--dry-run]
498+
[--no-audit] [--no-bin-links] [--no-fund] [--dry-run]
499499
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
500500
[-ws|--workspaces]
501501
@@ -516,9 +516,9 @@ npm link [<@scope>/]<pkg>[@<version>]
516516
Options:
517517
[-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer]
518518
[-E|--save-exact] [-g|--global] [--global-style] [--legacy-bundling]
519-
[--strict-peer-deps] [--package-lock]
519+
[--strict-peer-deps] [--no-package-lock]
520520
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--ignore-scripts]
521-
[--audit] [--bin-links] [--fund] [--dry-run]
521+
[--no-audit] [--no-bin-links] [--no-fund] [--dry-run]
522522
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
523523
[-ws|--workspaces]
524524
@@ -768,7 +768,7 @@ Usage:
768768
npm rebuild [[<@scope>/]<name>[@<version>] ...]
769769
770770
Options:
771-
[-g|--global] [--bin-links] [--ignore-scripts]
771+
[-g|--global] [--no-bin-links] [--ignore-scripts]
772772
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
773773
[-ws|--workspaces]
774774
@@ -786,7 +786,7 @@ Usage:
786786
npm repo [<pkgname> [<pkgname> ...]]
787787
788788
Options:
789-
[--browser|--browser <browser>]
789+
[--no-browser|--browser <browser>]
790790
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
791791
[-ws|--workspaces]
792792
@@ -848,7 +848,7 @@ Usage:
848848
npm search [search terms ...]
849849
850850
Options:
851-
[-l|--long] [--json] [--color|--color <always>] [-p|--parseable]
851+
[-l|--long] [--json] [--color|--no-color|--color always] [-p|--parseable]
852852
[--no-description] [--searchopts <searchopts>] [--searchexclude <searchexclude>]
853853
[--registry <registry>] [--prefer-online] [--prefer-offline] [--offline]
854854
@@ -1059,8 +1059,8 @@ npm update [<pkg>...]
10591059
10601060
Options:
10611061
[-g|--global] [--global-style] [--legacy-bundling] [--strict-peer-deps]
1062-
[--package-lock] [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
1063-
[--ignore-scripts] [--audit] [--bin-links] [--fund] [--dry-run]
1062+
[--no-package-lock] [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
1063+
[--ignore-scripts] [--no-audit] [--no-bin-links] [--no-fund] [--dry-run]
10641064
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
10651065
[-ws|--workspaces]
10661066
@@ -1078,7 +1078,7 @@ Usage:
10781078
npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git]
10791079
10801080
Options:
1081-
[--allow-same-version] [--commit-hooks] [--git-tag-version] [--json]
1081+
[--allow-same-version] [--no-commit-hooks] [--no-git-tag-version] [--json]
10821082
[--preid prerelease-id] [--sign-git-tag]
10831083
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
10841084
[-ws|--workspaces]

tap-snapshots/test/lib/utils/config/definitions.js.test.cjs

+4-3
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,10 @@ exports[`test/lib/utils/config/definitions.js TAP > config description for audit
218218
* Default: true
219219
* Type: Boolean
220220
221-
When "true" submit audit reports alongside \`npm install\` runs to the default
222-
registry and all registries configured for scopes. See the documentation for
223-
[\`npm audit\`](/commands/npm-audit) for details on what is submitted.
221+
When "true" submit audit reports alongside the current npm command to the
222+
default registry and all registries configured for scopes. See the
223+
documentation for [\`npm audit\`](/commands/npm-audit) for details on what is
224+
submitted.
224225
`
225226

226227
exports[`test/lib/utils/config/definitions.js TAP > config description for audit-level 1`] = `

0 commit comments

Comments
 (0)