mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-21 01:42:26 +00:00
resin sync: always display device selection dialog when uuid is not passed as an argument
Closes #375
This commit is contained in:
parent
e0a2217b94
commit
16a1741374
@ -146,10 +146,11 @@ module.exports =
|
||||
if options.ignore?
|
||||
options.ignore = options.ignore.split(',')
|
||||
|
||||
Promise.resolve(params.uuid ? loadConfig(options.source).uuid)
|
||||
Promise.resolve(params.uuid)
|
||||
.then (uuid) ->
|
||||
if not uuid?
|
||||
return patterns.inferOrSelectDevice()
|
||||
savedUuid = loadConfig(options.source).uuid
|
||||
return patterns.inferOrSelectDevice(savedUuid)
|
||||
|
||||
resin.models.device.has(uuid)
|
||||
.then (hasDevice) ->
|
||||
|
@ -150,21 +150,19 @@ exports.awaitDevice = (uuid) ->
|
||||
console.info("Waiting for #{deviceName} to connect to resin...")
|
||||
poll().return(uuid)
|
||||
|
||||
exports.inferOrSelectDevice = (applicationName) ->
|
||||
Promise.try ->
|
||||
if applicationName?
|
||||
return resin.models.device.getAllByApplication(applicationName)
|
||||
return resin.models.device.getAll()
|
||||
exports.inferOrSelectDevice = (preferredUuid) ->
|
||||
resin.models.device.getAll()
|
||||
.filter (device) ->
|
||||
device.is_online
|
||||
.then (devices) ->
|
||||
if _.isEmpty(devices)
|
||||
throw new Error('You don\'t have any devices')
|
||||
.then (onlineDevices) ->
|
||||
if _.isEmpty(onlineDevices)
|
||||
throw new Error('You don\'t have any devices online')
|
||||
|
||||
return form.ask
|
||||
message: 'Select a device'
|
||||
type: 'list'
|
||||
choices: _.map devices, (device) ->
|
||||
default: if preferredUuid in _.map(onlineDevices, 'uuid') then preferredUuid else onlineDevices[0].uuid
|
||||
choices: _.map onlineDevices, (device) ->
|
||||
return {
|
||||
name: "#{device.name or 'Untitled'} (#{device.uuid.slice(0, 7)})"
|
||||
value: device.uuid
|
||||
|
Loading…
x
Reference in New Issue
Block a user