mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-07 11:31:15 +00:00
Allow to choose a device interactively from device init
This commit is contained in:
parent
654ab26609
commit
c7c7d55338
@ -4,6 +4,7 @@ async = require('async')
|
|||||||
resin = require('resin-sdk')
|
resin = require('resin-sdk')
|
||||||
os = require('os')
|
os = require('os')
|
||||||
visuals = require('resin-cli-visuals')
|
visuals = require('resin-cli-visuals')
|
||||||
|
drivelist = require('drivelist')
|
||||||
commandOptions = require('./command-options')
|
commandOptions = require('./command-options')
|
||||||
drive = require('../drive/drive')
|
drive = require('../drive/drive')
|
||||||
|
|
||||||
@ -140,13 +141,15 @@ exports.supported =
|
|||||||
_.each(devices, _.unary(console.log))
|
_.each(devices, _.unary(console.log))
|
||||||
|
|
||||||
exports.init =
|
exports.init =
|
||||||
signature: 'device init <image> <device>'
|
signature: 'device init <image> [device]'
|
||||||
description: 'write an operating system image to a device'
|
description: 'write an operating system image to a device'
|
||||||
help: '''
|
help: '''
|
||||||
Use this command to write an operating system image to a device.
|
Use this command to write an operating system image to a device.
|
||||||
|
|
||||||
Note that this command requires admin privileges.
|
Note that this command requires admin privileges.
|
||||||
|
|
||||||
|
If `device` is omitted, you will be prompted to select a device interactively.
|
||||||
|
|
||||||
Notice this command asks for confirmation interactively.
|
Notice this command asks for confirmation interactively.
|
||||||
You can avoid this by passing the `--yes` boolean option.
|
You can avoid this by passing the `--yes` boolean option.
|
||||||
|
|
||||||
@ -171,6 +174,22 @@ exports.init =
|
|||||||
async.waterfall [
|
async.waterfall [
|
||||||
|
|
||||||
(callback) ->
|
(callback) ->
|
||||||
|
return callback(null, params.device) if params.device?
|
||||||
|
|
||||||
|
drivelist.list (error, drives) ->
|
||||||
|
return callback(error) if error?
|
||||||
|
|
||||||
|
drives = _.map drives, (item) ->
|
||||||
|
return {
|
||||||
|
name: "#{item.device} (#{item.size}) - #{item.description}"
|
||||||
|
value: item.device
|
||||||
|
}
|
||||||
|
|
||||||
|
visuals.widgets.select('Select a drive', drives, callback)
|
||||||
|
|
||||||
|
(device, callback) ->
|
||||||
|
params.device = device
|
||||||
|
|
||||||
if options.yes
|
if options.yes
|
||||||
return callback(null, true)
|
return callback(null, true)
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user