mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-20 06:07:55 +00:00
Merge pull request #23 from resin-io/feature/device-init-app-name
Make device init and os download take app names instead of ids
This commit is contained in:
commit
4c16835ca4
@ -111,19 +111,18 @@
|
|||||||
exports.init = {
|
exports.init = {
|
||||||
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\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\n $ resin device init --application MyApp\n $ resin device init --application MyApp --network ethernet\n $ resin device init /dev/disk2 --application MyApp --network wifi --ssid MyNetwork --key secret',
|
||||||
options: [commandOptions.optionalApplication, 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;
|
|
||||||
return async.waterfall([
|
return async.waterfall([
|
||||||
function(callback) {
|
function(callback) {
|
||||||
if (options.application != null) {
|
if (options.application != null) {
|
||||||
return callback(null, options.application);
|
return callback(null, options.application);
|
||||||
}
|
}
|
||||||
return vcs.getApplicationId(process.cwd(), callback);
|
return vcs.getApplicationName(process.cwd(), callback);
|
||||||
}, function(applicationId, callback) {
|
}, function(applicationName, callback) {
|
||||||
params.id = applicationId;
|
params.name = applicationName;
|
||||||
if (params.device != null) {
|
if (params.device != null) {
|
||||||
return callback(null, params.device);
|
return callback(null, params.device);
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,9 @@
|
|||||||
elevate = require('../elevate');
|
elevate = require('../elevate');
|
||||||
|
|
||||||
exports.download = {
|
exports.download = {
|
||||||
signature: 'os download <id>',
|
signature: 'os download <name>',
|
||||||
description: 'download device OS',
|
description: 'download device OS',
|
||||||
help: 'Use this command to download the device OS configured to a specific network.\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\nAlternatively, you can omit all kind of network configuration options to configure interactively.\n\nYou have to specify an output location with the `--output` option.\n\nExamples:\n\n $ resin os download 91 --output ~/MyResinOS.zip\n $ resin os download 91 --network ethernet --output ~/MyResinOS.zip\n $ resin os download 91 --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip\n $ resin os download 91 --network ethernet --output ~/MyResinOS.zip',
|
help: 'Use this command to download the device OS configured to a specific network.\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\nAlternatively, you can omit all kind of network configuration options to configure interactively.\n\nYou have to specify an output location with the `--output` option.\n\nExamples:\n\n $ resin os download MyApp --output ~/MyResinOS.zip\n $ resin os download MyApp --network ethernet --output ~/MyResinOS.zip\n $ resin os download MyApp --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip\n $ resin os download MyApp --network ethernet --output ~/MyResinOS.zip',
|
||||||
options: [
|
options: [
|
||||||
commandOptions.network, commandOptions.wifiSsid, commandOptions.wifiKey, {
|
commandOptions.network, commandOptions.wifiSsid, commandOptions.wifiKey, {
|
||||||
signature: 'output',
|
signature: 'output',
|
||||||
@ -40,51 +40,56 @@
|
|||||||
],
|
],
|
||||||
permission: 'user',
|
permission: 'user',
|
||||||
action: function(params, options, done) {
|
action: function(params, options, done) {
|
||||||
var osParams;
|
return resin.models.application.get(params.name, function(error, application) {
|
||||||
osParams = {
|
var osParams;
|
||||||
network: options.network,
|
|
||||||
wifiSsid: options.ssid,
|
|
||||||
wifiKey: options.key,
|
|
||||||
appId: params.id
|
|
||||||
};
|
|
||||||
return async.waterfall([
|
|
||||||
function(callback) {
|
|
||||||
if (osParams.network != null) {
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
return visuals.patterns.selectNetworkParameters(function(error, parameters) {
|
|
||||||
if (error != null) {
|
|
||||||
return callback(error);
|
|
||||||
}
|
|
||||||
_.extend(osParams, parameters);
|
|
||||||
return callback();
|
|
||||||
});
|
|
||||||
}, function(callback) {
|
|
||||||
return mkdirp(path.dirname(options.output), _.unary(callback));
|
|
||||||
}, function(callback) {
|
|
||||||
var bar, spinner;
|
|
||||||
console.info("Destination file: " + options.output + "\n");
|
|
||||||
bar = new visuals.widgets.Progress('Downloading Device OS');
|
|
||||||
spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)');
|
|
||||||
return resin.models.os.download(osParams, options.output, function(error) {
|
|
||||||
spinner.stop();
|
|
||||||
if (error != null) {
|
|
||||||
return callback(error);
|
|
||||||
}
|
|
||||||
}, function(state) {
|
|
||||||
if (state != null) {
|
|
||||||
return bar.update(state);
|
|
||||||
} else {
|
|
||||||
return spinner.start();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
], function(error) {
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
return done(error);
|
return done(error);
|
||||||
}
|
}
|
||||||
console.info("\nFinished downloading " + options.output);
|
osParams = {
|
||||||
return done(null, options.output);
|
network: options.network,
|
||||||
|
wifiSsid: options.ssid,
|
||||||
|
wifiKey: options.key,
|
||||||
|
appId: application.id
|
||||||
|
};
|
||||||
|
return async.waterfall([
|
||||||
|
function(callback) {
|
||||||
|
if (osParams.network != null) {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
return visuals.patterns.selectNetworkParameters(function(error, parameters) {
|
||||||
|
if (error != null) {
|
||||||
|
return callback(error);
|
||||||
|
}
|
||||||
|
_.extend(osParams, parameters);
|
||||||
|
return callback();
|
||||||
|
});
|
||||||
|
}, function(callback) {
|
||||||
|
return mkdirp(path.dirname(options.output), _.unary(callback));
|
||||||
|
}, function(callback) {
|
||||||
|
var bar, spinner;
|
||||||
|
console.info("Destination file: " + options.output + "\n");
|
||||||
|
bar = new visuals.widgets.Progress('Downloading Device OS');
|
||||||
|
spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)');
|
||||||
|
return resin.models.os.download(osParams, options.output, function(error) {
|
||||||
|
spinner.stop();
|
||||||
|
if (error != null) {
|
||||||
|
return callback(error);
|
||||||
|
}
|
||||||
|
}, function(state) {
|
||||||
|
if (state != null) {
|
||||||
|
return bar.update(state);
|
||||||
|
} else {
|
||||||
|
return spinner.start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
], function(error) {
|
||||||
|
if (error != null) {
|
||||||
|
return done(error);
|
||||||
|
}
|
||||||
|
console.info("\nFinished downloading " + options.output);
|
||||||
|
return done(null, options.output);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -83,7 +83,7 @@ Now you have access to all the commands referenced below.
|
|||||||
|
|
||||||
- OS
|
- OS
|
||||||
|
|
||||||
- [os download <id>](#/pages/using/cli.md#os-download-60-id-62-)
|
- [os download <name>](#/pages/using/cli.md#os-download-60-name-62-)
|
||||||
- [os install <image> [device]](#/pages/using/cli.md#os-install-60-image-62-device-)
|
- [os install <image> [device]](#/pages/using/cli.md#os-install-60-image-62-device-)
|
||||||
|
|
||||||
- Plugin
|
- Plugin
|
||||||
@ -211,7 +211,7 @@ Use this command to login to your resin.io account.
|
|||||||
|
|
||||||
To login, you need your token, which is accesible from the preferences page:
|
To login, you need your token, which is accesible from the preferences page:
|
||||||
|
|
||||||
https://staging.resin.io/preferences
|
https://dashboard.resin.io/preferences
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
@ -358,9 +358,9 @@ You can omit network related options to be asked about them interactively.
|
|||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
$ resin device init
|
$ resin device init
|
||||||
$ resin device init --application 91
|
$ resin device init --application MyApp
|
||||||
$ resin device init --application 91 --network ethernet
|
$ resin device init --application MyApp --network ethernet
|
||||||
$ resin device init /dev/disk2 --application 91 --network wifi --ssid MyNetwork --key secret
|
$ resin device init /dev/disk2 --application MyApp --network wifi --ssid MyNetwork --key secret
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
@ -618,7 +618,7 @@ device name
|
|||||||
|
|
||||||
# OS
|
# OS
|
||||||
|
|
||||||
## os download <id>
|
## os download <name>
|
||||||
|
|
||||||
Use this command to download the device OS configured to a specific network.
|
Use this command to download the device OS configured to a specific network.
|
||||||
|
|
||||||
@ -635,10 +635,10 @@ You have to specify an output location with the `--output` option.
|
|||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
$ resin os download 91 --output ~/MyResinOS.zip
|
$ resin os download MyApp --output ~/MyResinOS.zip
|
||||||
$ resin os download 91 --network ethernet --output ~/MyResinOS.zip
|
$ resin os download MyApp --network ethernet --output ~/MyResinOS.zip
|
||||||
$ resin os download 91 --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip
|
$ resin os download MyApp --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip
|
||||||
$ resin os download 91 --network ethernet --output ~/MyResinOS.zip
|
$ resin os download MyApp --network ethernet --output ~/MyResinOS.zip
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
|
@ -178,9 +178,9 @@ exports.init =
|
|||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
$ resin device init
|
$ resin device init
|
||||||
$ resin device init --application 91
|
$ resin device init --application MyApp
|
||||||
$ resin device init --application 91 --network ethernet
|
$ resin device init --application MyApp --network ethernet
|
||||||
$ resin device init /dev/disk2 --application 91 --network wifi --ssid MyNetwork --key secret
|
$ resin device init /dev/disk2 --application MyApp --network wifi --ssid MyNetwork --key secret
|
||||||
'''
|
'''
|
||||||
options: [
|
options: [
|
||||||
commandOptions.optionalApplication
|
commandOptions.optionalApplication
|
||||||
@ -191,16 +191,14 @@ exports.init =
|
|||||||
permission: 'user'
|
permission: 'user'
|
||||||
action: (params, options, done) ->
|
action: (params, options, done) ->
|
||||||
|
|
||||||
params.id = options.application
|
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
|
||||||
(callback) ->
|
(callback) ->
|
||||||
return callback(null, options.application) if options.application?
|
return callback(null, options.application) if options.application?
|
||||||
vcs.getApplicationId(process.cwd(), callback)
|
vcs.getApplicationName(process.cwd(), callback)
|
||||||
|
|
||||||
(applicationId, callback) ->
|
(applicationName, callback) ->
|
||||||
params.id = applicationId
|
params.name = applicationName
|
||||||
return callback(null, params.device) if params.device?
|
return callback(null, params.device) if params.device?
|
||||||
visuals.patterns.selectDrive(callback)
|
visuals.patterns.selectDrive(callback)
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ updateActions = require('./update')
|
|||||||
elevate = require('../elevate')
|
elevate = require('../elevate')
|
||||||
|
|
||||||
exports.download =
|
exports.download =
|
||||||
signature: 'os download <id>'
|
signature: 'os download <name>'
|
||||||
description: 'download device OS'
|
description: 'download device OS'
|
||||||
help: '''
|
help: '''
|
||||||
Use this command to download the device OS configured to a specific network.
|
Use this command to download the device OS configured to a specific network.
|
||||||
@ -30,10 +30,10 @@ exports.download =
|
|||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
$ resin os download 91 --output ~/MyResinOS.zip
|
$ resin os download MyApp --output ~/MyResinOS.zip
|
||||||
$ resin os download 91 --network ethernet --output ~/MyResinOS.zip
|
$ resin os download MyApp --network ethernet --output ~/MyResinOS.zip
|
||||||
$ resin os download 91 --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip
|
$ resin os download MyApp --network wifi --ssid MyNetwork --key secreykey123 --output ~/MyResinOS.zip
|
||||||
$ resin os download 91 --network ethernet --output ~/MyResinOS.zip
|
$ resin os download MyApp --network ethernet --output ~/MyResinOS.zip
|
||||||
'''
|
'''
|
||||||
options: [
|
options: [
|
||||||
commandOptions.network
|
commandOptions.network
|
||||||
@ -50,45 +50,48 @@ exports.download =
|
|||||||
]
|
]
|
||||||
permission: 'user'
|
permission: 'user'
|
||||||
action: (params, options, done) ->
|
action: (params, options, done) ->
|
||||||
osParams =
|
resin.models.application.get params.name, (error, application) ->
|
||||||
network: options.network
|
|
||||||
wifiSsid: options.ssid
|
|
||||||
wifiKey: options.key
|
|
||||||
appId: params.id
|
|
||||||
|
|
||||||
async.waterfall [
|
|
||||||
|
|
||||||
(callback) ->
|
|
||||||
return callback() if osParams.network?
|
|
||||||
visuals.patterns.selectNetworkParameters (error, parameters) ->
|
|
||||||
return callback(error) if error?
|
|
||||||
_.extend(osParams, parameters)
|
|
||||||
return callback()
|
|
||||||
|
|
||||||
(callback) ->
|
|
||||||
|
|
||||||
# We need to ensure this directory exists
|
|
||||||
mkdirp(path.dirname(options.output), _.unary(callback))
|
|
||||||
|
|
||||||
(callback) ->
|
|
||||||
console.info("Destination file: #{options.output}\n")
|
|
||||||
|
|
||||||
bar = new visuals.widgets.Progress('Downloading Device OS')
|
|
||||||
spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)')
|
|
||||||
|
|
||||||
resin.models.os.download osParams, options.output, (error) ->
|
|
||||||
spinner.stop()
|
|
||||||
return callback(error) if error?
|
|
||||||
, (state) ->
|
|
||||||
if state?
|
|
||||||
bar.update(state)
|
|
||||||
else
|
|
||||||
spinner.start()
|
|
||||||
|
|
||||||
], (error) ->
|
|
||||||
return done(error) if error?
|
return done(error) if error?
|
||||||
console.info("\nFinished downloading #{options.output}")
|
|
||||||
return done(null, options.output)
|
osParams =
|
||||||
|
network: options.network
|
||||||
|
wifiSsid: options.ssid
|
||||||
|
wifiKey: options.key
|
||||||
|
appId: application.id
|
||||||
|
|
||||||
|
async.waterfall [
|
||||||
|
|
||||||
|
(callback) ->
|
||||||
|
return callback() if osParams.network?
|
||||||
|
visuals.patterns.selectNetworkParameters (error, parameters) ->
|
||||||
|
return callback(error) if error?
|
||||||
|
_.extend(osParams, parameters)
|
||||||
|
return callback()
|
||||||
|
|
||||||
|
(callback) ->
|
||||||
|
|
||||||
|
# We need to ensure this directory exists
|
||||||
|
mkdirp(path.dirname(options.output), _.unary(callback))
|
||||||
|
|
||||||
|
(callback) ->
|
||||||
|
console.info("Destination file: #{options.output}\n")
|
||||||
|
|
||||||
|
bar = new visuals.widgets.Progress('Downloading Device OS')
|
||||||
|
spinner = new visuals.widgets.Spinner('Downloading Device OS (size unknown)')
|
||||||
|
|
||||||
|
resin.models.os.download osParams, options.output, (error) ->
|
||||||
|
spinner.stop()
|
||||||
|
return callback(error) if error?
|
||||||
|
, (state) ->
|
||||||
|
if state?
|
||||||
|
bar.update(state)
|
||||||
|
else
|
||||||
|
spinner.start()
|
||||||
|
|
||||||
|
], (error) ->
|
||||||
|
return done(error) if error?
|
||||||
|
console.info("\nFinished downloading #{options.output}")
|
||||||
|
return done(null, options.output)
|
||||||
|
|
||||||
exports.install =
|
exports.install =
|
||||||
signature: 'os install <image> [device]'
|
signature: 'os install <image> [device]'
|
||||||
|
@ -65,7 +65,7 @@
|
|||||||
"resin-cli-visuals": "^0.1.0",
|
"resin-cli-visuals": "^0.1.0",
|
||||||
"resin-sdk": "^1.2.0",
|
"resin-sdk": "^1.2.0",
|
||||||
"resin-settings-client": "^1.0.0",
|
"resin-settings-client": "^1.0.0",
|
||||||
"resin-vcs": "^1.1.0",
|
"resin-vcs": "^1.2.0",
|
||||||
"underscore.string": "~2.4.0",
|
"underscore.string": "~2.4.0",
|
||||||
"update-notifier": "^0.3.1"
|
"update-notifier": "^0.3.1"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user