Rename preload --commit latest to preload --commit current

`latest` is still supported

Change-type: patch
This commit is contained in:
Alexis Svinartchouk 2019-05-21 14:04:42 +02:00
parent 36ab6f5808
commit 2091768c84
2 changed files with 19 additions and 16 deletions

View File

@ -1390,8 +1390,9 @@ id of the application to preload
#### --commit, -c <hash> #### --commit, -c <hash>
the commit hash for a specific application release to preload, use "latest" to specify the latest release The commit hash for a specific application release to preload, use "current" to specify the current
(ignored if no appId is given) release (ignored if no appId is given). The current release is usually also the latest, but can be
manually pinned using the CLI to set the commit field on the application.
#### --splash-image, -s <splashImage.png> #### --splash-image, -s <splashImage.png>

View File

@ -16,10 +16,11 @@ limitations under the License.
dockerUtils = require('../utils/docker') dockerUtils = require('../utils/docker')
LATEST = 'latest'
allDeviceTypes = undefined allDeviceTypes = undefined
isCurrent = (commit) ->
return commit == 'latest' or commit == 'current'
getDeviceTypes = -> getDeviceTypes = ->
Bluebird = require('bluebird') Bluebird = require('bluebird')
_ = require('lodash') _ = require('lodash')
@ -88,14 +89,14 @@ selectApplicationCommit = (releases) ->
if releases.length == 0 if releases.length == 0
exitWithExpectedError('This application has no successful releases.') exitWithExpectedError('This application has no successful releases.')
DEFAULT_CHOICE = { 'name': LATEST, 'value': LATEST } DEFAULT_CHOICE = { 'name': 'current', 'value': 'current' }
choices = [ DEFAULT_CHOICE ].concat releases.map (release) -> choices = [ DEFAULT_CHOICE ].concat releases.map (release) ->
name: "#{release.end_timestamp} - #{release.commit}" name: "#{release.end_timestamp} - #{release.commit}"
value: release.commit value: release.commit
return form.ask return form.ask
message: 'Select a release' message: 'Select a release'
type: 'list' type: 'list'
default: LATEST default: 'current'
choices: choices choices: choices
offerToDisableAutomaticUpdates = (application, commit, pinDevice) -> offerToDisableAutomaticUpdates = (application, commit, pinDevice) ->
@ -103,13 +104,13 @@ offerToDisableAutomaticUpdates = (application, commit, pinDevice) ->
balena = require('balena-sdk').fromSharedOptions() balena = require('balena-sdk').fromSharedOptions()
form = require('resin-cli-form') form = require('resin-cli-form')
if commit == LATEST or not application.should_track_latest_release or pinDevice if isCurrent(commit) or not application.should_track_latest_release or pinDevice
return Promise.resolve() return Promise.resolve()
message = ''' message = '''
This application is set to automatically update all devices to the latest available version. This application is set to automatically update all devices to the current version.
This might be unexpected behaviour: with this enabled, the preloaded device will still This might be unexpected behaviour: with this enabled, the preloaded device will still
download and install the latest release once it is online. download and install the current release once it is online.
Do you want to disable automatic updates for this application? Do you want to disable automatic updates for this application?
@ -159,8 +160,9 @@ module.exports =
signature: 'commit' signature: 'commit'
parameter: 'hash' parameter: 'hash'
description: ''' description: '''
the commit hash for a specific application release to preload, use "latest" to specify the latest release The commit hash for a specific application release to preload, use "current" to specify the current
(ignored if no appId is given) release (ignored if no appId is given). The current release is usually also the latest, but can be
manually pinned using the CLI to set the commit field on the application.
''' '''
alias: 'c' alias: 'c'
} }
@ -275,9 +277,9 @@ module.exports =
# Use the commit given as --commit or show an interactive commit selection menu # Use the commit given as --commit or show an interactive commit selection menu
Promise.try -> Promise.try ->
if options.commit if options.commit
if options.commit == LATEST and preloader.application.commit if isCurrent(options.commit) and preloader.application.commit
# handle `--commit latest` # handle `--commit current` (and its `--commit latest` synonym)
return LATEST return 'latest'
release = _.find preloader.application.owns__release, (release) -> release = _.find preloader.application.owns__release, (release) ->
release.commit.startsWith(options.commit) release.commit.startsWith(options.commit)
if not release if not release
@ -285,12 +287,12 @@ module.exports =
return release.commit return release.commit
selectApplicationCommit(preloader.application.owns__release) selectApplicationCommit(preloader.application.owns__release)
.then (commit) -> .then (commit) ->
if commit == LATEST if isCurrent(commit)
preloader.commit = preloader.application.commit preloader.commit = preloader.application.commit
else else
preloader.commit = commit preloader.commit = commit
# Propose to disable automatic app updates if the commit is not the latest # Propose to disable automatic app updates if the commit is not the current release
offerToDisableAutomaticUpdates(preloader.application, commit, options.pinDevice) offerToDisableAutomaticUpdates(preloader.application, commit, options.pinDevice)
.then -> .then ->
# All options are ready: preload the image. # All options are ready: preload the image.