Move command declarations next to their definitions

This commit is contained in:
Juan Cruz Viotti 2015-01-15 14:10:14 -03:00
parent f94be29047
commit 5abc4e550f
14 changed files with 791 additions and 812 deletions

View File

@ -3,75 +3,155 @@ async = require('async')
resin = require('resin-sdk')
ui = require('../ui')
permissions = require('../permissions/permissions')
commandOptions = require('./command-options')
exports.create = permissions.user (params, options, done) ->
async.waterfall([
exports.create =
signature: 'app create <name>'
description: 'create an application'
help: '''
Use this command to create a new resin.io application.
(callback) ->
deviceType = options.type
You can specify the application type with the `--type` option.
Otherwise, an interactive dropdown will be shown for you to select from.
if deviceType?
return callback(null, deviceType)
else
deviceTypes = resin.models.device.getSupportedDeviceTypes()
ui.widgets.select('Select a type', deviceTypes, callback)
You can see a list of supported device types with
$ resin devices supported
(type, callback) ->
resin.models.application.create(params.name, type, callback)
Examples:
$ resin app create MyApp
$ resin app create MyApp --type raspberry-pi
'''
options: [
{
signature: 'type'
parameter: 'type'
description: 'application type'
alias: 't'
}
]
action: permissions.user (params, options, done) ->
async.waterfall([
], done)
(callback) ->
deviceType = options.type
exports.list = permissions.user (params, options, done) ->
resin.models.application.getAll (error, applications) ->
return done(error) if error?
console.log ui.widgets.table.horizontal applications, [
'ID'
'Name'
'Device Display Name'
'Online Devices'
'Devices Length'
]
return done()
if deviceType?
return callback(null, deviceType)
else
deviceTypes = resin.models.device.getSupportedDeviceTypes()
ui.widgets.select('Select a type', deviceTypes, callback)
exports.info = permissions.user (params, options, done) ->
resin.models.application.get params.id, (error, application) ->
return done(error) if error?
console.log ui.widgets.table.vertical application, [
'ID'
'Name'
'Device Display Name'
'Git Repository'
'Commit'
]
return done()
(type, callback) ->
resin.models.application.create(params.name, type, callback)
exports.restart = permissions.user (params, options, done) ->
resin.models.application.restart(params.id, done)
], done)
exports.remove = permissions.user (params, options, done) ->
ui.patterns.remove 'application', options.yes, (callback) ->
resin.models.application.remove(params.id, callback)
, done
exports.list =
signature: 'apps'
description: 'list all applications'
help: '''
Use this command to list all your applications.
exports.init = permissions.user (params, options, done) ->
Notice this command only shows the most important bits of information for each app.
If you want detailed information, use resin app <id> instead.
currentDirectory = process.cwd()
Examples:
$ resin apps
'''
action: permissions.user (params, options, done) ->
resin.models.application.getAll (error, applications) ->
return done(error) if error?
console.log ui.widgets.table.horizontal applications, [
'ID'
'Name'
'Device Display Name'
'Online Devices'
'Devices Length'
]
return done()
async.waterfall [
exports.info =
signature: 'app <id>'
description: 'list a single application'
help: '''
Use this command to show detailed information for a single application.
(callback) ->
resin.vcs.isResinProject(currentDirectory, callback)
Examples:
$ resin app 91
'''
action: permissions.user (params, options, done) ->
resin.models.application.get params.id, (error, application) ->
return done(error) if error?
console.log ui.widgets.table.vertical application, [
'ID'
'Name'
'Device Display Name'
'Git Repository'
'Commit'
]
return done()
(isResinProject, callback) ->
if isResinProject
error = new Error('Project is already a resin application.')
return callback(error)
return callback()
exports.restart =
signature: 'app restart <id>'
description: 'restart an application'
help: '''
Use this command to restart all devices that belongs to a certain application.
(callback) ->
resin.models.application.get(params.id, callback)
Examples:
$ resin app restart 91
'''
action: permissions.user (params, options, done) ->
resin.models.application.restart(params.id, done)
(application, callback) ->
resin.vcs.initProjectWithApplication(application, currentDirectory, callback)
exports.remove =
signature: 'app rm <id>'
description: 'remove an application'
help: '''
Use this command to remove a resin.io application.
], done
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin app rm 91
$ resin app rm 91 --yes
'''
options: [ commandOptions.yes ]
action: permissions.user (params, options, done) ->
ui.patterns.remove 'application', options.yes, (callback) ->
resin.models.application.remove(params.id, callback)
, done
exports.init =
signature: 'init <id>'
description: 'init an application'
help: '''
Use this command to associate a local project to an existing resin.io application.
The application should be a git repository before issuing this command.
Notice this command adds a `resin` git remote to your application.
Examples:
$ cd myApp && resin init 91
'''
action: permissions.user (params, options, done) ->
currentDirectory = process.cwd()
async.waterfall [
(callback) ->
resin.vcs.isResinProject(currentDirectory, callback)
(isResinProject, callback) ->
if isResinProject
error = new Error('Project is already a resin application.')
return callback(error)
return callback()
(callback) ->
resin.models.application.get(params.id, callback)
(application, callback) ->
resin.vcs.initProjectWithApplication(application, currentDirectory, callback)
], done

View File

@ -6,42 +6,94 @@ ui = require('../ui')
permissions = require('../permissions/permissions')
helpers = require('../helpers/helpers')
exports.login = (params, options, done) ->
async.waterfall [
exports.login =
signature: 'login [credentials]'
description: 'login to resin.io'
help: '''
Use this command to login to your resin.io account.
You need to login before you can use most of the commands this tool provides.
(callback) ->
if params.credentials?
return helpers.parseCredentials(params.credentials, callback)
else
return ui.widgets.login(callback)
You can pass your credentials as a colon separated string, or you can omit the
credentials, in which case the tool will present you with an interactive login form.
(credentials, callback) ->
resin.auth.login(credentials, callback)
Examples:
$ resin login username:password
$ resin login
'''
action: (params, options, done) ->
async.waterfall [
], done
(callback) ->
if params.credentials?
return helpers.parseCredentials(params.credentials, callback)
else
return ui.widgets.login(callback)
exports.logout = permissions.user (params, options, done) ->
resin.auth.logout(done)
(credentials, callback) ->
resin.auth.login(credentials, callback)
exports.signup = (params, options, done) ->
async.waterfall([
], done
(callback) ->
ui.widgets.register(callback)
exports.logout =
signature: 'logout'
description: 'logout from resin.io'
help: '''
Use this command to logout from your resin.io account.o
(credentials, callback) ->
resin.auth.register credentials, (error, token) ->
return callback(error, credentials)
Examples:
$ resin logout
'''
action: permissions.user (params, options, done) ->
resin.auth.logout(done)
(credentials, callback) ->
resin.auth.login(credentials, callback)
exports.signup =
signature: 'signup'
description: 'signup to resin.io'
help: '''
Use this command to signup for a resin.io account.
], done)
If signup is successful, you'll be logged in to your new user automatically.
exports.whoami = permissions.user (params, options, done) ->
resin.auth.whoami (error, username) ->
TODO: We need to provide a non interactive way to use this command,
however it's not clear to me how to do it easily for now.
if not username?
return done(new Error('Username not found'))
Examples:
$ resin signup
Email: me@mycompany.com
Username: johndoe
Password: ***********
console.log(username)
$ resin whoami
johndoe
'''
action: (params, options, done) ->
async.waterfall([
(callback) ->
ui.widgets.register(callback)
(credentials, callback) ->
resin.auth.register credentials, (error, token) ->
return callback(error, credentials)
(credentials, callback) ->
resin.auth.login(credentials, callback)
], done)
exports.whoami =
signature: 'whoami'
description: 'get current username'
help: '''
Use this command to find out the current logged in username.
Examples:
$ resin whoami
'''
action: permissions.user (params, options, done) ->
resin.auth.whoami (error, username) ->
if not username?
return done(new Error('Username not found'))
console.log(username)

View File

@ -0,0 +1,12 @@
exports.yes =
signature: 'yes'
description: 'confirm non interactively'
boolean: true
alias: 'y'
exports.application =
signature: 'application'
parameter: 'application'
description: 'application id'
alias: [ 'a', 'app' ]
required: 'You have to specify an application'

View File

@ -3,64 +3,130 @@ async = require('async')
resin = require('resin-sdk')
ui = require('../ui')
permissions = require('../permissions/permissions')
commandOptions = require('./command-options')
exports.list = permissions.user (params, options, done) ->
resin.models.device.getAllByApplication options.application, (error, devices) ->
return done(error) if error?
console.log ui.widgets.table.horizontal devices, [
'ID'
'Name'
'Device Display Name'
'Is Online'
'Application Name'
'Status'
'Last Seen'
]
exports.list =
signature: 'devices'
description: 'list all devices'
help: '''
Use this command to list all devices that belong to a certain application.
return done()
Examples:
$ resin devices --application 91
'''
options: [ commandOptions.application ]
action: permissions.user (params, options, done) ->
resin.models.device.getAllByApplication options.application, (error, devices) ->
return done(error) if error?
console.log ui.widgets.table.horizontal devices, [
'ID'
'Name'
'Device Display Name'
'Is Online'
'Application Name'
'Status'
'Last Seen'
]
exports.info = permissions.user (params, options, done) ->
resin.models.device.get params.id, (error, device) ->
return done(error) if error?
console.log ui.widgets.table.vertical device, [
'ID'
'Name'
'Device Display Name'
'Is Online'
'IP Address'
'Application Name'
'Status'
'Last Seen'
'UUID'
'Commit'
'Supervisor Version'
'Is Web Accessible'
'Note'
]
return done()
return done()
exports.info =
signature: 'device <id>'
description: 'list a single device'
help: '''
Use this command to show information about a single device.
exports.remove = permissions.user (params, options, done) ->
ui.patterns.remove 'device', options.yes, (callback) ->
resin.models.device.remove(params.id, callback)
, done
Examples:
$ resin device 317
'''
action: permissions.user (params, options, done) ->
resin.models.device.get params.id, (error, device) ->
return done(error) if error?
console.log ui.widgets.table.vertical device, [
'ID'
'Name'
'Device Display Name'
'Is Online'
'IP Address'
'Application Name'
'Status'
'Last Seen'
'UUID'
'Commit'
'Supervisor Version'
'Is Web Accessible'
'Note'
]
exports.identify = permissions.user (params, options, done) ->
resin.models.device.identify(params.uuid, done)
return done()
exports.rename = permissions.user (params, options, done) ->
async.waterfall [
exports.remove =
signature: 'device rm <id>'
description: 'remove a device'
help: '''
Use this command to remove a device from resin.io.
(callback) ->
if not _.isEmpty(params.name)
return callback(null, params.name)
ui.widgets.ask('How do you want to name this device?', callback)
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
(name, callback) ->
resin.models.device.rename(params.id, name, callback)
Examples:
$ resin device rm 317
$ resin device rm 317 --yes
'''
options: [ commandOptions.yes ]
action: permissions.user (params, options, done) ->
ui.patterns.remove 'device', options.yes, (callback) ->
resin.models.device.remove(params.id, callback)
, done
], done
exports.identify =
signature: 'device identify <uuid>'
description: 'identify a device with a UUID'
help: '''
Use this command to identify a device.
exports.supported = permissions.user ->
devices = resin.models.device.getSupportedDeviceTypes()
_.each(devices, _.unary(console.log))
In the Raspberry Pi, the ACT led is blinked several times.
Examples:
$ resin device identify 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828
'''
action: permissions.user (params, options, done) ->
resin.models.device.identify(params.uuid, done)
exports.rename =
signature: 'device rename <id> [name]'
description: 'rename a resin device'
help: '''
Use this command to rename a device.
If you omit the name, you'll get asked for it interactively.
Examples:
$ resin device rename 317 MyPi
$ resin device rename 317
'''
action: permissions.user (params, options, done) ->
async.waterfall [
(callback) ->
if not _.isEmpty(params.name)
return callback(null, params.name)
ui.widgets.ask('How do you want to name this device?', callback)
(name, callback) ->
resin.models.device.rename(params.id, name, callback)
], done
exports.supported =
signature: 'devices supported'
description: 'list all supported devices'
help: '''
Use this command to get the list of all supported devices
Examples:
$ resin devices supported
'''
action: permissions.user ->
devices = resin.models.device.getSupportedDeviceTypes()
_.each(devices, _.unary(console.log))

View File

@ -2,32 +2,102 @@ _ = require('lodash-contrib')
resin = require('resin-sdk')
ui = require('../ui')
permissions = require('../permissions/permissions')
commandOptions = require('./command-options')
exports.list = permissions.user (params, options, done) ->
resin.models.environmentVariables.getAllByApplication options.application, (error, environmentVariables) ->
return done(error) if error?
exports.list =
signature: 'envs'
description: 'list all environment variables'
help: '''
Use this command to list all environment variables for a particular application.
Notice we will support per-device environment variables soon.
if not options.verbose
environmentVariables = _.reject(environmentVariables, resin.models.environmentVariables.isSystemVariable)
This command lists all custom environment variables set on the devices running
the application. If you want to see all environment variables, including private
ones used by resin, use the verbose option.
console.log(ui.widgets.table.horizontal(environmentVariables))
return done()
Example:
$ resin envs --application 91
$ resin envs --application 91 --verbose
'''
options: [
commandOptions.application
exports.remove = permissions.user (params, options, done) ->
ui.patterns.remove 'environment variable', options.yes, (callback) ->
resin.models.environmentVariables.remove(params.id, callback)
, done
{
signature: 'verbose'
description: 'show private environment variables'
boolean: true
alias: 'v'
}
]
action: permissions.user (params, options, done) ->
resin.models.environmentVariables.getAllByApplication options.application, (error, environmentVariables) ->
return done(error) if error?
exports.add = permissions.user (params, options, done) ->
if not params.value?
params.value = process.env[params.key]
if not options.verbose
environmentVariables = _.reject(environmentVariables, resin.models.environmentVariables.isSystemVariable)
console.log(ui.widgets.table.horizontal(environmentVariables))
return done()
exports.remove =
signature: 'env rm <id>'
description: 'remove an environment variable'
help: '''
Use this command to remove an environment variable from an application.
Don't remove resin specific variables, as things might not work as expected.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin env rm 215
$ resin env rm 215 --yes
'''
options: [ commandOptions.yes ]
action: permissions.user (params, options, done) ->
ui.patterns.remove 'environment variable', options.yes, (callback) ->
resin.models.environmentVariables.remove(params.id, callback)
, done
exports.add =
signature: 'env add <key> [value]'
description: 'add an environment variable'
help: '''
Use this command to add an enviroment variable to an application.
You need to pass the `--application` option.
If value is omitted, the tool will attempt to use the variable's value
as defined in your host machine.
If the value is grabbed from the environment, a warning message will be printed.
Use `--quiet` to remove it.
Examples:
$ resin env add EDITOR vim -a 91
$ resin env add TERM -a 91
'''
options: [ commandOptions.application ]
action: permissions.user (params, options, done) ->
if not params.value?
return done(new Error("Environment value not found for key: #{params.key}"))
else
console.info("Warning: using #{params.key}=#{params.value} from host environment")
params.value = process.env[params.key]
resin.models.environmentVariables.create(options.application, params.key, params.value, done)
if not params.value?
return done(new Error("Environment value not found for key: #{params.key}"))
else
console.info("Warning: using #{params.key}=#{params.value} from host environment")
exports.rename = permissions.user (params, options, done) ->
resin.models.environmentVariables.update(params.id, params.value, done)
resin.models.environmentVariables.create(options.application, params.key, params.value, done)
exports.rename =
signature: 'env rename <id> <value>'
description: 'rename an environment variable'
help: '''
Use this command to rename an enviroment variable from an application.
Examples:
$ resin env rename 376 emacs
'''
action: permissions.user (params, options, done) ->
resin.models.environmentVariables.update(params.id, params.value, done)

View File

@ -8,61 +8,90 @@ permissions = require('../permissions/permissions')
ui = require('../ui')
examplesData = require('../data/examples.json')
exports.list = permissions.user ->
exports.list =
signature: 'examples'
description: 'list all example applications'
help: '''
Use this command to list available example applications from resin.io
examplesData = _.map examplesData, (example, index) ->
example.id = index + 1
return example
Example:
$ resin examples
'''
action: permissions.user ->
examplesData = _.map examplesData, (example, index) ->
example.id = index + 1
return example
examplesData = _.map examplesData, (example) ->
examplesData = _.map examplesData, (example) ->
example.author ?= 'Unknown'
return example
console.log ui.widgets.table.horizontal examplesData, [
'ID'
'Display Name'
'Repository'
'Author'
]
exports.info =
signature: 'example <id>'
description: 'list a single example application'
help: '''
Use this command to show information of a single example application
Example:
$ resin example 3
'''
action: permissions.user (params, options, done) ->
id = params.id - 1
example = examplesData[id]
if not example?
return done(new Error("Unknown example: #{id}"))
example.id = id
example.author ?= 'Unknown'
return example
console.log ui.widgets.table.horizontal examplesData, [
'ID'
'Display Name'
'Repository'
'Author'
]
console.log ui.widgets.table.vertical example, [
'ID'
'Display Name'
'Description'
'Author'
'Repository'
]
exports.info = permissions.user (params, options, done) ->
id = params.id - 1
example = examplesData[id]
return done()
if not example?
return done(new Error("Unknown example: #{id}"))
exports.clone =
signature: 'example clone <id>'
description: 'clone an example application'
help: '''
Use this command to clone an example application to the current directory
example.id = id
example.author ?= 'Unknown'
This command outputs information about the cloning process.
Use `--quiet` to remove that output.
console.log ui.widgets.table.vertical example, [
'ID'
'Display Name'
'Description'
'Author'
'Repository'
]
Example:
$ resin example clone 3
'''
action: permissions.user (params, options, done) ->
example = examplesData[params.id - 1]
return done()
if not example?
return done(new Error("Unknown example: #{id}"))
exports.clone = permissions.user (params, options, done) ->
example = examplesData[params.id - 1]
async.waterfall [
if not example?
return done(new Error("Unknown example: #{id}"))
(callback) ->
exampleAbsolutePath = path.join(process.cwd(), example.name)
async.waterfall [
fs.exists exampleAbsolutePath, (exists) ->
return callback() if not exists
error = new Error("Directory exists: #{example.name}")
return callback(error)
(callback) ->
exampleAbsolutePath = path.join(process.cwd(), example.name)
(callback) ->
console.info("Cloning #{example.display_name} to #{example.name}")
gitCli.Repository.clone(example.repository, example.name, callback)
fs.exists exampleAbsolutePath, (exists) ->
return callback() if not exists
error = new Error("Directory exists: #{example.name}")
return callback(error)
(callback) ->
console.info("Cloning #{example.display_name} to #{example.name}")
gitCli.Repository.clone(example.repository, example.name, callback)
], done
], done

View File

@ -110,8 +110,11 @@ exports.command = (params) ->
console.log()
exports.help = (params) ->
if params.command?
exports.command(arguments...)
else
exports.general(arguments...)
exports.help =
signature: 'help [command...]'
description: 'show help'
action: (params) ->
if params.command?
exports.command(arguments...)
else
exports.general(arguments...)

View File

@ -1,4 +1,7 @@
packageJSON = require('../../package.json')
exports.version = ->
console.log(packageJSON.version)
exports.version =
signature: 'version'
description: 'output the version number'
action: ->
console.log(packageJSON.version)

View File

@ -6,35 +6,81 @@ resin = require('resin-sdk')
helpers = require('../helpers/helpers')
ui = require('../ui')
permissions = require('../permissions/permissions')
commandOptions = require('./command-options')
exports.list = permissions.user (params, options, done) ->
resin.models.key.getAll (error, keys) ->
return done(error) if error?
console.log ui.widgets.table.horizontal keys, [ 'ID', 'Title' ]
return done()
exports.list =
signature: 'keys'
description: 'list all ssh keys'
help: '''
Use this command to list all your SSH keys.
exports.info = permissions.user (params, options, done) ->
resin.models.key.get params.id, (error, key) ->
return done(error) if error?
key.public_key = '\n' + _.str.chop(key.public_key, resin.settings.get('sshKeyWidth')).join('\n')
console.log(ui.widgets.table.vertical(key, [ 'ID', 'Title', 'Public Key' ]))
return done()
Examples:
$ resin keys
'''
action: permissions.user (params, options, done) ->
resin.models.key.getAll (error, keys) ->
return done(error) if error?
console.log ui.widgets.table.horizontal keys, [ 'ID', 'Title' ]
return done()
exports.remove = permissions.user (params, options, done) ->
ui.patterns.remove 'key', options.yes, (callback) ->
resin.models.key.remove(params.id, callback)
, done
exports.info =
signature: 'key <id>'
description: 'list a single ssh key'
help: '''
Use this command to show information about a single SSH key.
exports.add = permissions.user (params, options, done) ->
async.waterfall [
Examples:
$ resin key 17
'''
action: permissions.user (params, options, done) ->
resin.models.key.get params.id, (error, key) ->
return done(error) if error?
key.public_key = '\n' + _.str.chop(key.public_key, resin.settings.get('sshKeyWidth')).join('\n')
console.log(ui.widgets.table.vertical(key, [ 'ID', 'Title', 'Public Key' ]))
return done()
(callback) ->
if params.path?
fs.readFile(params.path, encoding: 'utf8', callback)
else
helpers.readStdin(callback)
exports.remove =
signature: 'key rm <id>'
description: 'remove a ssh key'
help: '''
Use this command to remove a SSH key from resin.io.
(key, callback) ->
resin.models.key.create(params.name, key, callback)
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
], done
Examples:
$ resin key rm 17
$ resin key rm 17 --yes
'''
options: [ commandOptions.yes ]
action: permissions.user (params, options, done) ->
ui.patterns.remove 'key', options.yes, (callback) ->
resin.models.key.remove(params.id, callback)
, done
exports.add =
signature: 'key add <name> [path]'
description: 'add a SSH key to resin.io'
help: '''
Use this command to associate a new SSH key with your account.
If `path` is omitted, the command will attempt
to read the SSH key from stdin.
Examples:
$ resin key add Main ~/.ssh/id_rsa.pub
$ cat ~/.ssh/id_rsa.pub | resin key add Main
'''
action: permissions.user (params, options, done) ->
async.waterfall [
(callback) ->
if params.path?
fs.readFile(params.path, encoding: 'utf8', callback)
else
helpers.readStdin(callback)
(key, callback) ->
resin.models.key.create(params.name, key, callback)
], done

View File

@ -4,12 +4,48 @@ permissions = require('../permissions/permissions')
LOGS_HISTORY_COUNT = 200
exports.logs = permissions.user (params, options, done) ->
exports.logs =
signature: 'logs <uuid>'
description: 'show device logs'
help: '''
Use this command to show logs for a specific device.
resin.logs.subscribe params.uuid, {
history: options.num or LOGS_HISTORY_COUNT
tail: options.tail
}, (error, message) ->
return done(error) if error?
_.each(message, console.log)
return done()
By default, the command prints all log messages and exit.
To limit the output to the n last lines, use the `--num` option along with a number.
This is similar to doing `resin logs <uuid> | tail -n X`.
To continuously stream output, and see new logs in real time, use the `--tail` option.
Note that for now you need to provide the whole UUID for this command to work correctly,
and the tool won't notice if you're using an invalid UUID.
This is due to some technical limitations that we plan to address soon.
Examples:
$ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828
$ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828 --num 20
$ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828 --tail
'''
options: [
{
signature: 'num'
parameter: 'num'
description: 'number of lines to display'
alias: 'n'
}
{
signature: 'tail'
description: 'continuously stream output'
boolean: true
alias: 't'
}
]
action: permissions.user (params, options, done) ->
resin.logs.subscribe params.uuid, {
history: options.num or LOGS_HISTORY_COUNT
tail: options.tail
}, (error, message) ->
return done(error) if error?
_.each(message, console.log)
return done()

View File

@ -3,15 +3,36 @@ permissions = require('../permissions/permissions')
helpers = require('../helpers/helpers')
resin = require('resin-sdk')
exports.set = permissions.user (params, options, done) ->
async.waterfall([
exports.set =
signature: 'note [note]'
description: 'set a device note'
help: '''
Use this command to set or update a device note.
(callback) ->
if not params.note?
return helpers.readStdin(callback)
return callback(null, params.note)
If note command isn't passed, the tool attempts to read from `stdin`.
(note, callback) ->
resin.models.device.note(options.device, note, callback)
To view the notes, use $ resin device <id>.
], done)
Examples:
$ resin note "My useful note" --device 317
$ cat note.txt | resin note --device 317
'''
options: [
signature: 'device'
parameter: 'device'
description: 'device id'
alias: [ 'd', 'dev' ]
required: 'You have to specify a device'
]
action: permissions.user (params, options, done) ->
async.waterfall([
(callback) ->
if not params.note?
return helpers.readStdin(callback)
return callback(null, params.note)
(note, callback) ->
resin.models.device.note(options.device, note, callback)
], done)

View File

@ -6,47 +6,93 @@ ProgressBar = require('progress')
resin = require('resin-sdk')
permissions = require('../permissions/permissions')
exports.download = (params, options, done) ->
exports.download =
signature: 'os download <id>'
description: 'download device OS'
help: '''
Use this command to download the device OS configured to a specific network.
osParams =
network: options.network
wifiSsid: options.ssid
wifiKey: options.key
appId: params.id
Ethernet:
You can setup the device OS to use ethernet by setting the `--network` option to "ethernet".
fileName = resin.models.os.generateCacheName(osParams)
Wifi:
You can setup the device OS to use wifi by setting the `--network` option to "wifi".
If you set "network" to "wifi", you will need to specify the `--ssid` and `--key` option as well.
outputFile = options.output or path.join(resin.settings.get('directories.os'), fileName)
By default, this command saved the downloaded image into a resin specific directory.
You can save it to a custom location by specifying the `--output` option.
async.waterfall [
Examples:
$ resin os download 91 --network ethernet
$ resin os download 91 --network wifi --ssid MyNetwork --key secreykey123
$ resin os download 91 --network ethernet --output ~/MyResinOS.zip
'''
options: [
{
signature: 'network'
parameter: 'network'
description: 'network type'
alias: 'n'
}
{
signature: 'ssid'
parameter: 'ssid'
description: 'wifi ssid, if network is wifi'
alias: 's'
}
{
signature: 'key'
parameter: 'key'
description: 'wifi key, if network is wifi'
alias: 'k'
}
{
signature: 'output'
parameter: 'output'
description: 'output file'
alias: 'o'
}
]
action: (params, options, done) ->
osParams =
network: options.network
wifiSsid: options.ssid
wifiKey: options.key
appId: params.id
(callback) ->
fileName = resin.models.os.generateCacheName(osParams)
# We need to ensure this directory exists
mkdirp path.dirname(outputFile), (error) ->
return callback(error)
outputFile = options.output or path.join(resin.settings.get('directories.os'), fileName)
(callback) ->
console.info("Destination file: #{outputFile}")
async.waterfall [
bar = null
received = 0
(callback) ->
resin.models.os.download osParams, outputFile, callback, (state) ->
# We need to ensure this directory exists
mkdirp path.dirname(outputFile), (error) ->
return callback(error)
# TODO: Allow quieting this progress bar
bar ?= new ProgressBar 'Downloading device OS [:bar] :percent :etas',
complete: '='
incomplete: ' '
width: 40
total: state.total
(callback) ->
console.info("Destination file: #{outputFile}")
return if bar.complete or not state?
bar = null
received = 0
bar.tick(state.received - received)
received = state.received
resin.models.os.download osParams, outputFile, callback, (state) ->
], (error) ->
return done(error) if error?
console.info("\nFinished downloading #{outputFile}")
return done()
# TODO: Allow quieting this progress bar
bar ?= new ProgressBar 'Downloading device OS [:bar] :percent :etas',
complete: '='
incomplete: ' '
width: 40
total: state.total
return if bar.complete or not state?
bar.tick(state.received - received)
received = state.received
], (error) ->
return done(error) if error?
console.info("\nFinished downloading #{outputFile}")
return done()

View File

@ -3,7 +3,19 @@ url = require('url')
resin = require('resin-sdk')
permissions = require('../permissions/permissions')
exports.preferences = permissions.user ->
preferencesUrl = resin.settings.get('urls.preferences')
absUrl = url.resolve(resin.settings.get('remoteUrl'), preferencesUrl)
open(absUrl)
exports.preferences =
signature: 'preferences'
description: 'open preferences form'
help: '''
Use this command to open the preferences form.
In the future, we will allow changing all preferences directly from the terminal.
For now, we open your default web browser and point it to the web based preferences form.
Examples:
$ resin preferences
'''
action: permissions.user ->
preferencesUrl = resin.settings.get('urls.preferences')
absUrl = url.resolve(resin.settings.get('remoteUrl'), preferencesUrl)
open(absUrl)

View File

@ -6,16 +6,6 @@ actions = require('./actions')
errors = require('./errors/errors')
plugin = require('./plugin/plugin')
capitano.command
signature: 'version'
description: 'output the version number'
action: actions.info.version
capitano.command
signature: 'help [command...]'
description: 'show help'
action: actions.help.help
capitano.command
signature: '*'
action: ->
@ -42,549 +32,62 @@ capitano.globalOption
description: 'disable colour highlighting'
boolean: true
yesOption =
signature: 'yes'
description: 'confirm non interactively'
boolean: true
alias: 'y'
# ---------- Info Module ----------
capitano.command(actions.info.version)
applicationOption =
signature: 'application'
parameter: 'application'
description: 'application id'
alias: [ 'a', 'app' ]
required: 'You have to specify an application'
deviceOption =
signature: 'device'
parameter: 'device'
description: 'device id'
alias: [ 'd', 'dev' ]
required: 'You have to specify a device'
# ---------- Help Module ----------
capitano.command(actions.help.help)
# ---------- Auth Module ----------
capitano.command
signature: 'login [credentials]'
description: 'login to resin.io'
help: '''
Use this command to login to your resin.io account.
You need to login before you can use most of the commands this tool provides.
You can pass your credentials as a colon separated string, or you can omit the
credentials, in which case the tool will present you with an interactive login form.
Examples:
$ resin login username:password
$ resin login
'''
action: actions.auth.login
capitano.command
signature: 'logout'
description: 'logout from resin.io'
help: '''
Use this command to logout from your resin.io account.o
Examples:
$ resin logout
'''
action: actions.auth.logout
capitano.command
signature: 'signup'
description: 'signup to resin.io'
help: '''
Use this command to signup for a resin.io account.
If signup is successful, you'll be logged in to your new user automatically.
TODO: We need to provide a non interactive way to use this command,
however it's not clear to me how to do it easily for now.
Examples:
$ resin signup
Email: me@mycompany.com
Username: johndoe
Password: ***********
$ resin whoami
johndoe
'''
action: actions.auth.signup
capitano.command
signature: 'whoami'
description: 'get current username'
help: '''
Use this command to find out the current logged in username.
Examples:
$ resin whoami
'''
action: actions.auth.whoami
capitano.command(actions.auth.login)
capitano.command(actions.auth.logout)
capitano.command(actions.auth.signup)
capitano.command(actions.auth.whoami)
# ---------- App Module ----------
capitano.command
signature: 'app create <name>'
description: 'create an application'
help: '''
Use this command to create a new resin.io application.
You can specify the application type with the `--type` option.
Otherwise, an interactive dropdown will be shown for you to select from.
You can see a list of supported device types with
$ resin devices supported
Examples:
$ resin app create MyApp
$ resin app create MyApp --type raspberry-pi
'''
action: actions.app.create
options: [
{
signature: 'type'
parameter: 'type'
description: 'application type'
alias: 't'
}
]
capitano.command
signature: 'apps'
description: 'list all applications'
help: '''
Use this command to list all your applications.
Notice this command only shows the most important bits of information for each app.
If you want detailed information, use resin app <id> instead.
Examples:
$ resin apps
'''
action: actions.app.list
capitano.command
signature: 'app <id>'
description: 'list a single application'
help: '''
Use this command to show detailed information for a single application.
Examples:
$ resin app 91
'''
action: actions.app.info
capitano.command
signature: 'app rm <id>'
description: 'remove an application'
help: '''
Use this command to remove a resin.io application.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin app rm 91
$ resin app rm 91 --yes
'''
action: actions.app.remove
options: [ yesOption ]
capitano.command
signature: 'app restart <id>'
description: 'restart an application'
help: '''
Use this command to restart all devices that belongs to a certain application.
Examples:
$ resin app restart 91
'''
action: actions.app.restart
capitano.command
signature: 'init <id>'
description: 'init an application'
help: '''
Use this command to associate a local project to an existing resin.io application.
The application should be a git repository before issuing this command.
Notice this command adds a `resin` git remote to your application.
Examples:
$ cd myApp && resin init 91
'''
action: actions.app.init
capitano.command(actions.app.create)
capitano.command(actions.app.list)
capitano.command(actions.app.info)
capitano.command(actions.app.remove)
capitano.command(actions.app.restart)
capitano.command(actions.app.init)
# ---------- Device Module ----------
capitano.command
signature: 'devices'
description: 'list all devices'
help: '''
Use this command to list all devices that belong to a certain application.
Examples:
$ resin devices --application 91
'''
action: actions.device.list
options: [ applicationOption ]
capitano.command
signature: 'devices supported'
description: 'list all supported devices'
help: '''
Use this command to get the list of all supported devices
Examples:
$ resin devices supported
'''
action: actions.device.supported
capitano.command
signature: 'device rename <id> [name]'
description: 'rename a resin device'
help: '''
Use this command to rename a device.
If you omit the name, you'll get asked for it interactively.
Examples:
$ resin device rename 317 MyPi
$ resin device rename 317
'''
action: actions.device.rename
capitano.command
signature: 'device <id>'
description: 'list a single device'
help: '''
Use this command to show information about a single device.
Examples:
$ resin device 317
'''
action: actions.device.info
capitano.command
signature: 'device rm <id>'
description: 'remove a device'
help: '''
Use this command to remove a device from resin.io.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin device rm 317
$ resin device rm 317 --yes
'''
action: actions.device.remove
options: [ yesOption ]
capitano.command
signature: 'device identify <uuid>'
description: 'identify a device with a UUID'
help: '''
Use this command to identify a device.
In the Raspberry Pi, the ACT led is blinked several times.
Examples:
$ resin device identify 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828
'''
action: actions.device.identify
capitano.command(actions.device.list)
capitano.command(actions.device.supported)
capitano.command(actions.device.rename)
capitano.command(actions.device.info)
capitano.command(actions.device.remove)
capitano.command(actions.device.identify)
# ---------- Device Module ----------
capitano.command
signature: 'note [note]'
description: 'set a device note'
help: '''
Use this command to set or update a device note.
If note command isn't passed, the tool attempts to read from `stdin`.
To view the notes, use $ resin device <id>.
Examples:
$ resin note "My useful note" --device 317
$ cat note.txt | resin note --device 317
'''
action: actions.notes.set
options: [ deviceOption ]
capitano.command(actions.notes.set)
# ---------- Preferences Module ----------
capitano.command
signature: 'preferences'
description: 'open preferences form'
help: '''
Use this command to open the preferences form.
In the future, we will allow changing all preferences directly from the terminal.
For now, we open your default web browser and point it to the web based preferences form.
Examples:
$ resin preferences
'''
action: actions.preferences.preferences
capitano.command(actions.preferences.preferences)
# ---------- Keys Module ----------
capitano.command
signature: 'keys'
description: 'list all ssh keys'
help: '''
Use this command to list all your SSH keys.
Examples:
$ resin keys
'''
action: actions.keys.list
capitano.command
signature: 'key add <name> [path]'
description: 'add a SSH key to resin.io'
help: '''
Use this command to associate a new SSH key with your account.
If `path` is omitted, the command will attempt
to read the SSH key from stdin.
Examples:
$ resin key add Main ~/.ssh/id_rsa.pub
$ cat ~/.ssh/id_rsa.pub | resin key add Main
'''
action: actions.keys.add
capitano.command
signature: 'key <id>'
description: 'list a single ssh key'
help: '''
Use this command to show information about a single SSH key.
Examples:
$ resin key 17
'''
action: actions.keys.info
capitano.command
signature: 'key rm <id>'
description: 'remove a ssh key'
help: '''
Use this command to remove a SSH key from resin.io.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin key rm 17
$ resin key rm 17 --yes
'''
action: actions.keys.remove
options: [ yesOption ]
capitano.command(actions.keys.list)
capitano.command(actions.keys.add)
capitano.command(actions.keys.info)
capitano.command(actions.keys.remove)
# ---------- Env Module ----------
capitano.command
signature: 'envs'
description: 'list all environment variables'
help: '''
Use this command to list all environment variables for a particular application.
Notice we will support per-device environment variables soon.
This command lists all custom environment variables set on the devices running
the application. If you want to see all environment variables, including private
ones used by resin, use the verbose option.
Example:
$ resin envs --application 91
$ resin envs --application 91 --verbose
'''
action: actions.env.list
options: [
applicationOption
{
signature: 'verbose'
description: 'show private environment variables'
boolean: true
alias: 'v'
}
]
capitano.command
signature: 'env add <key> [value]'
description: 'add an environment variable'
help: '''
Use this command to add an enviroment variable to an application.
You need to pass the `--application` option.
If value is omitted, the tool will attempt to use the variable's value
as defined in your host machine.
If the value is grabbed from the environment, a warning message will be printed.
Use `--quiet` to remove it.
Examples:
$ resin env add EDITOR vim -a 91
$ resin env add TERM -a 91
'''
options: [ applicationOption ]
action: actions.env.add
capitano.command
signature: 'env rename <id> <value>'
description: 'rename an environment variable'
help: '''
Use this command to rename an enviroment variable from an application.
Examples:
$ resin env rename 376 emacs
'''
action: actions.env.rename
capitano.command
signature: 'env rm <id>'
description: 'remove an environment variable'
help: '''
Use this command to remove an environment variable from an application.
Don't remove resin specific variables, as things might not work as expected.
Notice this command asks for confirmation interactively.
You can avoid this by passing the `--yes` boolean option.
Examples:
$ resin env rm 215
$ resin env rm 215 --yes
'''
action: actions.env.remove
options: [ yesOption ]
capitano.command(actions.env.list)
capitano.command(actions.env.add)
capitano.command(actions.env.rename)
capitano.command(actions.env.remove)
# ---------- Logs Module ----------
capitano.command
signature: 'logs <uuid>'
description: 'show device logs'
help: '''
Use this command to show logs for a specific device.
By default, the command prints all log messages and exit.
To limit the output to the n last lines, use the `--num` option along with a number.
This is similar to doing `resin logs <uuid> | tail -n X`.
To continuously stream output, and see new logs in real time, use the `--tail` option.
Note that for now you need to provide the whole UUID for this command to work correctly,
and the tool won't notice if you're using an invalid UUID.
This is due to some technical limitations that we plan to address soon.
Examples:
$ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828
$ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828 --num 20
$ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828 --tail
'''
action: actions.logs.logs
options: [
{
signature: 'num'
parameter: 'num'
description: 'number of lines to display'
alias: 'n'
}
{
signature: 'tail'
description: 'continuously stream output'
boolean: true
alias: 't'
}
]
capitano.command(actions.logs.logs)
# ---------- OS Module ----------
capitano.command
signature: 'os download <id>'
description: 'download device OS'
help: '''
Use this command to download the device OS configured to a specific network.
Ethernet:
You can setup the device OS to use ethernet by setting the `--network` option to "ethernet".
Wifi:
You can setup the device OS to use wifi by setting the `--network` option to "wifi".
If you set "network" to "wifi", you will need to specify the `--ssid` and `--key` option as well.
By default, this command saved the downloaded image into a resin specific directory.
You can save it to a custom location by specifying the `--output` option.
Examples:
$ resin os download 91 --network ethernet
$ resin os download 91 --network wifi --ssid MyNetwork --key secreykey123
$ resin os download 91 --network ethernet --output ~/MyResinOS.zip
'''
action: actions.os.download
options: [
{
signature: 'network'
parameter: 'network'
description: 'network type'
alias: 'n'
}
{
signature: 'ssid'
parameter: 'ssid'
description: 'wifi ssid, if network is wifi'
alias: 's'
}
{
signature: 'key'
parameter: 'key'
description: 'wifi key, if network is wifi'
alias: 'k'
}
{
signature: 'output'
parameter: 'output'
description: 'output file'
alias: 'o'
}
]
capitano.command(actions.os.download)
# ---------- Examples Module ----------
capitano.command
signature: 'examples'
description: 'list all example applications'
help: '''
Use this command to list available example applications from resin.io
Example:
$ resin examples
'''
action: actions.examples.list
capitano.command
signature: 'example clone <id>'
description: 'clone an example application'
help: '''
Use this command to clone an example application to the current directory
This command outputs information about the cloning process.
Use `--quiet` to remove that output.
Example:
$ resin example clone 3
'''
action: actions.examples.clone
capitano.command
signature: 'example <id>'
description: 'list a single example application'
help: '''
Use this command to show information of a single example application
Example:
$ resin example 3
'''
action: actions.examples.info
capitano.command(actions.examples.list)
capitano.command(actions.examples.clone)
capitano.command(actions.examples.info)
try
for pluginPath in plugin.getPluginsPathsByGlob('resin-plugin-*')