Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit 14506cd

Browse files
committed
fix usage models for editing commands
Fixes #749
1 parent 792ea08 commit 14506cd

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

app/plugins/modules/editor/lib/edit.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ const path = require('path'),
2323
placeholders = require('./placeholders'),
2424
{ lockIcon } = require('./readonly')
2525

26-
/** optional command line arguments, by command */
27-
const optionalArguments = {
28-
new: '[--kind <nodejs:default*|python:default|php:default|swift:default>]'
29-
}
30-
3126
/** default settings */
3227
const defaults = {
3328
kind: 'nodejs:default'
@@ -717,12 +712,12 @@ module.exports = (commandTree, prequire) => {
717712
const wsk = prequire('/ui/commands/openwhisk-core')
718713

719714
// command registration: edit existing action
720-
commandTree.listen('/editor/edit', edit(wsk, prequire), { docs: strings.docs.edit })
715+
commandTree.listen('/editor/edit', edit(wsk, prequire), { usage: usage.edit })
721716

722717
// command registration: create new action
723-
commandTree.listen('/editor/new', newAction({wsk, prequire}), { docs: strings.docs.new })
718+
commandTree.listen('/editor/new', newAction({wsk, prequire}), { usage: usage.new })
724719

725720
// command registration: create new app/composition
726721
commandTree.listen('/editor/compose', newAction(compositionOptions({ wsk, prequire, op: 'compose'})),
727-
{ docs: strings.docs.compose })
722+
{ usage: usage.compose })
728723
}

app/plugins/modules/editor/usage.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,39 @@ module.exports = {
3535
},
3636

3737
edit: {
38+
strict: 'edit',
39+
command: 'edit',
3840
title: 'Edit action',
3941
header: 'Open a given action or composition in the sidecar for editing.',
4042
example: 'edit <actionName>',
41-
commandPrefix: 'editor edit',
42-
required: [{ name: '<actionName>', docs: 'The OpenWhisk action to edit' }],
43+
required: [{ name: '<actionName>', docs: 'The OpenWhisk action to edit', implicitOK: ['actions', 'activations'] }],
4344
parents: [{command: 'editor'}],
4445
related: allExcept('edit')
4546
},
4647

4748
compose: {
49+
strict: 'compose',
50+
command: 'compose',
4851
title: 'New composition',
4952
header: 'For quick prototyping of compositions, this command opens an editor in the sidecar.',
5053
example: 'compose <appName>',
51-
commandPrefix: 'editor compose',
5254
required: [{ name: '<appName>', docs: 'The name of your new composition' }],
5355
parents: [{command: 'editor'}],
5456
related: allExcept('compose')
5557
},
5658

5759
new: {
60+
strict: 'new',
61+
command: 'new',
5862
title: 'New action',
5963
header: 'For quick prototyping of actions, this command opens an editor in the sidecar.',
6064
example: 'new <actionName>',
61-
commandPrefix: 'editor new',
6265
required: [{ name: '<actionName>', docs: 'The name of your new action' }],
66+
optional: [{ name: '--kind', alias: '-k', docs: 'The OpenWhisk kind of the new action',
67+
allowed: ['nodejs', 'python', 'php', 'swift'],
68+
allowedIsPrefixMatch: true,
69+
defaultValue: 'nodejs'
70+
}],
6371
parents: [{command: 'editor'}],
6472
related: allExcept('new')
6573
}

tests/tests/passes/04/edit-new.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ describe('create new actions in editor', function() {
4242
.then(cli.expectError(409))
4343
.catch(common.oops(this)))
4444

45+
it('should report 498 for new --kind zoo', () => cli.do('new nope --kind zoo', this.app)
46+
.then(cli.expectError(498)) // bad value for optional parameter
47+
.catch(common.oops(this)))
48+
4549
/** deploy the new action */
4650
const deploy = (app, action) => () => {
4751
return app.client.click(ui.selectors.SIDECAR_MODE_BUTTON('Deploy'))

tests/tests/passes/04/edit.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,20 @@ describe('edit actions', function() {
3636
.then(cli.expectError(404))
3737
.catch(common.oops(this)))
3838

39+
it('should report 499 for edit --kind', () => cli.do('edit nope --kind foo', this.app)
40+
.then(cli.expectError(499)) // unsupported optional parameter
41+
.catch(common.oops(this)))
42+
3943
it('should create an action', () => cli.do('let foo = x=>x', this.app)
4044
.then(cli.expectOK)
4145
.then(sidecar.expectOpen)
4246
.then(sidecar.expectShowing('foo'))
4347
.catch(common.oops(this)))
4448

49+
it('should report 499 for edit --kind on existing action', () => cli.do('edit foo --kind foo', this.app)
50+
.then(cli.expectError(499)) // unsupported optional parameter
51+
.catch(common.oops(this)))
52+
4553
it('should edit with implicit entity', () => cli.do('edit', this.app)
4654
.then(cli.expectOK)
4755
.then(sidecar.expectOpen)

0 commit comments

Comments
 (0)