Skip to content

Commit

Permalink
feat: json output for plugins list (#609)
Browse files Browse the repository at this point in the history
* feat: json output for plugins list

* fix: handle jsonEnabled correctly

* chore: test timeout (windows, sigh)

* test: assert json output

* test: longer timeout
  • Loading branch information
mshanemc authored May 24, 2023
1 parent 3d09af5 commit f274f3f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
],
"recursive": true,
"reporter": "spec",
"timeout": 60000
}
"timeout": 200000
}
11 changes: 8 additions & 3 deletions src/commands/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Plugins from '../../plugins'
import {sortBy} from '../../util'

export default class PluginsIndex extends Command {
static enableJsonFlag = true
static flags = {
core: Flags.boolean({description: 'Show core plugins.'}),
}
Expand All @@ -15,7 +16,7 @@ export default class PluginsIndex extends Command {

plugins = new Plugins(this.config)

async run(): Promise<void> {
async run(): Promise<ReturnType<Plugins['list']>> {
const {flags} = await this.parse(PluginsIndex)
let plugins = this.config.plugins
sortBy(plugins, p => this.plugins.friendlyName(p.name))
Expand All @@ -25,10 +26,14 @@ export default class PluginsIndex extends Command {

if (plugins.length === 0) {
this.log('No plugins installed.')
return
return []
}

this.display(plugins as Plugin[])
if (!this.jsonEnabled()) {
this.display(plugins as Plugin[])
}

return this.plugins.list()
}

private display(plugins: Plugin[]) {
Expand Down
17 changes: 17 additions & 0 deletions test/commands/plugins/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import {platform} from 'node:os'

describe('command', () => {
test
.stdout()
.command(['plugins'], {reset: true})
.do(output => expect(output.stdout).to.equal('No plugins installed.\n'))
.command(['plugins:install', '@oclif/example-plugin-ts'], {reset: true})
.stdout()
.command(['plugins'], {reset: true})
Expand All @@ -16,6 +19,20 @@ describe('command', () => {
.do(output => expect(output.stdout).to.equal('No plugins installed.\n'))
.it('installs and uninstalls @oclif/example-plugin-ts')

test
.command(['plugins', '--json'], {reset: true})
.do(output => expect((output.returned)).to.deep.equal([]))
.command(['plugins:install', '@oclif/example-plugin-ts'], {reset: true})
.command(['plugins', '--json'], {reset: true})
.do(output => expect((output.returned as [{name: string}]).find(o => o.name === '@oclif/example-plugin-ts')).to.have.property('type', 'user'))
.stdout()
.command(['hello'], {reset: true})
.do(output => expect(output.stdout).to.contain('hello world'))
.command(['plugins:uninstall', '@heroku-cli/plugin-@oclif/example-plugin-ts'])
.command(['plugins', '--json'], {reset: true})
.do(output => expect((output.returned)).to.deep.equal([]))
.it('installs and uninstalls @oclif/example-plugin-ts (--json)')

test
.command(['plugins:install', '@oclif/example-plugin-ts@latest'], {reset: true})
.stdout()
Expand Down
20 changes: 2 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3601,7 +3601,7 @@ isarray@^1.0.0, isarray@~1.0.0:
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=

isbinaryfile@^4.0.10, isbinaryfile@^4.0.8:
isbinaryfile@^4.0.10:
version "4.0.10"
resolved "https://registry.yarnpkg.com/isbinaryfile/-/isbinaryfile-4.0.10.tgz#0c5b5e30c2557a2f06febd37b7322946aaee42b3"
integrity sha512-iHrqe5shvBUcFbmZq9zOQHBoeOhZJu6RQGrDpBgenUm/Am+F3JM2MgQj+rK3Z601fzrL5gLZWtAPH2OBaSVcyw==
Expand Down Expand Up @@ -4058,23 +4058,7 @@ map-obj@^4.0.0:
resolved "https://registry.npmjs.org/map-obj/-/map-obj-4.2.1.tgz#e4ea399dbc979ae735c83c863dd31bdf364277b7"
integrity sha512-+WA2/1sPmDj1dlvvJmB5G6JKfY9dpn7EVBUL06+y6PoljPkh+6V1QihwxNkbcGxCRjt2b0F9K0taiCuo7MbdFQ==

"mem-fs-editor@^8.1.2 || ^9.0.0":
version "9.4.0"
resolved "https://registry.npmjs.org/mem-fs-editor/-/mem-fs-editor-9.4.0.tgz#0cc1cf61350e33c25fc364c97fb0551eb32b8c9b"
integrity sha512-HSSOLSVRrsDdui9I6i96dDtG+oAez/4EB2g4cjSrNhgNQ3M+L57/+22NuPdORSoxvOHjIg/xeOE+C0wwF91D2g==
dependencies:
binaryextensions "^4.16.0"
commondir "^1.0.1"
deep-extend "^0.6.0"
ejs "^3.1.6"
globby "^11.0.3"
isbinaryfile "^4.0.8"
minimatch "^3.0.4"
multimatch "^5.0.0"
normalize-path "^3.0.0"
textextensions "^5.13.0"

mem-fs-editor@^9.0.0:
"mem-fs-editor@^8.1.2 || ^9.0.0", mem-fs-editor@^9.0.0:
version "9.7.0"
resolved "https://registry.yarnpkg.com/mem-fs-editor/-/mem-fs-editor-9.7.0.tgz#dbb458b8acb885c84013645e93f71aa267a7fdf6"
integrity sha512-ReB3YD24GNykmu4WeUL/FDIQtkoyGB6zfJv60yfCo3QjKeimNcTqv2FT83bP0ccs6uu+sm5zyoBlspAzigmsdg==
Expand Down

0 comments on commit f274f3f

Please sign in to comment.