Namespace actions with an actions object

This commit is contained in:
Juan Cruz Viotti 2014-11-26 15:11:34 -04:00
parent 7f01cae064
commit 86ecf5b1b6
2 changed files with 25 additions and 29 deletions

7
lib/actions/index.coffee Normal file
View File

@ -0,0 +1,7 @@
module.exports =
app: require('./app')
auth: require('./auth')
device: require('./device')
env: require('./environment-variables')
keys: require('./keys')
preferences: require('./preferences')

View File

@ -1,6 +1,7 @@
_ = require('lodash')
resin = require('./resin')
packageJSON = require('../package.json')
actions = require('./actions')
resin.cli.setVersion(packageJSON.version)
@ -15,45 +16,33 @@ resin.cli.addOption('-t, --type <type>', 'specify a type when creating an applic
resin.cli.addOption('-a, --application <app>', 'application id', _.parseInt)
# ---------- Auth Module ----------
auth = require('./actions/auth')
resin.cli.addCommand('login [username:password]', 'login to resin.io', auth.login)
resin.cli.addCommand('logout', 'logout from resin.io', auth.logout)
resin.cli.addCommand('signup', 'signup to resin.io', auth.signup)
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)
# ---------- App Module ----------
app = require('./actions/app')
resin.cli.addCommand('app:create <name>', 'create a resin.io application', app.create)
resin.cli.addCommand('apps', 'list your applications', app.list)
resin.cli.addCommand('app <id>', 'list a single application', app.info)
resin.cli.addCommand('app:restart <id>', 'restart an application', app.restart)
resin.cli.addCommand('app:rm <id>', 'remove an application', app.remove)
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.addCommand('app:restart <id>', 'restart an application', actions.app.restart)
resin.cli.addCommand('app:rm <id>', 'remove an application', actions.app.remove)
# ---------- Device Module ----------
device = require('./actions/device')
resin.cli.addCommand('devices <id>', 'show devices for an application', device.list)
resin.cli.addCommand('device:rm <id>', 'remove a device', device.remove)
resin.cli.addCommand('device:identify <uuid>', 'identify a device with a UUID', device.identify)
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.addCommand('device:identify <uuid>', 'identify a device with a UUID', actions.device.identify)
# ---------- Preferences Module ----------
preferences = require('./actions/preferences')
resin.cli.addCommand('preferences', 'open preferences form', preferences.preferences)
resin.cli.addCommand('preferences', 'open preferences form', actions.preferences.preferences)
# ---------- Keys Module ----------
keys = require('./actions/keys')
resin.cli.addCommand('keys', 'list all SSH keys', keys.list)
resin.cli.addCommand('key <id>', 'list a single SSH key', keys.info)
resin.cli.addCommand('key:rm <id>', 'remove a SSH key', keys.remove)
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)
# ---------- Env Module ----------
env = require('./actions/environment-variables')
resin.cli.addCommand('envs', 'list all environment variables', env.list)
resin.cli.addCommand('env:rm <id>', 'remove environment variable', env.remove)
resin.cli.addCommand('envs', 'list all environment variables', actions.env.list)
resin.cli.addCommand('env:rm <id>', 'remove environment variable', actions.env.remove)
resin.data.prefix.set resin.config.dataPrefix, (error) ->
resin.errors.handle(error) if error?