Make device init attempt to get application id from current directory

This commit is contained in:
Juan Cruz Viotti 2015-03-12 12:03:59 -04:00
parent 8410a709c9
commit 80e0f20301
4 changed files with 33 additions and 7 deletions

View File

@ -1,4 +1,8 @@
(function() { (function() {
var _;
_ = require('lodash');
exports.yes = { exports.yes = {
signature: 'yes', signature: 'yes',
description: 'confirm non interactively', description: 'confirm non interactively',
@ -6,14 +10,17 @@
alias: 'y' alias: 'y'
}; };
exports.application = { exports.optionalApplication = {
signature: 'application', signature: 'application',
parameter: 'application', parameter: 'application',
description: 'application id', description: 'application id',
alias: ['a', 'app'], alias: ['a', 'app']
required: 'You have to specify an application'
}; };
exports.application = _.defaults({
required: 'You have to specify an application'
}, exports.optionalApplication);
exports.network = { exports.network = {
signature: 'network', signature: 'network',
parameter: 'network', parameter: 'network',

View File

@ -1,5 +1,5 @@
(function() { (function() {
var _, async, commandOptions, osAction, path, resin, visuals; var _, async, commandOptions, osAction, path, resin, vcs, visuals;
_ = require('lodash-contrib'); _ = require('lodash-contrib');
@ -11,6 +11,8 @@
visuals = require('resin-cli-visuals'); visuals = require('resin-cli-visuals');
vcs = require('resin-vcs');
commandOptions = require('./command-options'); commandOptions = require('./command-options');
osAction = require('./os'); osAction = require('./os');
@ -110,12 +112,18 @@
signature: 'device init [device]', signature: 'device init [device]',
description: 'initialise a device with resin os', description: 'initialise a device with resin os',
help: 'Use this command to download the OS image of a certain application and write it to an SD Card.\n\nNote that this command requires admin privileges.\n\nIf `device` is omitted, you will be prompted to select a device interactively.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nYou can quiet the progress bar by passing the `--quiet` boolean option.\n\nYou may have to unmount the device before attempting this operation.\n\nYou need to configure the network type and other settings:\n\nEthernet:\n You can setup the device OS to use ethernet by setting the `--network` option to "ethernet".\n\nWifi:\n You can setup the device OS to use wifi by setting the `--network` option to "wifi".\n If you set "network" to "wifi", you will need to specify the `--ssid` and `--key` option as well.\n\nYou can omit network related options to be asked about them interactively.\n\nExamples:\n\n $ resin device init --application 91\n $ resin device init --application 91 --network ethernet\n $ resin device init /dev/disk2 --application 91 --network wifi --ssid MyNetwork --key secret', help: 'Use this command to download the OS image of a certain application and write it to an SD Card.\n\nNote that this command requires admin privileges.\n\nIf `device` is omitted, you will be prompted to select a device interactively.\n\nNotice this command asks for confirmation interactively.\nYou can avoid this by passing the `--yes` boolean option.\n\nYou can quiet the progress bar by passing the `--quiet` boolean option.\n\nYou may have to unmount the device before attempting this operation.\n\nYou need to configure the network type and other settings:\n\nEthernet:\n You can setup the device OS to use ethernet by setting the `--network` option to "ethernet".\n\nWifi:\n You can setup the device OS to use wifi by setting the `--network` option to "wifi".\n If you set "network" to "wifi", you will need to specify the `--ssid` and `--key` option as well.\n\nYou can omit network related options to be asked about them interactively.\n\nExamples:\n\n $ resin device init --application 91\n $ resin device init --application 91 --network ethernet\n $ resin device init /dev/disk2 --application 91 --network wifi --ssid MyNetwork --key secret',
options: [commandOptions.application, commandOptions.network, commandOptions.wifiSsid, commandOptions.wifiKey], options: [commandOptions.optionalApplication, commandOptions.network, commandOptions.wifiSsid, commandOptions.wifiKey],
permission: 'user', permission: 'user',
action: function(params, options, done) { action: function(params, options, done) {
params.id = options.application; params.id = options.application;
return async.waterfall([ return async.waterfall([
function(callback) { function(callback) {
if (options.application != null) {
return callback(null, options.application);
}
return vcs.getApplicationId(process.cwd(), callback);
}, function(applicationId, callback) {
params.id = applicationId;
if (params.device != null) { if (params.device != null) {
return callback(null, params.device); return callback(null, params.device);
} }

View File

@ -1,15 +1,20 @@
_ = require('lodash')
exports.yes = exports.yes =
signature: 'yes' signature: 'yes'
description: 'confirm non interactively' description: 'confirm non interactively'
boolean: true boolean: true
alias: 'y' alias: 'y'
exports.application = exports.optionalApplication =
signature: 'application' signature: 'application'
parameter: 'application' parameter: 'application'
description: 'application id' description: 'application id'
alias: [ 'a', 'app' ] alias: [ 'a', 'app' ]
exports.application = _.defaults
required: 'You have to specify an application' required: 'You have to specify an application'
, exports.optionalApplication
exports.network = exports.network =
signature: 'network' signature: 'network'

View File

@ -3,6 +3,7 @@ path = require('path')
async = require('async') async = require('async')
resin = require('resin-sdk') resin = require('resin-sdk')
visuals = require('resin-cli-visuals') visuals = require('resin-cli-visuals')
vcs = require('resin-vcs')
commandOptions = require('./command-options') commandOptions = require('./command-options')
osAction = require('./os') osAction = require('./os')
@ -181,7 +182,7 @@ exports.init =
$ resin device init /dev/disk2 --application 91 --network wifi --ssid MyNetwork --key secret $ resin device init /dev/disk2 --application 91 --network wifi --ssid MyNetwork --key secret
''' '''
options: [ options: [
commandOptions.application commandOptions.optionalApplication
commandOptions.network commandOptions.network
commandOptions.wifiSsid commandOptions.wifiSsid
commandOptions.wifiKey commandOptions.wifiKey
@ -194,6 +195,11 @@ exports.init =
async.waterfall([ async.waterfall([
(callback) -> (callback) ->
return callback(null, options.application) if options.application?
vcs.getApplicationId(process.cwd(), callback)
(applicationId, callback) ->
params.id = applicationId
return callback(null, params.device) if params.device? return callback(null, params.device) if params.device?
visuals.patterns.selectDrive(callback) visuals.patterns.selectDrive(callback)