From d1ce99eb233155e019a585177972188953b0ffaf Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Tue, 12 Oct 2021 16:06:17 -0700 Subject: [PATCH] fix: add summary and use configured command (#217) --- package.json | 4 ++-- src/commands/commands.ts | 10 ++++++-- test/commands/commands.test.ts | 14 ++++++------ yarn.lock | 42 +++++++++++++++++++++++++--------- 4 files changed, 48 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 14da82f8..d58f0f82 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "author": "Jeff Dickey @jdxcode", "bugs": "https://github.com/oclif/plugin-commands/issues", "dependencies": { - "@oclif/core": "^0.5.39", + "@oclif/core": "^1.0.1", "cli-ux": "^5.6.3", "lodash": "^4.17.11" }, @@ -25,7 +25,7 @@ "mocha": "^8", "nock": "^13.0.0", "nyc": "^15.1.0", - "oclif": "^2.0.0-main.5", + "oclif": "^2.0.0-main.8", "ts-node": "^9.1.1", "tslib": "^2.0.0", "typescript": "4.4.3" diff --git a/src/commands/commands.ts b/src/commands/commands.ts index 4f49cbbe..c68b99ce 100644 --- a/src/commands/commands.ts +++ b/src/commands/commands.ts @@ -1,4 +1,4 @@ -import {Command, Flags} from '@oclif/core' +import {Command, Flags, toConfiguredId} from '@oclif/core' import {ux} from 'cli-ux' import * as _ from 'lodash' import {EOL} from 'os' @@ -26,7 +26,9 @@ export default class Commands extends Command { commands = _.sortBy(commands, 'id').map(command => { // Template supported fields. command.description = (typeof command.description === 'string' && _.template(command.description)({command, config})) || undefined + command.summary = (typeof command.summary === 'string' && _.template(command.summary)({command, config})) || undefined command.usage = (typeof command.usage === 'string' && _.template(command.usage)({command, config})) || undefined + command.id = toConfiguredId(command.id, this.config) return command }) @@ -51,6 +53,7 @@ export default class Commands extends Command { ux.table(commands.map(command => { // Massage some fields so it looks good in the table command.description = (command.description || '').split(EOL)[0] + command.summary = (command.summary || (command.description || '').split(EOL)[0]) command.hidden = Boolean(command.hidden) command.usage = (command.usage || '') return command @@ -58,7 +61,10 @@ export default class Commands extends Command { id: { header: 'Command', }, - description: {}, + summary: {}, + description: { + extended: true, + }, usage: { extended: true, }, diff --git a/test/commands/commands.test.ts b/test/commands/commands.test.ts index df050cd7..9403e742 100644 --- a/test/commands/commands.test.ts +++ b/test/commands/commands.test.ts @@ -48,7 +48,7 @@ describe('commands', () => { .command(['commands']) .it('runs commands', (ctx: { stdout: any }) => { expect(ctx.stdout).to.equal( - ' Command Description \n' + + ' Command Summary \n' + ' ──────── ────────────────────────────── \n' + ' commands list all the commands \n' + ' help display help for oclif-example \n', @@ -68,7 +68,7 @@ describe('commands', () => { .command(['commands', '--hidden']) .it('runs commands --hidden', (ctx: { stdout: any }) => { expect(ctx.stdout).to.equal( - ' Command Description \n' + + ' Command Summary \n' + ' ───────────────────────────── ─────────────────────────────── \n' + ' anothertopic:subtopic:command another super good test command \n' + ' hidden \n' + @@ -82,7 +82,7 @@ describe('commands', () => { .command(['commands', '--filter=Command=^topic']) .it('runs commands --filter="Command=^topic"', (ctx: { stdout: any }) => { expect(ctx.stdout).to.equal( - ' Command Description \n' + + ' Command Summary \n' + ' ────────────────────── ─────────────────────── \n' + ' topic:subtopic:command super good test command \n', ) @@ -94,7 +94,7 @@ describe('commands', () => { .command(['commands', '--filter=Plugin=anothertest']) .it('runs commands --filter="Plugin=anothertest"', (ctx: { stdout: any }) => { expect(ctx.stdout).to.equal( - ' Command Description \n' + + ' Command Summary \n' + ' ───────────────────────────── ─────────────────────────────── \n' + ' anothertopic:subtopic:command another super good test command \n', ) @@ -106,7 +106,7 @@ describe('commands', () => { .command(['commands', '--filter=Command=anothertopic:subtopic:command']) .it('runs commands --filter="Command=anothertopic:subtopic:command"', (ctx: { stdout: any }) => { expect(ctx.stdout).to.equal( - ' Command Description \n' + + ' Command Summary \n' + ' ───────────────────────────── ─────────────────────────────── \n' + ' anothertopic:subtopic:command another super good test command \n', ) @@ -129,7 +129,7 @@ describe('commands', () => { .command(['commands', '--filter=Command=subtopic:command']) .it('runs commands --filter"=Command=subtopic:command"', (ctx: { stdout: any }) => { expect(ctx.stdout).to.equal( - ' Command Description \n' + + ' Command Summary \n' + ' ───────────────────────────── ─────────────────────────────── \n' + ' anothertopic:subtopic:command another super good test command \n' + ' topic:subtopic:command super good test command \n', @@ -142,7 +142,7 @@ describe('commands', () => { .command(['commands', '--filter=Command=^topic:subtopic:command']) .it('runs commands --filter"=Command=^topic:subtopic:command"', (ctx: { stdout: any }) => { expect(ctx.stdout).to.equal( - ' Command Description \n' + + ' Command Summary \n' + ' ────────────────────── ─────────────────────── \n' + ' topic:subtopic:command super good test command \n', ) diff --git a/yarn.lock b/yarn.lock index fd4e3258..740c0b9a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -274,7 +274,7 @@ supports-color "^5.4.0" tslib "^1" -"@oclif/command@^1.5.10", "@oclif/command@^1.5.20", "@oclif/command@^1.6", "@oclif/command@^1.6.0": +"@oclif/command@^1.5.10", "@oclif/command@^1.5.20", "@oclif/command@^1.6.0": version "1.8.0" resolved "https://registry.yarnpkg.com/@oclif/command/-/command-1.8.0.tgz#c1a499b10d26e9d1a611190a81005589accbb339" integrity sha512-5vwpq6kbvwkQwKqAoOU3L72GZ3Ta8RRrewKj9OJRolx28KLJJ8Dg9Rf7obRwt5jQA9bkYd8gqzMTrI7H3xLfaw== @@ -286,7 +286,7 @@ debug "^4.1.1" semver "^7.3.2" -"@oclif/config@^1.12.6", "@oclif/config@^1.12.8", "@oclif/config@^1.15.1": +"@oclif/config@^1.12.8", "@oclif/config@^1.15.1": version "1.17.0" resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.17.0.tgz#ba8639118633102a7e481760c50054623d09fcab" integrity sha512-Lmfuf6ubjQ4ifC/9bz1fSCHc6F6E653oyaRXxg+lgT4+bYf9bk+nqrUpAbrXyABkCqgIBiFr3J4zR/kiFdE1PA== @@ -298,7 +298,7 @@ is-wsl "^2.1.1" tslib "^2.0.0" -"@oclif/core@^0.5.34", "@oclif/core@^0.5.39": +"@oclif/core@^0.5.39": version "0.5.39" resolved "https://registry.yarnpkg.com/@oclif/core/-/core-0.5.39.tgz#d00705f31c5e6617145e84bb9dd50156cf3b01c5" integrity sha512-4XusxLX8PnHDQxtRP25PImlkIj1Mlx6wt0NWb1FxQGvTJOAgXGJZl3YB02ZeXZLYbeKA2A3AqqxFTTKbADnZng== @@ -321,6 +321,29 @@ widest-line "^3.1.0" wrap-ansi "^7.0.0" +"@oclif/core@^1.0.0", "@oclif/core@^1.0.1": + version "1.0.1" + resolved "https://registry.npmjs.org/@oclif/core/-/core-1.0.1.tgz#e97fc5c234db1a745fb4468eb79cabeea5f84af9" + integrity sha512-ai9XwnEZ+P34VUtV+fX/6HmRbo5CXGdZjX3iK3PsY6O+KYeJBKVAkPCKLz0qtAHxx0HX4+Yj2wnmy+hTCx6HYQ== + dependencies: + "@oclif/linewrap" "^1.0.0" + chalk "^4.1.0" + clean-stack "^3.0.0" + cli-ux "^5.1.0" + debug "^4.1.1" + fs-extra "^9.0.1" + get-package-type "^0.1.0" + globby "^11.0.1" + indent-string "^4.0.0" + is-wsl "^2.1.1" + lodash.template "^4.4.0" + semver "^7.3.2" + string-width "^4.2.0" + strip-ansi "^6.0.0" + tslib "^2.0.0" + widest-line "^3.1.0" + wrap-ansi "^7.0.0" + "@oclif/errors@^1.2.1", "@oclif/errors@^1.2.2", "@oclif/errors@^1.3.3": version "1.3.3" resolved "https://registry.yarnpkg.com/@oclif/errors/-/errors-1.3.3.tgz#fb597dfbc58c6b8609dc0b2fdf91a2d487818a82" @@ -3951,15 +3974,12 @@ object.pick@^1.3.0: dependencies: isobject "^3.0.1" -oclif@^2.0.0-main.5: - version "2.0.0-main.5" - resolved "https://registry.yarnpkg.com/oclif/-/oclif-2.0.0-main.5.tgz#077d587da46049da3812828247ec4321ffff8663" - integrity sha512-f6DnW2b70mop0fFf03K4OUcbCx+Ox8tGFWTuaypyguJoN2JPGkim1XvdW7HkhChJ8LTbgy55dFF8GuKBcBU6qQ== +oclif@^2.0.0-main.8: + version "2.0.0-main.8" + resolved "https://registry.npmjs.org/oclif/-/oclif-2.0.0-main.8.tgz#cef5fa8325fd8a3bd7e24f649d045422180bd9aa" + integrity sha512-/35x1hVr6s+vyN8cVJ65AU7h00HPPoCWsw7ztrxnaJLTmjJ7b+mKeHYczrAerHldeulzfzS8vYXyfbDFwj18/A== dependencies: - "@oclif/command" "^1.6" - "@oclif/config" "^1.12.6" - "@oclif/core" "^0.5.34" - "@oclif/errors" "^1.2.2" + "@oclif/core" "^1.0.0" "@oclif/fixpack" "^2.3.0" "@oclif/plugin-help" "^3" "@oclif/plugin-not-found" "^1.2.2"