Skip to content

Commit

Permalink
fix: use core v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Jan 24, 2023
1 parent a8a2363 commit 09c493e
Show file tree
Hide file tree
Showing 5 changed files with 533 additions and 876 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"author": "Salesforce",
"bugs": "https://github.com/oclif/plugin-commands/issues",
"dependencies": {
"@oclif/core": "^1.2.0",
"@oclif/core": "^2.0.3",
"lodash": "^4.17.11"
},
"devDependencies": {
"@oclif/plugin-help": "^5.2.0",
"@oclif/test": "^2.0.2",
"@oclif/test": "^2.3.3",
"@types/chai": "^4.3.4",
"@types/lodash": "^4.14.191",
"@types/mocha": "^8.0.0",
Expand All @@ -24,7 +24,7 @@
"mocha": "^8",
"nock": "^13.3.0",
"nyc": "^15.1.0",
"oclif": "^2.3.0",
"oclif": "^3.6.1",
"shx": "^0.3.3",
"ts-node": "^9.1.1",
"tslib": "^2.4.1",
Expand Down Expand Up @@ -54,11 +54,11 @@
"scripts": {
"lint": "eslint . --ext .ts --config .eslintrc",
"pretest": "yarn build && tsc -p test --noEmit",
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
"test": "mocha \"test/**/*.test.ts\"",
"posttest": "yarn lint",
"prepack": "shx rm -rf lib && tsc && oclif manifest . && oclif readme",
"postpack": "shx rm -f oclif.manifest.json",
"version": "oclif readme && git add README.md",
"build": "shx rm -rf lib && tsc"
}
}
}
8 changes: 4 additions & 4 deletions src/commands/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CliUx, Command, Flags, toConfiguredId} from '@oclif/core'
import {ux, Command, Flags, toConfiguredId} from '@oclif/core'
import * as _ from 'lodash'
import {EOL} from 'os'
import createCommandTree from '../utils/tree'
Expand All @@ -9,11 +9,11 @@ export default class Commands extends Command {

static enableJsonFlag = true

static flags: any = {
static flags = {
help: Flags.help({char: 'h'}),
hidden: Flags.boolean({description: 'show hidden commands'}),
tree: Flags.boolean({description: 'show tree of commands'}),
...CliUx.ux.table.flags(),
...ux.table.flags(),
}

async run() {
Expand Down Expand Up @@ -63,7 +63,7 @@ export default class Commands extends Command {
return tree
}

CliUx.ux.table(commands.map(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])
Expand Down
6 changes: 3 additions & 3 deletions src/utils/tree.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CliUx, Interfaces} from '@oclif/core'
import {ux, Command} from '@oclif/core'
import {Tree} from '@oclif/core/lib/cli-ux/styled/tree'

const addNodes = (tree: Tree, commandParts: string[]) => {
Expand All @@ -18,8 +18,8 @@ const addNodes = (tree: Tree, commandParts: string[]) => {
}
}

const createCommandTree = (commands: Interfaces.Command[], topicSeparator = ':') => {
const tree = CliUx.ux.tree()
const createCommandTree = (commands: Command.Loadable[], topicSeparator = ':') => {
const tree = ux.tree()

commands.forEach(command => {
const commandParts = command.id.split(topicSeparator)
Expand Down
16 changes: 3 additions & 13 deletions test/commands/commands.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {expect, test} from '@oclif/test'
import {Command} from '@oclif/core'
import Commands from '../../lib/commands/commands'
import Commands from '../../src/commands/commands'

abstract class TestCommand extends Command {
public static testCustomProperty = 'test'
Expand Down Expand Up @@ -48,18 +48,8 @@ describe('commands', () => {
.stdout()
.command(['commands'])
.it('runs commands', (ctx: { stdout: any }) => {
expect(ctx.stdout).to.equal(
' Command Summary \n' +
' ──────── ───────────────────── \n' +
' commands list all the commands \n',
)
})

test
.stdout()
.command(['commands', '--json'])
.it('runs commands --json', (ctx: { stdout: string }) => {
expect(JSON.parse(ctx.stdout)[0].id).to.equal('commands')
expect(ctx.stdout).to.include('commands list all the commands')
expect(ctx.stdout).to.include('help Display help for oclif-example.')
})

test
Expand Down
Loading

0 comments on commit 09c493e

Please sign in to comment.