Skip to content

Commit

Permalink
fix: add summary and use configured command (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley authored Oct 12, 2021
1 parent efc615d commit d1ce99e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
Expand Down
10 changes: 8 additions & 2 deletions src/commands/commands.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
})

Expand All @@ -51,14 +53,18 @@ 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
}), {
id: {
header: 'Command',
},
description: {},
summary: {},
description: {
extended: true,
},
usage: {
extended: true,
},
Expand Down
14 changes: 7 additions & 7 deletions test/commands/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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' +
Expand All @@ -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',
)
Expand All @@ -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',
)
Expand All @@ -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',
)
Expand All @@ -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',
Expand All @@ -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',
)
Expand Down
42 changes: 31 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand All @@ -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==
Expand All @@ -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==
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit d1ce99e

Please sign in to comment.