Skip to content

Commit

Permalink
feat: support Oclif-2 in publickey commands
Browse files Browse the repository at this point in the history
  • Loading branch information
purplecabbage committed Jun 20, 2022
1 parent d77beef commit 98f7e0a
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 34 deletions.
10 changes: 5 additions & 5 deletions src/commands/console/publickey/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ governing permissions and limitations under the License.
*/

const aioConsoleLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-console:publickey:list', { provider: 'debug' })
const { flags } = require('@oclif/command')
const { Flags } = require('@oclif/core')
const { CONFIG_KEYS } = require('../../../config')
const ConsoleCommand = require('../index')

class DeleteCommand extends ConsoleCommand {
async run () {
const { args, flags } = this.parse(DeleteCommand)
const { args, flags } = await this.parse(DeleteCommand)

const orgId = flags.orgId || this.getConfig(`${CONFIG_KEYS.ORG}.id`)
if (!orgId) {
Expand Down Expand Up @@ -72,13 +72,13 @@ DeleteCommand.description = 'Delete a public key certificate from the selected W

DeleteCommand.flags = {
...ConsoleCommand.flags,
orgId: flags.string({
orgId: Flags.string({
description: 'Organization id of the Console Workspace to delete the public key certificate from'
}),
projectId: flags.string({
projectId: Flags.string({
description: 'Project id of the Console Workspace to delete the public key certificate from'
}),
workspaceId: flags.string({
workspaceId: Flags.string({
description: 'Workspace id of the Console Workspace to delete the public key certificate from'
})
}
Expand Down
7 changes: 3 additions & 4 deletions src/commands/console/publickey/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

const Help = require('@oclif/plugin-help').default
const ConsoleCommand = require('..')
const { cli } = require('cli-ux')
const { Help, CliUx: { ux: cli } } = require('@oclif/core')
const ConsoleCommand = require('../')

class IndexCommand extends ConsoleCommand {
async run () {
const help = new Help(this.config)
help.showHelp(['console:publickey', '--help'])
await help.showHelp(['console:publickey', '--help'])
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/commands/console/publickey/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ governing permissions and limitations under the License.
*/

const aioConsoleLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-console:publickey:list', { provider: 'debug' })
const { flags } = require('@oclif/command')
const { Flags } = require('@oclif/core')
const { CONFIG_KEYS } = require('../../../config')

const ConsoleCommand = require('../index')
const IndexCommand = require('./index')

class ListCommand extends ConsoleCommand {
async run () {
const { flags } = this.parse(ListCommand)
const { flags } = await this.parse(ListCommand)

const orgId = flags.orgId || this.getConfig(`${CONFIG_KEYS.ORG}.id`)
if (!orgId) {
Expand Down Expand Up @@ -71,21 +71,21 @@ ListCommand.description = 'List the public key certificates bound to the selecte

ListCommand.flags = {
...ConsoleCommand.flags,
orgId: flags.string({
orgId: Flags.string({
description: 'Organization id of the Console Workspace to list the public key certificates for'
}),
projectId: flags.string({
projectId: Flags.string({
description: 'Project id of the Console Workspace to list the public key certificate for'
}),
workspaceId: flags.string({
workspaceId: Flags.string({
description: 'Workspace id of the Console Workspace to list the public key certificate for'
}),
json: flags.boolean({
json: Flags.boolean({
description: 'Output json',
char: 'j',
exclusive: ['yml']
}),
yml: flags.boolean({
yml: Flags.boolean({
description: 'Output yml',
char: 'y',
exclusive: ['json']
Expand Down
14 changes: 7 additions & 7 deletions src/commands/console/publickey/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
const { flags } = require('@oclif/command')
const { Flags } = require('@oclif/core')
const ConsoleCommand = require('../index')
const IndexCommand = require('./index')
const fs = require('fs')
Expand All @@ -19,7 +19,7 @@ const aioConsoleLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-

class UploadAndBindCommand extends ConsoleCommand {
async run () {
const { args, flags } = this.parse(UploadAndBindCommand)
const { args, flags } = await this.parse(UploadAndBindCommand)

const orgId = flags.orgId || this.getConfig(`${CONFIG_KEYS.ORG}.id`)
if (!orgId) {
Expand Down Expand Up @@ -99,21 +99,21 @@ UploadAndBindCommand.description = 'Upload a public key certificate to the selec

UploadAndBindCommand.flags = {
...ConsoleCommand.flags,
orgId: flags.string({
orgId: Flags.string({
description: 'Organization id of the Console Workspace to upload the public key certificate to'
}),
projectId: flags.string({
projectId: Flags.string({
description: 'Project id of the Console Workspace to upload the public key certificate to'
}),
workspaceId: flags.string({
workspaceId: Flags.string({
description: 'Workspace id of the Console Workspace to upload the public key certificate to'
}),
json: flags.boolean({
json: Flags.boolean({
description: 'Output json',
char: 'j',
exclusive: ['yml']
}),
yml: flags.boolean({
yml: Flags.boolean({
description: 'Output yml',
char: 'y',
exclusive: ['json']
Expand Down
1 change: 1 addition & 0 deletions test/commands/console/org/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ test('args', async () => {
})

test('flags', async () => {
console.log('org TheCommand = ', JSON.stringify(TheCommand.flags, 0, 2))
expect(TheCommand.flags.help.type).toBe('boolean')
})

Expand Down
2 changes: 1 addition & 1 deletion test/commands/console/publickey/delete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

const { Command } = require('@oclif/command')
const { Command } = require('@oclif/core')
const { stdout } = require('stdout-stderr')

// mock data
Expand Down
16 changes: 8 additions & 8 deletions test/commands/console/publickey/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ governing permissions and limitations under the License.

const TheCommand = require('../../../../src/commands/console/publickey')
const ConsoleCommand = require('../../../../src/commands/console')
const Help = require('@oclif/plugin-help').default
const { cli: mockCLI } = require('cli-ux')
jest.mock('cli-ux')
const { Help, CliUx: { ux: cli } } = require('@oclif/core')

test('exports', async () => {
expect(typeof TheCommand).toEqual('function')
Expand All @@ -29,6 +27,7 @@ test('args', async () => {
})

test('flags', async () => {
console.log('TheCommand = ', JSON.stringify(ConsoleCommand, 0, 2))
expect(TheCommand.flags.help.type).toBe('boolean')
})

Expand All @@ -39,7 +38,8 @@ test('formatExpiry', async () => {

test('printBindings', async () => {
expect(typeof TheCommand.printBindings).toEqual('function')
const spy = jest.spyOn(TheCommand, 'formatExpiry')
const spyFormatExpiry = jest.spyOn(TheCommand, 'formatExpiry')
const spyTable = jest.spyOn(cli, 'table')
const bindingWithExpires = {
bindingId: 'testBinding1',
orgId: 'testOrgId',
Expand Down Expand Up @@ -70,10 +70,9 @@ test('printBindings', async () => {
header: 'Expires'
}
}
mockCLI.table = jest.fn()
TheCommand.printBindings([bindingWithExpires, bindingWithoutExpires])
expect(spy).toHaveBeenCalledWith(1685806324000)
expect(mockCLI.table).toHaveBeenCalledWith([decoratedWithExpires, decoratedWithoutExpires], columns)
expect(spyFormatExpiry).toHaveBeenCalledWith(1685806324000)
expect(spyTable).toHaveBeenLastCalledWith([decoratedWithExpires, decoratedWithoutExpires], columns)
})

describe('instance methods', () => {
Expand All @@ -89,7 +88,8 @@ describe('instance methods', () => {
})

test('returns help file for console command', () => {
const spy = jest.spyOn(Help.prototype, 'showHelp').mockReturnValue(true)
command.config = {}
const spy = jest.spyOn(Help.prototype, 'showHelp').mockResolvedValue(true)
return command.run().then(() => {
expect(spy).toHaveBeenCalledWith(['console:publickey', '--help'])
})
Expand Down
2 changes: 1 addition & 1 deletion test/commands/console/publickey/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

const { Command } = require('@oclif/command')
const { Command } = require('@oclif/core')
const { stdout } = require('stdout-stderr')

// mock data
Expand Down
2 changes: 1 addition & 1 deletion test/commands/console/publickey/upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

const { Command } = require('@oclif/command')
const { Command } = require('@oclif/core')
const { stdout } = require('stdout-stderr')
const fs = require('fs')

Expand Down

0 comments on commit 98f7e0a

Please sign in to comment.