2015-08-13 17:42:49 +00:00
|
|
|
_ = require('lodash')
|
2015-01-08 12:04:37 +00:00
|
|
|
resin = require('resin-sdk')
|
2015-01-21 13:50:19 +00:00
|
|
|
visuals = require('resin-cli-visuals')
|
2015-01-15 17:10:14 +00:00
|
|
|
commandOptions = require('./command-options')
|
2015-03-12 15:24:36 +00:00
|
|
|
vcs = require('resin-vcs')
|
2015-08-31 21:39:48 +00:00
|
|
|
events = require('resin-cli-events')
|
2015-08-13 18:00:23 +00:00
|
|
|
helpers = require('../utils/helpers')
|
2015-08-20 19:54:42 +00:00
|
|
|
patterns = require('../utils/patterns')
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
exports.create =
|
|
|
|
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
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin devices supported
|
|
|
|
|
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin app create MyApp
|
|
|
|
$ resin app create MyApp --type raspberry-pi
|
|
|
|
'''
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
signature: 'type'
|
|
|
|
parameter: 'type'
|
|
|
|
description: 'application type'
|
|
|
|
alias: 't'
|
|
|
|
}
|
|
|
|
]
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
2015-10-01 14:39:36 +00:00
|
|
|
primary: true
|
2015-01-16 12:34:59 +00:00
|
|
|
action: (params, options, done) ->
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-08-13 17:42:49 +00:00
|
|
|
# Validate the the application name is available
|
|
|
|
# before asking the device type.
|
|
|
|
# https://github.com/resin-io/resin-cli/issues/30
|
|
|
|
resin.models.application.has(params.name).then (hasApplication) ->
|
|
|
|
if hasApplication
|
|
|
|
throw new Error('You already have an application with that name!')
|
|
|
|
|
2015-08-20 19:54:42 +00:00
|
|
|
.then(patterns.selectDeviceType).then (deviceType) ->
|
2015-08-13 18:00:23 +00:00
|
|
|
return resin.models.application.create(params.name, deviceType)
|
|
|
|
.then (application) ->
|
2015-08-13 17:42:49 +00:00
|
|
|
console.info("Application created: #{application.app_name} (#{application.device_type}, id #{application.id})")
|
2015-08-31 21:39:48 +00:00
|
|
|
events.send('application.create', application: application.id)
|
2015-08-13 17:42:49 +00:00
|
|
|
.nodeify(done)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
exports.list =
|
|
|
|
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.
|
2015-03-23 12:17:55 +00:00
|
|
|
If you want detailed information, use resin app <name> instead.
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
$ resin apps
|
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
2015-10-01 14:39:36 +00:00
|
|
|
primary: true
|
2015-01-16 12:34:59 +00:00
|
|
|
action: (params, options, done) ->
|
2015-07-22 22:06:53 +00:00
|
|
|
resin.models.application.getAll().then (applications) ->
|
2015-07-29 13:34:31 +00:00
|
|
|
console.log visuals.table.horizontal applications, [
|
2015-01-22 17:06:02 +00:00
|
|
|
'id'
|
|
|
|
'app_name'
|
2015-01-22 17:20:20 +00:00
|
|
|
'device_type'
|
2015-01-22 17:06:02 +00:00
|
|
|
'online_devices'
|
|
|
|
'devices_length'
|
2015-01-15 17:10:14 +00:00
|
|
|
]
|
2015-07-22 22:06:53 +00:00
|
|
|
.nodeify(done)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
exports.info =
|
2015-03-23 12:17:55 +00:00
|
|
|
signature: 'app <name>'
|
2015-01-15 17:10:14 +00:00
|
|
|
description: 'list a single application'
|
|
|
|
help: '''
|
|
|
|
Use this command to show detailed information for a single application.
|
|
|
|
|
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-03-23 12:17:55 +00:00
|
|
|
$ resin app MyApp
|
2015-01-15 17:10:14 +00:00
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
2015-10-01 14:39:36 +00:00
|
|
|
primary: true
|
2015-01-16 12:34:59 +00:00
|
|
|
action: (params, options, done) ->
|
2015-07-22 22:06:53 +00:00
|
|
|
resin.models.application.get(params.name).then (application) ->
|
2015-07-29 13:34:31 +00:00
|
|
|
console.log visuals.table.vertical application, [
|
|
|
|
"$#{application.app_name}$"
|
2015-01-22 17:06:02 +00:00
|
|
|
'id'
|
2015-01-22 17:20:20 +00:00
|
|
|
'device_type'
|
2015-01-22 17:06:02 +00:00
|
|
|
'git_repository'
|
|
|
|
'commit'
|
2015-01-15 17:10:14 +00:00
|
|
|
]
|
2015-08-31 21:39:48 +00:00
|
|
|
events.send('application.open', application: application.id)
|
2015-07-22 22:06:53 +00:00
|
|
|
.nodeify(done)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
exports.restart =
|
2015-03-23 12:17:55 +00:00
|
|
|
signature: 'app restart <name>'
|
2015-01-15 17:10:14 +00:00
|
|
|
description: 'restart an application'
|
|
|
|
help: '''
|
|
|
|
Use this command to restart all devices that belongs to a certain application.
|
|
|
|
|
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-03-23 12:17:55 +00:00
|
|
|
$ resin app restart MyApp
|
2015-01-15 17:10:14 +00:00
|
|
|
'''
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-07-22 22:06:53 +00:00
|
|
|
resin.models.application.restart(params.name).nodeify(done)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
exports.remove =
|
2015-03-23 12:17:55 +00:00
|
|
|
signature: 'app rm <name>'
|
2015-01-15 17:10:14 +00:00
|
|
|
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:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-03-23 12:17:55 +00:00
|
|
|
$ resin app rm MyApp
|
|
|
|
$ resin app rm MyApp --yes
|
2015-01-15 17:10:14 +00:00
|
|
|
'''
|
|
|
|
options: [ commandOptions.yes ]
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-08-20 19:54:42 +00:00
|
|
|
patterns.confirm(options.yes, 'Are you sure you want to delete the application?').then ->
|
2015-08-13 17:42:49 +00:00
|
|
|
resin.models.application.remove(params.name)
|
2015-08-31 21:39:48 +00:00
|
|
|
.tap ->
|
|
|
|
resin.models.application.get(params.name).then (application) ->
|
|
|
|
events.send('application.delete', application: application.id)
|
2015-08-13 17:42:49 +00:00
|
|
|
.nodeify(done)
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-03-09 13:14:39 +00:00
|
|
|
exports.associate =
|
2015-03-23 12:17:55 +00:00
|
|
|
signature: 'app associate <name>'
|
2015-03-09 13:14:39 +00:00
|
|
|
description: 'associate a resin project'
|
2015-01-15 17:10:14 +00:00
|
|
|
help: '''
|
2015-03-09 13:14:39 +00:00
|
|
|
Use this command to associate a project directory with a resin application.
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-03-09 13:14:39 +00:00
|
|
|
This command adds a 'resin' git remote to the directory and runs git init if necessary.
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-06-02 16:32:35 +00:00
|
|
|
Notice this command asks for confirmation interactively.
|
|
|
|
You can avoid this by passing the `--yes` boolean option.
|
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-03-23 12:17:55 +00:00
|
|
|
$ resin app associate MyApp
|
2015-01-15 17:10:14 +00:00
|
|
|
'''
|
2015-06-02 16:32:35 +00:00
|
|
|
options: [ commandOptions.yes ]
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-03-12 15:24:36 +00:00
|
|
|
currentDirectory = process.cwd()
|
2015-08-27 14:01:33 +00:00
|
|
|
console.info("Associating #{params.name} with #{currentDirectory}")
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-08-13 17:42:49 +00:00
|
|
|
resin.models.application.has(params.name).then (hasApplication) ->
|
|
|
|
if not hasApplication
|
|
|
|
throw new Error("Invalid application: #{params.name}")
|
2015-06-02 16:32:35 +00:00
|
|
|
|
2015-08-13 17:42:49 +00:00
|
|
|
.then ->
|
|
|
|
message = "Are you sure you want to associate #{currentDirectory} with #{params.name}?"
|
2015-08-20 19:54:42 +00:00
|
|
|
patterns.confirm(options.yes, message)
|
2015-08-20 20:16:20 +00:00
|
|
|
.then ->
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-08-13 17:42:49 +00:00
|
|
|
resin.models.application.get(params.name).get('git_repository').then (gitRepository) ->
|
|
|
|
vcs.initialize(currentDirectory).then ->
|
|
|
|
return vcs.associate(currentDirectory, gitRepository)
|
|
|
|
.then ->
|
|
|
|
console.info("git repository added: #{gitRepository}")
|
|
|
|
return gitRepository
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-08-13 17:42:49 +00:00
|
|
|
.nodeify(done)
|