update inspect command to support rules
diff --git a/client/lib/commands/inspect.js b/client/lib/commands/inspect.js
index 892d40f..930fa21 100644
--- a/client/lib/commands/inspect.js
+++ b/client/lib/commands/inspect.js
@@ -1,5 +1,6 @@
var ok = require('../repl-messages').ok,
ok_ = require('../repl-messages').ok_,
+ okAfter = require('../repl-messages').okAfter,
errorWhile = require('../repl-messages').errorWhile,
_list = require('./list')._list,
inquirer = require('inquirer'),
@@ -11,26 +12,43 @@
var ow = setupOpenWhisk(wskprops);
function doInspect(name) {
+ const attached = isDirectlyAttachedTo(name);
+ const chainAttached = isChainAttachedTo(name);
+
+ console.log( ('Attached = ' + (attached ? 'yes' : chainAttached ? 'yes, to one or more parts' : 'no'))
+ [attached ? 'blue' : chainAttached ? 'blue' : 'dim'] );
+
ow.actions.get({ actionName: name })
.then((details) => {
- const attached = isDirectlyAttachedTo(name);
- const chainAttached = isChainAttachedTo(name);
- console.log( ('Attached = ' + (attached ? 'yes' : chainAttached ? 'yes, to one or more parts' : 'no'))
- [attached ? 'blue' : chainAttached ? 'blue' : 'dim'] );
-
if (details.exec && details.exec.kind === 'sequence') {
+ //
+ // sequence
+ //
console.log(details.exec.components
.map(a => {
const name = a.substring(a.lastIndexOf('/') + 1);
return name[chainAttached && isDirectlyAttachedTo(name) ? 'green' : 'reset'];
}).join(' -> '));
+
} else {
+ //
+ // normal action
+ //
console.log(property ? details.exec[property]
: 'This is a ' + details.exec.kind.blue + ' action');
}
ok_(next);
- }).catch(errorWhile('fetching action details', next));
+ }).catch((err) => {
+ if (err.toString().indexOf('Resource already exists with this name') >= 0) {
+ //
+ // then the entity exists, but isn't an action. try rules, next
+ //
+ ow.rules.get({ ruleName: name })
+ .then(okAfter(rule => console.log(`${rule.trigger} |-> ${rule.action}`), next))
+ .catch(errorWhile('inspecting entity', next));
+ }
+ });
}
if (!name) {
diff --git a/client/lib/repl-messages.js b/client/lib/repl-messages.js
index 85715d1..77ff9ac 100644
--- a/client/lib/repl-messages.js
+++ b/client/lib/repl-messages.js
@@ -25,6 +25,13 @@
exports.ok(next)();
};
+exports.okAfter = function okAfter(f, next) {
+ return function() {
+ f.apply(undefined, arguments);
+ exports.ok_(next);
+ };
+};
+
/**
* Log an error, and continue
*