update the command handlers to use argv parsing
diff --git a/client/lib/repl.js b/client/lib/repl.js
index 7862b6a..1f13809 100644
--- a/client/lib/repl.js
+++ b/client/lib/repl.js
@@ -1,4 +1,5 @@
-var prompt = require('inquirer'),
+var argv = require('argv'),
+ prompt = require('inquirer'),
rewriter = require('./rewriter'),
columnify = require('columnify');
@@ -30,7 +31,8 @@
handler: rewriter.attach,
enumerate: rewriter.list,
description: "Attach to an action",
- synchronous: true
+ synchronous: true,
+ options: [{ name: 'action-only', short: 'a', type: 'string', description: 'Instrument just the action, not any rules or sequences in which it takes part' }]
};
var detach = {
handler: rewriter.detach,
@@ -53,7 +55,8 @@
var list = {
handler: rewriter.listToConsole,
description: "List available actions",
- synchronous: true
+ synchronous: true,
+ options: [{ name: 'full', short: 'f', type: 'string', description: 'Show all actions, including debugging artifacts' }]
};
var clean = {
handler: rewriter.clean,
@@ -119,17 +122,36 @@
var command = commandLine.shift();
var handler = commandHandlers[command];
+ var options;
+ if (handler.options) {
+ argv.clear();
+ argv.description = 'Usage: ' + command + ' [options]';
+ argv.options.help.example = "";
+ argv.options.help.onset = (args) => {
+ argv.help(args.mod);
+ }
+ options = argv.option(handler.options).run(commandLine).options;
+ }
+
if (handler.synchronous) {
// the second parameter is the call back to the repl
// when done with the synchronous operation
commandLine.unshift(repl.bind(undefined, wskprops));
}
+ if (handler.options) {
+ commandLine.unshift(options);
+ }
+
// the first parameter is wskprops
commandLine.unshift(wskprops);
// call to the handler!
- handler.handler.apply(undefined, commandLine);
+ try {
+ handler.handler.apply(undefined, commandLine);
+ } catch (e) {
+ console.error(e);
+ }
if (!handler.synchronous) {
// if async, then restart the repl right away
diff --git a/client/lib/rewriter.js b/client/lib/rewriter.js
index 3549365..f03a698 100644
--- a/client/lib/rewriter.js
+++ b/client/lib/rewriter.js
@@ -85,14 +85,13 @@
errorWhile('fetching actions', callback));
}
-exports.listToConsole = function listToConsole(wskprops, next, options) {
- console.log('Available actions:'.blue);
+exports.listToConsole = function listToConsole(wskprops, options, next) {
+ if (options.help) return next();
+ console.log('Available actions:'.blue);
function print(actions) {
actions
- .filter(action =>
- (options && (options == '--full' || options == '--f' || options == '-f'))
- || !Namer.isDebugArtifact(action.name))
+ .filter(action => options && options.full || !Namer.isDebugArtifact(action.name))
.forEach(action => console.log(' ', action.name[created[action.name] ? 'green' : 'reset']));
ok_(next);
@@ -366,8 +365,10 @@
* Attach to the given entity, allowing for debugging its invocations
*
*/
-exports.attach = function attach(wskprops, next, entity, option) {
- console.log('Attaching'.blue + ' to ' + entity + (option ? ' with option ' + option : ''));
+exports.attach = function attach(wskprops, options, next, entity) {
+ if (options.help) return next();
+
+ console.log('Attaching'.blue + ' to ' + entity);
try {
var entityNamespace = wskprops['NAMESPACE'];
@@ -375,7 +376,7 @@
console.log(' Creating action trampoline'.green);
splice(ow, entity, entityNamespace, function afterSplice(names) {
- if (option === '--action-only' || option === '--ao' || option == '-ao') {
+ if (options && options['action-only']) {
//
// user asked not to instrument any rules or sequences
//