Skip to content

Commit 16fe009

Browse files
committed
Add cli:false for options that can only be provided in ncurc.
1 parent 1b34a50 commit 16fe009

File tree

3 files changed

+39
-26
lines changed

3 files changed

+39
-26
lines changed

README.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ ncu "/^(?!react-).*$/" # windows
174174
-f, --filter <p> Include only package names matching the given
175175
string, wildcard, glob, comma-or-space-delimited
176176
list, /regex/, or predicate function.
177-
--filterResults <fn> Filters out upgrades based on a user provided
177+
filterResults* Filters out upgrades based on a user provided
178178
function. Run "ncu --help --filterResults" for
179179
details.
180180
--filterVersion <p> Filter on package version using
@@ -187,7 +187,7 @@ ncu "/^(?!react-).*$/" # windows
187187
[])
188188
-g, --global Check global packages instead of in the current
189189
project.
190-
--groupFunction <fn> Customize how packages are divided into groups
190+
groupFunction* Customize how packages are divided into groups
191191
when using '--format group'. Run "ncu --help
192192
--groupFunction" for details.
193193
-i, --interactive Enable interactive prompts for each dependency;
@@ -254,8 +254,8 @@ ncu "/^(?!react-).*$/" # windows
254254
[])
255255
-ws, --workspaces Run on all workspaces. Add --root to also upgrade
256256
the root project.
257-
-V, --version output the version number
258-
-h, --help display help
257+
-V, --version Output the version number.
258+
-h, --help You're lookin' at it.
259259
```
260260

261261
<!-- END Options -->
@@ -328,16 +328,12 @@ Example:
328328

329329
## filterResults
330330

331-
Usage:
332-
333-
ncu --filterResults [fn]
334-
335-
Filters out upgrades based on a user provided function. Only available in .ncurc.js or when importing npm-check-updates as a module.
331+
Filters out upgrades based on a user provided function.
336332

337-
For the SemVer type, see: https://git.coolaj86.com/coolaj86/semver-utils.js#semverutils-parse-semverstring
333+
Only available in .ncurc.js or when importing npm-check-updates as a module.
338334

339335
```js
340-
/**
336+
/** Filter out non-major version updates.
341337
@param {string} packageName The name of the dependency.
342338
@param {string} currentVersion Current version declaration (may be range).
343339
@param {SemVer[]} currentVersionSemver Current version declaration in semantic versioning format (may be range).
@@ -355,7 +351,7 @@ filterResults: (packageName, {currentVersion, currentVersionSemver, upgradedVers
355351
}
356352
```
357353
358-
The above example filters out non-major version updates.
354+
For the SemVer type definition, see: https://git.coolaj86.com/coolaj86/semver-utils.js#semverutils-parse-semverstring
359355
360356
## format
361357
@@ -375,11 +371,9 @@ Modify the output formatting or show additional information. Specify one or more
375371
376372
## groupFunction
377373
378-
Usage:
379-
380-
ncu --groupFunction [fn]
374+
Customize how packages are divided into groups when using `--format group`.
381375
382-
Customize how packages are divided into groups when using `--format group`. Only available in .ncurc.js or when importing npm-check-updates as a module:
376+
Only available in .ncurc.js or when importing npm-check-updates as a module.
383377
384378
```js
385379
/**
@@ -504,7 +498,7 @@ Determines the version to upgrade to. (default: "latest")
504498
You can also specify a custom function in your .ncurc.js file, or when importing npm-check-updates as a module:
505499
506500
```js
507-
/** Custom target.
501+
/** Upgrade major version zero to the next minor version, and everything else to latest.
508502
@param dependencyName The name of the dependency.
509503
@param parsedVersion A parsed Semver object from semver-utils.
510504
(See https://git.coolaj86.com/coolaj86/semver-utils.js#semverutils-parse-semverstring)

src/bin/cli.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,25 @@ ${chalk.dim.underline(
8484
process.exit(0)
8585
}
8686

87+
// a set of options that only work in an rc config file, not on the command line
88+
const noCli = new Set(cliOptions.filter(option => option.cli === false).map(option => `--${option.long}`))
89+
8790
// start commander program
8891
program
8992
.description('[filter] is a list or regex of package names to check (all others will be ignored).')
9093
.usage('[options] [filter]')
9194
// See: boolean optional arg below
9295
.configureHelp({
93-
optionTerm: option => option.flags.replace('[bool]', ''),
96+
optionTerm: option =>
97+
option.long && noCli.has(option.long)
98+
? option.long.replace('--', '') + '*'
99+
: option.flags.replace('[bool]', ''),
94100
optionDescription: option =>
95-
option.long === '--help' ? 'display help' : Help.prototype.optionDescription(option),
101+
option.long === '--version'
102+
? 'Output the version number.'
103+
: option.long === '--help'
104+
? `You're lookin' at it.`
105+
: Help.prototype.optionDescription(option),
96106
})
97107

98108
// add cli options

src/cli-options.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type ExtendedHelp = string | ((options: { markdown?: boolean }) => string)
1212
export interface CLIOption<T = any> {
1313
arg?: string
1414
choices?: T[]
15+
/** If false, the option is only usable in the ncurc file, or when using npm-check-updates as a module, not on the command line. */
16+
cli?: boolean
1517
default?: T
1618
deprecated?: boolean
1719
description: string
@@ -36,9 +38,12 @@ const codeBlock = (code: string, { markdown }: { markdown?: boolean } = {}) => {
3638

3739
/** Renders the extended help for an option with usage information. */
3840
export const renderExtendedHelp = (option: CLIOption, { markdown }: { markdown?: boolean } = {}) => {
39-
let output = `Usage:
41+
let output = ''
42+
if (option.cli !== false) {
43+
output = `Usage:
4044
4145
ncu --${option.long}${option.arg ? ` [${option.arg}]` : ''}\n`
46+
}
4247
if (option.short) {
4348
output += ` ncu -${option.short}${option.arg ? ` [${option.arg}]` : ''}\n`
4449
}
@@ -119,12 +124,12 @@ Example:
119124

120125
/** Extended help for the filterResults option. */
121126
const extendedHelpFilterResults: ExtendedHelp = ({ markdown }) => {
122-
return `Filters out upgrades based on a user provided function. Only available in .ncurc.js or when importing npm-check-updates as a module.
127+
return `Filters out upgrades based on a user provided function.
123128
124-
For the SemVer type, see: https://git.coolaj86.com/coolaj86/semver-utils.js#semverutils-parse-semverstring
129+
Only available in .ncurc.js or when importing npm-check-updates as a module.
125130
126131
${codeBlock(
127-
`${chalk.gray(`/**
132+
`${chalk.gray(`/** Filter out non-major version updates.
128133
@param {string} packageName The name of the dependency.
129134
@param {string} currentVersion Current version declaration (may be range).
130135
@param {SemVer[]} currentVersionSemver Current version declaration in semantic versioning format (may be range).
@@ -145,7 +150,7 @@ ${chalk.cyan(
145150
{ markdown },
146151
)}
147152
148-
The above example filters out non-major version updates.
153+
For the SemVer type definition, see: https://git.coolaj86.com/coolaj86/semver-utils.js#semverutils-parse-semverstring
149154
150155
`
151156
}
@@ -172,7 +177,9 @@ const extendedHelpFormat: ExtendedHelp = ({ markdown }) => {
172177

173178
/** Extended help for the --group option. */
174179
const extendedHelpGroupFunction: ExtendedHelp = ({ markdown }) => {
175-
return `Customize how packages are divided into groups when using \`--format group\`. Only available in .ncurc.js or when importing npm-check-updates as a module:
180+
return `Customize how packages are divided into groups when using \`--format group\`.
181+
182+
Only available in .ncurc.js or when importing npm-check-updates as a module.
176183
177184
${codeBlock(
178185
`${chalk.gray(`/**
@@ -227,7 +234,7 @@ ${padLeft(tableString, markdown ? 0 : 4)}
227234
You can also specify a custom function in your .ncurc.js file, or when importing npm-check-updates as a module:
228235
229236
${codeBlock(
230-
`${chalk.gray(`/** Custom target.
237+
`${chalk.gray(`/** Upgrade major version zero to the next minor version, and everything else to latest.
231238
@param dependencyName The name of the dependency.
232239
@param parsedVersion A parsed Semver object from semver-utils.
233240
(See https://git.coolaj86.com/coolaj86/semver-utils.js#semverutils-parse-semverstring)
@@ -444,6 +451,7 @@ const cliOptions: CLIOption[] = [
444451
{
445452
long: 'filterResults',
446453
arg: 'fn',
454+
cli: false,
447455
description: `Filters out upgrades based on a user provided function.`,
448456
type: 'FilterResultsFunction',
449457
help: extendedHelpFilterResults,
@@ -475,6 +483,7 @@ const cliOptions: CLIOption[] = [
475483
{
476484
long: 'groupFunction',
477485
arg: 'fn',
486+
cli: false,
478487
description: `Customize how packages are divided into groups when using '--format group'.`,
479488
type: 'GroupFunction',
480489
help: extendedHelpGroupFunction,

0 commit comments

Comments
 (0)