2016-01-04 03:58:51 +00:00
|
|
|
###
|
2018-10-19 14:38:50 +00:00
|
|
|
Copyright 2016-2017 Balena
|
2016-01-04 03:58:51 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
###
|
|
|
|
|
2015-01-15 17:10:14 +00:00
|
|
|
commandOptions = require('./command-options')
|
|
|
|
|
|
|
|
exports.create =
|
|
|
|
signature: 'app create <name>'
|
|
|
|
description: 'create an application'
|
|
|
|
help: '''
|
2018-10-19 14:38:50 +00:00
|
|
|
Use this command to create a new balena application.
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2017-05-12 10:01:37 +00:00
|
|
|
You can specify the application device type with the `--type` option.
|
2015-01-15 17:10:14 +00:00
|
|
|
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
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena devices supported
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena app create MyApp
|
|
|
|
$ balena app create MyApp --type raspberry-pi
|
2015-01-15 17:10:14 +00:00
|
|
|
'''
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
signature: 'type'
|
|
|
|
parameter: 'type'
|
2018-10-19 14:38:50 +00:00
|
|
|
description: 'application device type (Check available types with `balena devices supported`)'
|
2015-01-15 17:10:14 +00:00
|
|
|
alias: 't'
|
|
|
|
}
|
|
|
|
]
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
2018-10-19 11:14:08 +00:00
|
|
|
|
2015-12-07 14:32:24 +00:00
|
|
|
patterns = require('../utils/patterns')
|
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.
|
2018-10-19 14:38:50 +00:00
|
|
|
# https://github.com/balena-io/balena-cli/issues/30
|
|
|
|
balena.models.application.has(params.name).then (hasApplication) ->
|
2015-08-13 17:42:49 +00:00
|
|
|
if hasApplication
|
2018-04-17 13:17:48 +00:00
|
|
|
patterns.exitWithExpectedError('You already have an application with that name!')
|
2015-08-13 17:42:49 +00:00
|
|
|
|
2015-10-19 17:07:23 +00:00
|
|
|
.then ->
|
|
|
|
return options.type or patterns.selectDeviceType()
|
|
|
|
.then (deviceType) ->
|
2018-10-19 14:38:50 +00:00
|
|
|
return balena.models.application.create({
|
2018-10-19 11:14:08 +00:00
|
|
|
name: params.name
|
|
|
|
deviceType
|
|
|
|
})
|
2015-08-13 18:00:23 +00:00
|
|
|
.then (application) ->
|
2015-08-13 17:42:49 +00:00
|
|
|
console.info("Application created: #{application.app_name} (#{application.device_type}, id #{application.id})")
|
|
|
|
.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.
|
2018-10-19 14:38:50 +00:00
|
|
|
If you want detailed information, use balena app <name> instead.
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena apps
|
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) ->
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
2015-12-07 14:32:24 +00:00
|
|
|
visuals = require('resin-cli-visuals')
|
|
|
|
|
2019-05-17 17:48:49 +00:00
|
|
|
balena.models.application.getAll
|
|
|
|
$select: [
|
|
|
|
'id'
|
|
|
|
'app_name'
|
|
|
|
'device_type'
|
|
|
|
]
|
|
|
|
$expand: owns__device: $select: 'is_online'
|
|
|
|
.then (applications) ->
|
|
|
|
applications.forEach (application) ->
|
|
|
|
application.device_count = application.owns__device.length
|
|
|
|
application.online_devices = application.owns__device.filter((d) -> d.is_online == true).length
|
|
|
|
|
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'
|
2019-05-17 17:48:49 +00:00
|
|
|
'device_count'
|
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
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena 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) ->
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
2015-12-07 14:32:24 +00:00
|
|
|
visuals = require('resin-cli-visuals')
|
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
balena.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-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
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena 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) ->
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
|
|
|
balena.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: '''
|
2018-10-19 14:38:50 +00:00
|
|
|
Use this command to remove a balena application.
|
2015-01-15 17:10:14 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2018-10-19 14:38:50 +00:00
|
|
|
$ balena app rm MyApp
|
|
|
|
$ balena 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) ->
|
2018-10-19 14:38:50 +00:00
|
|
|
balena = require('balena-sdk').fromSharedOptions()
|
2015-12-07 14:32:24 +00:00
|
|
|
patterns = require('../utils/patterns')
|
|
|
|
|
2015-08-20 19:54:42 +00:00
|
|
|
patterns.confirm(options.yes, 'Are you sure you want to delete the application?').then ->
|
2018-10-19 14:38:50 +00:00
|
|
|
balena.models.application.remove(params.name)
|
2015-08-13 17:42:49 +00:00
|
|
|
.nodeify(done)
|