Skip to content

Commit

Permalink
Add extended help to --format option.
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Jun 16, 2022
1 parent 49a91c3 commit 4ebf32a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ ncu "/^(?!react-).*$/" # windows
--filterVersion <matches> Filter on package version using
comma-or-space-delimited list, /regex/, or
predicate function.
--format <value> Enable additional output data, string or
comma-delimited list. ownerChanged: shows if the
package owner changed between versions. repo:
infers and displays links to source code
repository. (default: [])
--format <value> Modify the output formatting or show additional
information. Specify one or more comma-delimited
values: repo, ownerChanged. Run "ncu --help
--format" for details. (default: [])
-g, --global Check global packages instead of in the current
project.
-i, --interactive Enable interactive prompts for each dependency;
Expand Down
32 changes: 22 additions & 10 deletions src/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ export interface CLIOption<T = any> {
type: string
}

/**
* "newest" means most recently released in terms of release date, even if there are other version numbers that are higher. It includes prereleases.
* "greatest" means the highest version number, regardless of release date. It includes prereleases.
* "latest" is whatever the project's "latest" git tag points to. It's usually the non-prerelease version with the highest version number, but is ultimately decided by each project's maintainers.
* "minor" means the highest minor version without incrementing the current major.
* "patch" means the highest patch version without incrementing the current major or minor.
**/
const getHelpTargetTable = (): string => {
/** Extended help for the --target option. */
const extendedHelpTarget = (): string => {
/* eslint-disable fp/no-mutating-methods */

const table = new Table({
Expand Down Expand Up @@ -68,6 +62,23 @@ You can also specify a custom function in your .ncurc.js file, or when importing
`
}

/** Extended help for the --format option. */
const extendedHelpFormat = (): string => {
/* eslint-disable fp/no-mutating-methods */

const table = new Table({
colAligns: ['right', 'left'],
})

table.push(['repo', `Infers and displays links to the package's source code repository.`])
table.push(['ownerChanged', `Shows if the package owner has changed.`])

return `Modify the output formatting or show additional information. Specify one or more comma-delimited values.
${table.toString()}
`
}

// store CLI options separately from bin file so that they can be used to build type definitions
const cliOptions: CLIOption[] = [
{
Expand Down Expand Up @@ -170,11 +181,12 @@ const cliOptions: CLIOption[] = [
long: 'format',
arg: 'value',
description:
'Enable additional output data, string or comma-delimited list. ownerChanged: shows if the package owner changed between versions. repo: infers and displays links to source code repository.',
'Modify the output formatting or show additional information. Specify one or more comma-delimited values: repo, ownerChanged. Run "ncu --help --format" for details.',
parse: value => (typeof value === 'string' ? value.split(',') : value),
default: [],
type: 'string[]',
choices: ['ownerChanged', 'repo'],
help: extendedHelpFormat(),
},
{
long: 'global',
Expand Down Expand Up @@ -353,7 +365,7 @@ As a comparison: without using the --peer option, ncu will suggest the latest ve
arg: 'value',
description:
'Determines the version to upgrade to: latest, newest, greatest, minor, patch, @[tag], or [function]. Run "ncu --help --target" for details. (default: "latest")',
help: getHelpTargetTable(),
help: extendedHelpTarget(),
// eslint-disable-next-line no-template-curly-in-string
type: `'latest' | 'newest' | 'greatest' | 'minor' | 'patch' | ${'`@${string}`'} | TargetFunction`,
},
Expand Down
2 changes: 1 addition & 1 deletion src/types/RunOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface RunOptions {
/** Filter on package version using comma-or-space-delimited list, /regex/, or predicate function. */
filterVersion?: string | string[] | RegExp | RegExp[] | FilterFunction

/** Enable additional output data, string or comma-delimited list. ownerChanged: shows if the package owner changed between versions. repo: infers and displays links to source code repository. */
/** Modify the output formatting or show additional information. Specify one or more comma-delimited values: repo, ownerChanged. Run "ncu --help --format" for details. */
format?: string[]

/** Check global packages instead of in the current project. */
Expand Down

0 comments on commit 4ebf32a

Please sign in to comment.