diff --git a/lib/app.coffee b/lib/app.coffee index 5de772c6..869255b7 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -6,36 +6,84 @@ actions = require('./actions') resin.cli.setVersion(packageJSON.version) # ---------- Options ---------- -resin.cli.addOption('-y, --yes', 'confirm non interactively') -resin.cli.addOption('-v, --verbose', 'increase verbosity') -resin.cli.addOption('-q, --quiet', 'quiet (no output)') -resin.cli.addOption('-t, --type ', 'specify a type when creating an application') +resin.cli.addOption + option: '-y, --yes' + description: 'confirm non interactively' + +resin.cli.addOption + option: '-v, --verbose' + description: 'increase verbosity' + +resin.cli.addOption + option: '-q, --quiet' + description: 'quiet (no output)' + +resin.cli.addOption + option: '-t, --type ' + description: 'specify a type when creating an application' # TODO: I have to use 'application' instead of 'app' here # as Commander gets confused with the app command -resin.cli.addOption('-a, --application ', 'application id', _.parseInt) +resin.cli.addOption + option: '-a, --application ' + description: 'application id' + coerce: _.parseInt # ---------- Auth Module ---------- -resin.cli.addCommand('login [username:password]', 'login to resin.io', actions.auth.login) -resin.cli.addCommand('logout', 'logout from resin.io', actions.auth.logout) -resin.cli.addCommand('signup', 'signup to resin.io', actions.auth.signup) +resin.cli.addCommand + command: 'login [username:password]' + description: 'login to resin.io' + action: actions.auth.login + +resin.cli.addCommand + command: 'logout' + description: 'logout from resin.io' + action: actions.auth.logout + +resin.cli.addCommand + command: 'signup' + description: 'signup to resin.io' + action: actions.auth.signup # ---------- App Module ---------- -resin.cli.addResource('app', 'application', actions.app) -resin.cli.addCommand('app:restart ', 'restart an application', actions.app.restart) +resin.cli.addResource + name: 'app' + displayName: 'application' + actions: actions.app + +resin.cli.addCommand + command: 'app:restart ' + description: 'restart an application' + action: actions.app.restart # ---------- Device Module ---------- -resin.cli.addResource('device', 'device', actions.device) -resin.cli.addCommand('device:identify ', 'identify a device with a UUID', actions.device.identify) +resin.cli.addResource + name: 'device' + displayName: 'device' + actions: actions.device + +resin.cli.addCommand + command: 'device:identify ' + description: 'identify a device with a UUID' + action: actions.device.identify # ---------- Preferences Module ---------- -resin.cli.addCommand('preferences', 'open preferences form', actions.preferences.preferences) +resin.cli.addCommand + command: 'preferences' + description: 'open preferences form' + action: actions.preferences.preferences # ---------- Keys Module ---------- -resin.cli.addResource('key', 'ssh key', actions.keys) +resin.cli.addResource + name: 'key' + displayName: 'ssh key' + actions: actions.keys # ---------- Env Module ---------- -resin.cli.addResource('env', 'environment variable', actions.env) +resin.cli.addResource + name: 'env' + displayName: 'environment variable' + actions: actions.env resin.data.prefix.set resin.config.dataPrefix, (error) -> resin.errors.handle(error) if error? diff --git a/lib/resin/cli/cli.coffee b/lib/resin/cli/cli.coffee index 7b5c60c2..92711464 100644 --- a/lib/resin/cli/cli.coffee +++ b/lib/resin/cli/cli.coffee @@ -11,38 +11,53 @@ exports.setVersion = (version) -> program.version(version) # Set version command automatically - exports.addCommand 'version', 'show version', -> - log.out(version) + exports.addCommand + command: 'version' + description: 'show version' + action: -> + log.out(version) -exports.addCommand = (command, description, action) -> +exports.addCommand = (options = {}) -> program - .command(command) - .description(description) - .action(action) + .command(options.command) + .description(options.description) + .action(options.action) return program -exports.addOption = (option, description, coerceFunction) -> - program.option(option, description, coerceFunction) +exports.addOption = (options = {}) -> + program.option(options.option, options.description, options.coerce) -exports.addResource = (name, displayName, actions = {}) -> - displayName ?= name - nameArticle = indefiniteArticle(displayName) +exports.addResource = (options = {}) -> + options.displayName ?= options.name + nameArticle = indefiniteArticle(options.displayName) - pluralizedName = pluralize(name) - pluralizedDisplayName = pluralize(displayName) + pluralizedName = pluralize(options.name) + pluralizedDisplayName = pluralize(options.displayName) - if _.isFunction(actions.create) - exports.addCommand("#{name}:create ", "create #{nameArticle} #{displayName}", actions.create) + if _.isFunction(options.actions.create) + exports.addCommand + command: "#{options.name}:create " + description: "create #{nameArticle} #{options.displayName}" + action: options.actions.create - if _.isFunction(actions.list) - exports.addCommand("#{pluralizedName}", "list all #{pluralizedDisplayName}", actions.list) + if _.isFunction(options.actions.list) + exports.addCommand + command: "#{pluralizedName}" + description: "list all #{pluralizedDisplayName}" + action: options.actions.list - if _.isFunction(actions.info) - exports.addCommand("#{name} ", "list a single #{displayName}", actions.info) + if _.isFunction(options.actions.info) + exports.addCommand + command: "#{options.name} " + description: "list a single #{options.displayName}" + action: options.actions.info - if _.isFunction(actions.remove) - exports.addCommand("#{name}:rm ", "remove #{nameArticle} #{displayName}", actions.remove) + if _.isFunction(options.actions.remove) + exports.addCommand + command: "#{options.name}:rm " + description: "remove #{nameArticle} #{options.displayName}" + action: options.actions.remove exports.parse = (argv) -> program.parse(argv)