2017-03-08 23:30:24 +00:00
// Generated by CoffeeScript 1.12.4
2016-01-11 19:58:35 +00:00
/ *
Copyright 2016 Resin . io
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-02-26 15:47:56 +00:00
( function ( ) {
2015-12-07 14:32:24 +00:00
var commandOptions ;
2015-02-26 15:47:56 +00:00
commandOptions = require ( './command-options' ) ;
exports . create = {
signature : 'app create <name>' ,
description : 'create an application' ,
2015-03-03 14:14:16 +00:00
help : 'Use this command to create a new resin.io application.\n\nYou can specify the application type with the `--type` option.\nOtherwise, an interactive dropdown will be shown for you to select from.\n\nYou can see a list of supported device types with\n\n $ resin devices supported\n\nExamples:\n\n $ resin app create MyApp\n $ resin app create MyApp --type raspberry-pi' ,
2015-02-26 15:47:56 +00:00
options : [
{
signature : 'type' ,
parameter : 'type' ,
description : 'application type' ,
alias : 't'
}
] ,
permission : 'user' ,
action : function ( params , options , done ) {
2016-02-12 18:34:16 +00:00
var patterns , resin ;
2017-01-25 18:32:07 +00:00
resin = require ( 'resin-sdk-preconfigured' ) ;
2015-12-07 14:32:24 +00:00
patterns = require ( '../utils/patterns' ) ;
2015-08-13 17:42:49 +00:00
return resin . models . application . has ( params . name ) . then ( function ( hasApplication ) {
if ( hasApplication ) {
throw new Error ( 'You already have an application with that name!' ) ;
2015-02-26 15:47:56 +00:00
}
2015-10-19 17:07:23 +00:00
} ) . then ( function ( ) {
return options . type || patterns . selectDeviceType ( ) ;
} ) . then ( function ( deviceType ) {
2015-08-13 18:00:23 +00:00
return resin . models . application . create ( params . name , deviceType ) ;
} ) . then ( function ( application ) {
2016-02-12 18:34:16 +00:00
return console . info ( "Application created: " + application . app _name + " (" + application . device _type + ", id " + application . id + ")" ) ;
2015-08-13 17:42:49 +00:00
} ) . nodeify ( done ) ;
2015-02-26 15:47:56 +00:00
}
} ;
exports . list = {
signature : 'apps' ,
description : 'list all applications' ,
2015-03-23 12:17:55 +00:00
help : 'Use this command to list all your applications.\n\nNotice this command only shows the most important bits of information for each app.\nIf you want detailed information, use resin app <name> instead.\n\nExamples:\n\n $ resin apps' ,
2015-02-26 15:47:56 +00:00
permission : 'user' ,
2015-10-01 14:39:36 +00:00
primary : true ,
2015-02-26 15:47:56 +00:00
action : function ( params , options , done ) {
2015-12-07 14:32:24 +00:00
var resin , visuals ;
2017-01-25 18:32:07 +00:00
resin = require ( 'resin-sdk-preconfigured' ) ;
2015-12-07 14:32:24 +00:00
visuals = require ( 'resin-cli-visuals' ) ;
2015-07-22 22:06:53 +00:00
return resin . models . application . getAll ( ) . then ( function ( applications ) {
2015-07-29 13:34:31 +00:00
return console . log ( visuals . table . horizontal ( applications , [ 'id' , 'app_name' , 'device_type' , 'online_devices' , 'devices_length' ] ) ) ;
2015-07-22 22:06:53 +00:00
} ) . nodeify ( done ) ;
2015-02-26 15:47:56 +00:00
}
} ;
exports . info = {
2015-03-23 12:17:55 +00:00
signature : 'app <name>' ,
2015-02-26 15:47:56 +00:00
description : 'list a single application' ,
2015-03-23 12:17:55 +00:00
help : 'Use this command to show detailed information for a single application.\n\nExamples:\n\n $ resin app MyApp' ,
2015-02-26 15:47:56 +00:00
permission : 'user' ,
2015-10-01 14:39:36 +00:00
primary : true ,
2015-02-26 15:47:56 +00:00
action : function ( params , options , done ) {
2016-02-12 18:34:16 +00:00
var resin , visuals ;
2017-01-25 18:32:07 +00:00
resin = require ( 'resin-sdk-preconfigured' ) ;
2015-12-07 14:32:24 +00:00
visuals = require ( 'resin-cli-visuals' ) ;
2015-07-22 22:06:53 +00:00
return resin . models . application . get ( params . name ) . then ( function ( application ) {
2016-02-12 18:34:16 +00:00
return console . log ( visuals . table . vertical ( application , [ "$" + application . app _name + "$" , 'id' , 'device_type' , 'git_repository' , 'commit' ] ) ) ;
2015-07-22 22:06:53 +00:00
} ) . nodeify ( done ) ;
2015-02-26 15:47:56 +00:00
}
} ;
exports . restart = {
2015-03-23 12:17:55 +00:00
signature : 'app restart <name>' ,
2015-02-26 15:47:56 +00:00
description : 'restart an application' ,
2015-03-23 12:17:55 +00:00
help : 'Use this command to restart all devices that belongs to a certain application.\n\nExamples:\n\n $ resin app restart MyApp' ,
2015-02-26 15:47:56 +00:00
permission : 'user' ,
action : function ( params , options , done ) {
2015-12-07 14:32:24 +00:00
var resin ;
2017-01-25 18:32:07 +00:00
resin = require ( 'resin-sdk-preconfigured' ) ;
2015-07-22 22:06:53 +00:00
return resin . models . application . restart ( params . name ) . nodeify ( done ) ;
2015-02-26 15:47:56 +00:00
}
} ;
exports . remove = {
2015-03-23 12:17:55 +00:00
signature : 'app rm <name>' ,
2015-02-26 15:47:56 +00:00
description : 'remove an application' ,
2015-03-23 12:17:55 +00:00
help : 'Use this command to remove a resin.io application.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nExamples:\n\n $ resin app rm MyApp\n $ resin app rm MyApp --yes' ,
2015-02-26 15:47:56 +00:00
options : [ commandOptions . yes ] ,
permission : 'user' ,
action : function ( params , options , done ) {
2016-02-12 18:34:16 +00:00
var patterns , resin ;
2017-01-25 18:32:07 +00:00
resin = require ( 'resin-sdk-preconfigured' ) ;
2015-12-07 14:32:24 +00:00
patterns = require ( '../utils/patterns' ) ;
2015-08-20 19:54:42 +00:00
return patterns . confirm ( options . yes , 'Are you sure you want to delete the application?' ) . then ( function ( ) {
2015-08-13 17:42:49 +00:00
return resin . models . application . remove ( params . name ) ;
} ) . nodeify ( done ) ;
2015-02-26 15:47:56 +00:00
}
} ;
} ) . call ( this ) ;