mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-03-10 22:44:14 +00:00
Implement resin/cli and decouple app.coffee from commander
This commit is contained in:
parent
cf4778f889
commit
7f01cae064
123
lib/app.coffee
123
lib/app.coffee
@ -2,130 +2,63 @@ _ = require('lodash')
|
|||||||
resin = require('./resin')
|
resin = require('./resin')
|
||||||
packageJSON = require('../package.json')
|
packageJSON = require('../package.json')
|
||||||
|
|
||||||
program = require('commander')
|
resin.cli.setVersion(packageJSON.version)
|
||||||
program.version(packageJSON.version)
|
|
||||||
|
|
||||||
# ---------- Options ----------
|
# ---------- Options ----------
|
||||||
program.option('-y, --yes', 'confirm non interactively')
|
resin.cli.addOption('-y, --yes', 'confirm non interactively')
|
||||||
program.option('-v, --verbose', 'increase verbosity')
|
resin.cli.addOption('-v, --verbose', 'increase verbosity')
|
||||||
program.option('-q, --quiet', 'quiet (no output)')
|
resin.cli.addOption('-q, --quiet', 'quiet (no output)')
|
||||||
program.option('-t, --type <type>', 'specify a type when creating an application')
|
resin.cli.addOption('-t, --type <type>', 'specify a type when creating an application')
|
||||||
|
|
||||||
# TODO: I have to use 'application' instead of 'app' here
|
# TODO: I have to use 'application' instead of 'app' here
|
||||||
# as Commander gets confused with the app command
|
# as Commander gets confused with the app command
|
||||||
program.option('-a, --application <app>', 'application id', _.parseInt)
|
resin.cli.addOption('-a, --application <app>', 'application id', _.parseInt)
|
||||||
|
|
||||||
# ---------- Auth Module ----------
|
# ---------- Auth Module ----------
|
||||||
auth = require('./actions/auth')
|
auth = require('./actions/auth')
|
||||||
|
|
||||||
program
|
resin.cli.addCommand('login [username:password]', 'login to resin.io', auth.login)
|
||||||
.command('login [username:password]')
|
resin.cli.addCommand('logout', 'logout from resin.io', auth.logout)
|
||||||
.description('Login to resin.io')
|
resin.cli.addCommand('signup', 'signup to resin.io', auth.signup)
|
||||||
.action(auth.login)
|
|
||||||
|
|
||||||
program
|
|
||||||
.command('logout')
|
|
||||||
.description('Logout from resin.io')
|
|
||||||
.action(auth.logout)
|
|
||||||
|
|
||||||
program
|
|
||||||
.command('signup')
|
|
||||||
.description('Signup to resin.io')
|
|
||||||
.action(auth.signup)
|
|
||||||
|
|
||||||
# ---------- App Module ----------
|
# ---------- App Module ----------
|
||||||
app = require('./actions/app')
|
app = require('./actions/app')
|
||||||
|
|
||||||
program
|
resin.cli.addCommand('app:create <name>', 'create a resin.io application', app.create)
|
||||||
.command('app:create <name>')
|
resin.cli.addCommand('apps', 'list your applications', app.list)
|
||||||
.description('Create a resin.io application')
|
resin.cli.addCommand('app <id>', 'list a single application', app.info)
|
||||||
.action(app.create)
|
resin.cli.addCommand('app:restart <id>', 'restart an application', app.restart)
|
||||||
|
resin.cli.addCommand('app:rm <id>', 'remove an application', app.remove)
|
||||||
program
|
|
||||||
.command('apps')
|
|
||||||
.description('List your applications')
|
|
||||||
.action(app.list)
|
|
||||||
|
|
||||||
program
|
|
||||||
.command('app <id>')
|
|
||||||
.description('List a single application')
|
|
||||||
.action(app.info)
|
|
||||||
|
|
||||||
program
|
|
||||||
.command('app:restart <id>')
|
|
||||||
.description('Restart an application')
|
|
||||||
.action(app.restart)
|
|
||||||
|
|
||||||
program
|
|
||||||
.command('app:rm <id>')
|
|
||||||
.description('Remove an application')
|
|
||||||
.action(app.remove)
|
|
||||||
|
|
||||||
# ---------- Device Module ----------
|
# ---------- Device Module ----------
|
||||||
device = require('./actions/device')
|
device = require('./actions/device')
|
||||||
|
|
||||||
program
|
resin.cli.addCommand('devices <id>', 'show devices for an application', device.list)
|
||||||
.command('devices <id>')
|
resin.cli.addCommand('device:rm <id>', 'remove a device', device.remove)
|
||||||
.description('Show devices for an application')
|
resin.cli.addCommand('device:identify <uuid>', 'identify a device with a UUID', device.identify)
|
||||||
.action(device.list)
|
|
||||||
|
|
||||||
program
|
|
||||||
.command('device:rm <id>')
|
|
||||||
.description('Remove a device')
|
|
||||||
.action(device.remove)
|
|
||||||
|
|
||||||
program
|
|
||||||
.command('device:identify <uuid>')
|
|
||||||
.description('Identify a device with a UUID')
|
|
||||||
.action(device.identify)
|
|
||||||
|
|
||||||
# ---------- Preferences Module ----------
|
# ---------- Preferences Module ----------
|
||||||
preferences = require('./actions/preferences')
|
preferences = require('./actions/preferences')
|
||||||
|
|
||||||
program
|
resin.cli.addCommand('preferences', 'open preferences form', preferences.preferences)
|
||||||
.command('preferences')
|
|
||||||
.description('Open preferences form')
|
|
||||||
.action(preferences.preferences)
|
|
||||||
|
|
||||||
# ---------- Info Module ----------
|
|
||||||
program
|
|
||||||
.command('version')
|
|
||||||
.description('Show version')
|
|
||||||
.action ->
|
|
||||||
resin.log.out(packageJSON.version)
|
|
||||||
|
|
||||||
# ---------- Keys Module ----------
|
# ---------- Keys Module ----------
|
||||||
keys = require('./actions/keys')
|
keys = require('./actions/keys')
|
||||||
|
|
||||||
program
|
resin.cli.addCommand('keys', 'list all SSH keys', keys.list)
|
||||||
.command('keys')
|
resin.cli.addCommand('key <id>', 'list a single SSH key', keys.info)
|
||||||
.description('List all SSH keys')
|
resin.cli.addCommand('key:rm <id>', 'remove a SSH key', keys.remove)
|
||||||
.action(keys.list)
|
|
||||||
|
|
||||||
program
|
|
||||||
.command('key <id>')
|
|
||||||
.description('List a single SSH key')
|
|
||||||
.action(keys.info)
|
|
||||||
|
|
||||||
program
|
|
||||||
.command('key:rm <id>')
|
|
||||||
.description('Remove a SSH key')
|
|
||||||
.action(keys.remove)
|
|
||||||
|
|
||||||
# ---------- Env Module ----------
|
# ---------- Env Module ----------
|
||||||
env = require('./actions/environment-variables')
|
env = require('./actions/environment-variables')
|
||||||
|
|
||||||
program
|
resin.cli.addCommand('envs', 'list all environment variables', env.list)
|
||||||
.command('envs')
|
resin.cli.addCommand('env:rm <id>', 'remove environment variable', env.remove)
|
||||||
.description('List all environment variables')
|
|
||||||
.action(env.list)
|
|
||||||
|
|
||||||
program
|
|
||||||
.command('env:rm <id>')
|
|
||||||
.description('Remove environment variable')
|
|
||||||
.action(env.remove)
|
|
||||||
|
|
||||||
resin.data.prefix.set resin.config.dataPrefix, (error) ->
|
resin.data.prefix.set resin.config.dataPrefix, (error) ->
|
||||||
resin.errors.handle(error) if error?
|
resin.errors.handle(error) if error?
|
||||||
program.parse(process.argv)
|
|
||||||
resin.log.setQuiet(program.quiet)
|
resin.cli.parse(process.argv)
|
||||||
|
|
||||||
|
quiet = resin.cli.getArgument('quiet')
|
||||||
|
resin.log.setQuiet(quiet)
|
||||||
|
26
lib/resin/cli/cli.coffee
Normal file
26
lib/resin/cli/cli.coffee
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
program = require('commander')
|
||||||
|
log = require('../log/log')
|
||||||
|
|
||||||
|
exports.getArgument = (name) ->
|
||||||
|
return program[name]
|
||||||
|
|
||||||
|
exports.setVersion = (version) ->
|
||||||
|
program.version(version)
|
||||||
|
|
||||||
|
# Set version command automatically
|
||||||
|
exports.addCommand 'version', 'show version', ->
|
||||||
|
log.out(version)
|
||||||
|
|
||||||
|
exports.addCommand = (command, description, action) ->
|
||||||
|
program
|
||||||
|
.command(command)
|
||||||
|
.description(description)
|
||||||
|
.action(action)
|
||||||
|
|
||||||
|
return program
|
||||||
|
|
||||||
|
exports.addOption = (option, description, coerceFunction) ->
|
||||||
|
program.option(option, description, coerceFunction)
|
||||||
|
|
||||||
|
exports.parse = (argv) ->
|
||||||
|
program.parse(argv)
|
@ -8,4 +8,5 @@ module.exports =
|
|||||||
auth: require('./auth/auth')
|
auth: require('./auth/auth')
|
||||||
device: require('./device/device')
|
device: require('./device/device')
|
||||||
ui: require('./ui')
|
ui: require('./ui')
|
||||||
|
cli: require('./cli/cli')
|
||||||
config: require('./config')
|
config: require('./config')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user