Implement CLI addResource

This commit is contained in:
Juan Cruz Viotti 2014-11-27 09:10:51 -04:00
parent 86ecf5b1b6
commit a5791d080f
3 changed files with 32 additions and 15 deletions

View File

@ -21,28 +21,21 @@ resin.cli.addCommand('logout', 'logout from resin.io', actions.auth.logout)
resin.cli.addCommand('signup', 'signup to resin.io', actions.auth.signup)
# ---------- App Module ----------
resin.cli.addCommand('app:create <name>', 'create a resin.io application', actions.app.create)
resin.cli.addCommand('apps', 'list your applications', actions.app.list)
resin.cli.addCommand('app <id>', 'list a single application', actions.app.info)
resin.cli.addResource('app', 'application', actions.app)
resin.cli.addCommand('app:restart <id>', 'restart an application', actions.app.restart)
resin.cli.addCommand('app:rm <id>', 'remove an application', actions.app.remove)
# ---------- Device Module ----------
resin.cli.addCommand('devices <id>', 'show devices for an application', actions.device.list)
resin.cli.addCommand('device:rm <id>', 'remove a device', actions.device.remove)
resin.cli.addResource('device', 'device', actions.device)
resin.cli.addCommand('device:identify <uuid>', 'identify a device with a UUID', actions.device.identify)
# ---------- Preferences Module ----------
resin.cli.addCommand('preferences', 'open preferences form', actions.preferences.preferences)
# ---------- Keys Module ----------
resin.cli.addCommand('keys', 'list all SSH keys', actions.keys.list)
resin.cli.addCommand('key <id>', 'list a single SSH key', actions.keys.info)
resin.cli.addCommand('key:rm <id>', 'remove a SSH key', actions.keys.remove)
resin.cli.addResource('key', 'ssh key', actions.keys)
# ---------- Env Module ----------
resin.cli.addCommand('envs', 'list all environment variables', actions.env.list)
resin.cli.addCommand('env:rm <id>', 'remove environment variable', actions.env.remove)
resin.cli.addResource('env', 'environment variable', actions.env)
resin.data.prefix.set resin.config.dataPrefix, (error) ->
resin.errors.handle(error) if error?

View File

@ -1,4 +1,7 @@
_ = require('lodash')
program = require('commander')
pluralize = require('pluralize')
indefiniteArticle = require('indefinite-article')
log = require('../log/log')
exports.getArgument = (name) ->
@ -22,5 +25,24 @@ exports.addCommand = (command, description, action) ->
exports.addOption = (option, description, coerceFunction) ->
program.option(option, description, coerceFunction)
exports.addResource = (name, displayName, actions = {}) ->
displayName ?= name
nameArticle = indefiniteArticle(displayName)
pluralizedName = pluralize(name)
pluralizedDisplayName = pluralize(displayName)
if _.isFunction(actions.create)
exports.addCommand("#{name}:create <name>", "create #{nameArticle} #{displayName}", actions.create)
if _.isFunction(actions.list)
exports.addCommand("#{pluralizedName}", "list all #{pluralizedDisplayName}", actions.list)
if _.isFunction(actions.info)
exports.addCommand("#{name} <id>", "list a single #{displayName}", actions.info)
if _.isFunction(actions.remove)
exports.addCommand("#{name}:rm <id>", "remove #{nameArticle} #{displayName}", actions.remove)
exports.parse = (argv) ->
program.parse(argv)

View File

@ -3,9 +3,9 @@
"version": "0.0.1",
"description": "Git Push to your devices",
"main": "./lib/app.js",
"bin": {
"resin": "./bin/resin"
},
"bin": {
"resin": "./bin/resin"
},
"scripts": {
"test": "cult test"
},
@ -48,6 +48,8 @@
"cliff": "~0.1.9",
"underscore.string": "~2.4.0",
"typed-error": "~0.1.0",
"is-online": "~3.0.0"
"is-online": "~3.0.0",
"pluralize": "~1.1.0",
"indefinite-article": "0.0.2"
}
}