mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-03 04:26:39 +00:00
Option based addOption/addCommand/addResource
This commit is contained in:
parent
a5791d080f
commit
507ff16050
@ -6,36 +6,84 @@ actions = require('./actions')
|
|||||||
resin.cli.setVersion(packageJSON.version)
|
resin.cli.setVersion(packageJSON.version)
|
||||||
|
|
||||||
# ---------- Options ----------
|
# ---------- Options ----------
|
||||||
resin.cli.addOption('-y, --yes', 'confirm non interactively')
|
resin.cli.addOption
|
||||||
resin.cli.addOption('-v, --verbose', 'increase verbosity')
|
option: '-y, --yes'
|
||||||
resin.cli.addOption('-q, --quiet', 'quiet (no output)')
|
description: 'confirm non interactively'
|
||||||
resin.cli.addOption('-t, --type <type>', 'specify a type when creating an application')
|
|
||||||
|
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 <type>'
|
||||||
|
description: '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
|
||||||
resin.cli.addOption('-a, --application <app>', 'application id', _.parseInt)
|
resin.cli.addOption
|
||||||
|
option: '-a, --application <app>'
|
||||||
|
description: 'application id'
|
||||||
|
coerce: _.parseInt
|
||||||
|
|
||||||
# ---------- Auth Module ----------
|
# ---------- Auth Module ----------
|
||||||
resin.cli.addCommand('login [username:password]', 'login to resin.io', actions.auth.login)
|
resin.cli.addCommand
|
||||||
resin.cli.addCommand('logout', 'logout from resin.io', actions.auth.logout)
|
command: 'login [username:password]'
|
||||||
resin.cli.addCommand('signup', 'signup to resin.io', actions.auth.signup)
|
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 ----------
|
# ---------- App Module ----------
|
||||||
resin.cli.addResource('app', 'application', actions.app)
|
resin.cli.addResource
|
||||||
resin.cli.addCommand('app:restart <id>', 'restart an application', actions.app.restart)
|
name: 'app'
|
||||||
|
displayName: 'application'
|
||||||
|
actions: actions.app
|
||||||
|
|
||||||
|
resin.cli.addCommand
|
||||||
|
command: 'app:restart <id>'
|
||||||
|
description: 'restart an application'
|
||||||
|
action: actions.app.restart
|
||||||
|
|
||||||
# ---------- Device Module ----------
|
# ---------- Device Module ----------
|
||||||
resin.cli.addResource('device', 'device', actions.device)
|
resin.cli.addResource
|
||||||
resin.cli.addCommand('device:identify <uuid>', 'identify a device with a UUID', actions.device.identify)
|
name: 'device'
|
||||||
|
displayName: 'device'
|
||||||
|
actions: actions.device
|
||||||
|
|
||||||
|
resin.cli.addCommand
|
||||||
|
command: 'device:identify <uuid>'
|
||||||
|
description: 'identify a device with a UUID'
|
||||||
|
action: actions.device.identify
|
||||||
|
|
||||||
# ---------- Preferences Module ----------
|
# ---------- 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 ----------
|
# ---------- Keys Module ----------
|
||||||
resin.cli.addResource('key', 'ssh key', actions.keys)
|
resin.cli.addResource
|
||||||
|
name: 'key'
|
||||||
|
displayName: 'ssh key'
|
||||||
|
actions: actions.keys
|
||||||
|
|
||||||
# ---------- Env Module ----------
|
# ---------- 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.data.prefix.set resin.config.dataPrefix, (error) ->
|
||||||
resin.errors.handle(error) if error?
|
resin.errors.handle(error) if error?
|
||||||
|
@ -11,38 +11,53 @@ exports.setVersion = (version) ->
|
|||||||
program.version(version)
|
program.version(version)
|
||||||
|
|
||||||
# Set version command automatically
|
# Set version command automatically
|
||||||
exports.addCommand 'version', 'show version', ->
|
exports.addCommand
|
||||||
|
command: 'version'
|
||||||
|
description: 'show version'
|
||||||
|
action: ->
|
||||||
log.out(version)
|
log.out(version)
|
||||||
|
|
||||||
exports.addCommand = (command, description, action) ->
|
exports.addCommand = (options = {}) ->
|
||||||
program
|
program
|
||||||
.command(command)
|
.command(options.command)
|
||||||
.description(description)
|
.description(options.description)
|
||||||
.action(action)
|
.action(options.action)
|
||||||
|
|
||||||
return program
|
return program
|
||||||
|
|
||||||
exports.addOption = (option, description, coerceFunction) ->
|
exports.addOption = (options = {}) ->
|
||||||
program.option(option, description, coerceFunction)
|
program.option(options.option, options.description, options.coerce)
|
||||||
|
|
||||||
exports.addResource = (name, displayName, actions = {}) ->
|
exports.addResource = (options = {}) ->
|
||||||
displayName ?= name
|
options.displayName ?= options.name
|
||||||
nameArticle = indefiniteArticle(displayName)
|
nameArticle = indefiniteArticle(options.displayName)
|
||||||
|
|
||||||
pluralizedName = pluralize(name)
|
pluralizedName = pluralize(options.name)
|
||||||
pluralizedDisplayName = pluralize(displayName)
|
pluralizedDisplayName = pluralize(options.displayName)
|
||||||
|
|
||||||
if _.isFunction(actions.create)
|
if _.isFunction(options.actions.create)
|
||||||
exports.addCommand("#{name}:create <name>", "create #{nameArticle} #{displayName}", actions.create)
|
exports.addCommand
|
||||||
|
command: "#{options.name}:create <name>"
|
||||||
|
description: "create #{nameArticle} #{options.displayName}"
|
||||||
|
action: options.actions.create
|
||||||
|
|
||||||
if _.isFunction(actions.list)
|
if _.isFunction(options.actions.list)
|
||||||
exports.addCommand("#{pluralizedName}", "list all #{pluralizedDisplayName}", actions.list)
|
exports.addCommand
|
||||||
|
command: "#{pluralizedName}"
|
||||||
|
description: "list all #{pluralizedDisplayName}"
|
||||||
|
action: options.actions.list
|
||||||
|
|
||||||
if _.isFunction(actions.info)
|
if _.isFunction(options.actions.info)
|
||||||
exports.addCommand("#{name} <id>", "list a single #{displayName}", actions.info)
|
exports.addCommand
|
||||||
|
command: "#{options.name} <id>"
|
||||||
|
description: "list a single #{options.displayName}"
|
||||||
|
action: options.actions.info
|
||||||
|
|
||||||
if _.isFunction(actions.remove)
|
if _.isFunction(options.actions.remove)
|
||||||
exports.addCommand("#{name}:rm <id>", "remove #{nameArticle} #{displayName}", actions.remove)
|
exports.addCommand
|
||||||
|
command: "#{options.name}:rm <id>"
|
||||||
|
description: "remove #{nameArticle} #{options.displayName}"
|
||||||
|
action: options.actions.remove
|
||||||
|
|
||||||
exports.parse = (argv) ->
|
exports.parse = (argv) ->
|
||||||
program.parse(argv)
|
program.parse(argv)
|
||||||
|
Loading…
Reference in New Issue
Block a user