balena-cli/lib/actions/plugin.coffee

95 lines
2.2 KiB
CoffeeScript
Raw Normal View History

2015-02-12 13:41:25 +00:00
_ = require('lodash')
visuals = require('resin-cli-visuals')
2015-02-12 16:50:40 +00:00
commandOptions = require('./command-options')
2015-02-12 17:09:45 +00:00
plugins = require('../plugins')
2015-02-12 13:41:25 +00:00
exports.list =
signature: 'plugins'
description: 'list all plugins'
help: '''
Use this command to list all the installed resin plugins.
Examples:
2015-02-12 13:41:25 +00:00
$ resin plugins
'''
permission: 'user'
action: (params, options, done) ->
2015-02-24 17:36:10 +00:00
plugins.list (error, resinPlugins) ->
2015-02-12 17:09:45 +00:00
return done(error) if error?
2015-02-12 16:23:01 +00:00
2015-02-12 17:09:45 +00:00
if _.isEmpty(resinPlugins)
console.log('You don\'t have any plugins yet')
return done()
2015-02-12 13:41:25 +00:00
2015-02-12 17:09:45 +00:00
console.log visuals.widgets.table.horizontal resinPlugins, [
'name'
'version'
'description'
'license'
]
2015-02-12 13:41:25 +00:00
2015-02-12 17:09:45 +00:00
return done()
2015-02-12 16:23:01 +00:00
exports.install =
signature: 'plugin install <name>'
description: 'install a plugin'
help: '''
Use this command to install a resin plugin
Use `--quiet` to prevent information logging.
2015-02-12 16:23:01 +00:00
Examples:
2015-02-12 16:23:01 +00:00
$ resin plugin install hello
'''
permission: 'user'
action: (params, options, done) ->
2015-02-24 17:36:10 +00:00
plugins.install params.name, (error) ->
2015-02-12 17:09:45 +00:00
return done(error) if error?
2015-02-24 17:36:10 +00:00
console.info("Plugin installed: #{params.name}")
2015-02-12 17:09:45 +00:00
return done()
2015-02-12 16:50:40 +00:00
2015-03-02 14:41:08 +00:00
exports.update =
signature: 'plugin update <name>'
description: 'update a plugin'
help: '''
Use this command to update a resin plugin
Use `--quiet` to prevent information logging.
Examples:
2015-03-02 14:41:08 +00:00
$ resin plugin update hello
'''
permission: 'user'
action: (params, options, done) ->
plugins.update params.name, (error, version) ->
return done(error) if error?
console.info("Plugin updated: #{params.name}@#{version}")
return done()
2015-02-12 16:50:40 +00:00
exports.remove =
signature: 'plugin rm <name>'
description: 'remove a plugin'
help: '''
Use this command to remove a resin.io plugin.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
2015-02-12 16:50:40 +00:00
$ resin plugin rm hello
$ resin plugin rm hello --yes
'''
options: [ commandOptions.yes ]
permission: 'user'
action: (params, options, done) ->
2015-02-12 17:09:45 +00:00
visuals.patterns.remove 'plugin', options.yes, (callback) ->
2015-02-24 17:36:10 +00:00
plugins.remove(params.name, callback)
, (error) ->
2015-02-12 17:09:45 +00:00
return done(error) if error?
2015-02-24 17:36:10 +00:00
console.info("Plugin removed: #{params.name}")
2015-02-12 17:09:45 +00:00
return done()