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-07-27 12:08:55 +00:00
|
|
|
form = require('resin-cli-form')
|
|
|
|
async = require('async')
|
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-03-03 14:14:16 +00:00
|
|
|
|
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-07-29 13:34:31 +00:00
|
|
|
console.log visuals.table.horizontal resinPlugins, [
|
2015-02-12 17:09:45 +00:00
|
|
|
'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
|
|
|
|
|
2015-03-02 14:41:38 +00:00
|
|
|
Use `--quiet` to prevent information logging.
|
|
|
|
|
2015-02-12 16:23:01 +00:00
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
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-03 14:14:16 +00:00
|
|
|
|
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-03-03 14:14:16 +00:00
|
|
|
|
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-07-27 12:08:55 +00:00
|
|
|
async.waterfall [
|
|
|
|
|
|
|
|
(callback) ->
|
|
|
|
if options.yes
|
|
|
|
return callback(null, true)
|
|
|
|
else
|
|
|
|
form.ask
|
|
|
|
message: 'Are you sure you want to delete the plugin?'
|
|
|
|
type: 'confirm'
|
|
|
|
default: false
|
|
|
|
.nodeify(callback)
|
|
|
|
|
|
|
|
(confirmed, callback) ->
|
|
|
|
return callback() if not confirmed
|
|
|
|
plugins.remove(params.name, callback)
|
2015-02-24 17:36:10 +00:00
|
|
|
, (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()
|
2015-07-27 12:08:55 +00:00
|
|
|
]
|