mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-21 22:47:48 +00:00
Rename expectedError to exitWithExpectedError
This commit is contained in:
parent
6a8b947c2e
commit
37e4ec6364
@ -52,7 +52,7 @@ exports.create =
|
||||
# https://github.com/resin-io/resin-cli/issues/30
|
||||
resin.models.application.has(params.name).then (hasApplication) ->
|
||||
if hasApplication
|
||||
patterns.expectedError('You already have an application with that name!')
|
||||
patterns.exitWithExpectedError('You already have an application with that name!')
|
||||
|
||||
.then ->
|
||||
return options.type or patterns.selectDeviceType()
|
||||
|
@ -92,7 +92,7 @@ exports.login =
|
||||
resin.auth.whoami()
|
||||
.then (username) ->
|
||||
if !username
|
||||
patterns.expectedError('Token authentication failed')
|
||||
patterns.exitWithExpectedError('Token authentication failed')
|
||||
else if options.credentials
|
||||
return patterns.authenticate(options)
|
||||
else if options.web
|
||||
|
@ -95,7 +95,7 @@ module.exports =
|
||||
# compositions with many services trigger misleading warnings
|
||||
require('events').defaultMaxListeners = 1000
|
||||
|
||||
{ expectedError } = require('../utils/patterns')
|
||||
{ exitWithExpectedError } = require('../utils/patterns')
|
||||
helpers = require('../utils/helpers')
|
||||
Logger = require('../utils/logger')
|
||||
|
||||
@ -112,7 +112,7 @@ module.exports =
|
||||
{ application, arch, deviceType } = options
|
||||
|
||||
if (not (arch? and deviceType?) and not application?) or (application? and (arch? or deviceType?))
|
||||
expectedError('You must specify either an application or an arch/deviceType pair to build for')
|
||||
exitWithExpectedError('You must specify either an application or an arch/deviceType pair to build for')
|
||||
|
||||
if arch? and deviceType?
|
||||
[ undefined, arch, deviceType ]
|
||||
|
@ -279,10 +279,10 @@ exports.generate =
|
||||
prettyjson = require('prettyjson')
|
||||
|
||||
{ generateDeviceConfig, generateApplicationConfig } = require('../utils/config')
|
||||
{ expectedError } = require('../utils/patterns')
|
||||
{ exitWithExpectedError } = require('../utils/patterns')
|
||||
|
||||
if not options.device? and not options.application?
|
||||
expectedError '''
|
||||
exitWithExpectedError '''
|
||||
You have to pass either a device or an application.
|
||||
|
||||
See the help page for examples:
|
||||
|
@ -53,7 +53,7 @@ exports.list =
|
||||
resin = require('resin-sdk-preconfigured')
|
||||
visuals = require('resin-cli-visuals')
|
||||
|
||||
{ expectedError } = require('../utils/patterns')
|
||||
{ exitWithExpectedError } = require('../utils/patterns')
|
||||
|
||||
Promise.try ->
|
||||
if options.application?
|
||||
@ -61,11 +61,11 @@ exports.list =
|
||||
else if options.device?
|
||||
return resin.models.environmentVariables.device.getAll(options.device)
|
||||
else
|
||||
expectedError('You must specify an application or device')
|
||||
exitWithExpectedError('You must specify an application or device')
|
||||
|
||||
.tap (environmentVariables) ->
|
||||
if _.isEmpty(environmentVariables)
|
||||
expectedError('No environment variables found')
|
||||
exitWithExpectedError('No environment variables found')
|
||||
if not options.verbose
|
||||
isSystemVariable = resin.models.environmentVariables.isSystemVariable
|
||||
environmentVariables = _.reject(environmentVariables, isSystemVariable)
|
||||
@ -143,7 +143,7 @@ exports.add =
|
||||
Promise = require('bluebird')
|
||||
resin = require('resin-sdk-preconfigured')
|
||||
|
||||
{ expectedError } = require('../utils/patterns')
|
||||
{ exitWithExpectedError } = require('../utils/patterns')
|
||||
|
||||
Promise.try ->
|
||||
if not params.value?
|
||||
@ -159,7 +159,7 @@ exports.add =
|
||||
else if options.device?
|
||||
resin.models.environmentVariables.device.create(options.device, params.key, params.value)
|
||||
else
|
||||
expectedError('You must specify an application or device')
|
||||
exitWithExpectedError('You must specify an application or device')
|
||||
.nodeify(done)
|
||||
|
||||
exports.rename =
|
||||
|
@ -18,7 +18,7 @@ _ = require('lodash')
|
||||
capitano = require('capitano')
|
||||
columnify = require('columnify')
|
||||
messages = require('../utils/messages')
|
||||
{ expectedError } = require('../utils/patterns')
|
||||
{ exitWithExpectedError } = require('../utils/patterns')
|
||||
|
||||
parse = (object) ->
|
||||
return _.fromPairs _.map object, (item) ->
|
||||
@ -79,7 +79,7 @@ command = (params, options, done) ->
|
||||
return done(error) if error?
|
||||
|
||||
if not command? or command.isWildcard()
|
||||
expectedError("Command not found: #{params.command}")
|
||||
exitWithExpectedError("Command not found: #{params.command}")
|
||||
|
||||
console.log("Usage: #{command.signature}")
|
||||
|
||||
|
@ -4,7 +4,7 @@ form = require('resin-cli-form')
|
||||
chalk = require('chalk')
|
||||
|
||||
dockerUtils = require('../../utils/docker')
|
||||
{ expectedError } = require('../../utils/patterns')
|
||||
{ exitWithExpectedError } = require('../../utils/patterns')
|
||||
|
||||
exports.dockerPort = dockerPort = 2375
|
||||
exports.dockerTimeout = dockerTimeout = 2000
|
||||
@ -24,7 +24,7 @@ exports.selectContainerFromDevice = Promise.method (deviceIp, filterSupervisor =
|
||||
filterOutSupervisorContainer(container)
|
||||
.then (containers) ->
|
||||
if _.isEmpty(containers)
|
||||
expectedError("No containers found in #{deviceIp}")
|
||||
exitWithExpectedError("No containers found in #{deviceIp}")
|
||||
|
||||
return form.ask
|
||||
message: 'Select a container'
|
||||
|
@ -64,7 +64,7 @@ module.exports =
|
||||
{ SpinnerPromise } = require('resin-cli-visuals')
|
||||
{ dockerPort, dockerTimeout } = require('./common')
|
||||
dockerUtils = require('../../utils/docker')
|
||||
{ expectedError } = require('../../utils/patterns')
|
||||
{ exitWithExpectedError } = require('../../utils/patterns')
|
||||
|
||||
if options.timeout?
|
||||
options.timeout *= 1000
|
||||
@ -82,7 +82,7 @@ module.exports =
|
||||
.catchReturn(false)
|
||||
.tap (devices) ->
|
||||
if _.isEmpty(devices)
|
||||
expectedError('Could not find any resinOS devices in the local network')
|
||||
exitWithExpectedError('Could not find any resinOS devices in the local network')
|
||||
.map ({ host, address }) ->
|
||||
docker = dockerUtils.createClient(host: address, port: dockerPort, timeout: dockerTimeout)
|
||||
Promise.props
|
||||
|
@ -69,10 +69,10 @@ module.exports =
|
||||
{ forms } = require('resin-sync')
|
||||
|
||||
{ selectContainerFromDevice, getSubShellCommand } = require('./common')
|
||||
{ expectedError } = require('../../utils/patterns')
|
||||
{ exitWithExpectedError } = require('../../utils/patterns')
|
||||
|
||||
if (options.host is true and options.container?)
|
||||
expectedError('Please pass either --host or --container option')
|
||||
exitWithExpectedError('Please pass either --host or --container option')
|
||||
|
||||
if not options.port?
|
||||
options.port = 22222
|
||||
|
@ -45,11 +45,11 @@ exports.set =
|
||||
_ = require('lodash')
|
||||
resin = require('resin-sdk-preconfigured')
|
||||
|
||||
{ expectedError } = require('../utils/patterns')
|
||||
{ exitWithExpectedError } = require('../utils/patterns')
|
||||
|
||||
Promise.try ->
|
||||
if _.isEmpty(params.note)
|
||||
expectedError('Missing note content')
|
||||
exitWithExpectedError('Missing note content')
|
||||
|
||||
resin.models.device.note(options.device, params.note)
|
||||
.nodeify(done)
|
||||
|
@ -244,7 +244,7 @@ exports.configure =
|
||||
options.application
|
||||
params.uuid
|
||||
]).length != 1
|
||||
patterns.expectedError '''
|
||||
patterns.exitWithExpectedError '''
|
||||
To configure an image, you must provide exactly one of:
|
||||
|
||||
* A device, with --device <uuid>
|
||||
|
@ -40,7 +40,7 @@ getApplicationsWithSuccessfulBuilds = (deviceType) ->
|
||||
selectApplication = (deviceType) ->
|
||||
visuals = require('resin-cli-visuals')
|
||||
form = require('resin-cli-form')
|
||||
{ expectedError } = require('../utils/patterns')
|
||||
{ exitWithExpectedError } = require('../utils/patterns')
|
||||
|
||||
applicationInfoSpinner = new visuals.Spinner('Downloading list of applications and releases.')
|
||||
applicationInfoSpinner.start()
|
||||
@ -49,7 +49,7 @@ selectApplication = (deviceType) ->
|
||||
.then (applications) ->
|
||||
applicationInfoSpinner.stop()
|
||||
if applications.length == 0
|
||||
expectedError("You have no apps with successful releases for a '#{deviceType}' device type.")
|
||||
exitWithExpectedError("You have no apps with successful releases for a '#{deviceType}' device type.")
|
||||
form.ask
|
||||
message: 'Select an application'
|
||||
type: 'list'
|
||||
@ -59,10 +59,10 @@ selectApplication = (deviceType) ->
|
||||
|
||||
selectApplicationCommit = (releases) ->
|
||||
form = require('resin-cli-form')
|
||||
{ expectedError } = require('../utils/patterns')
|
||||
{ exitWithExpectedError } = require('../utils/patterns')
|
||||
|
||||
if releases.length == 0
|
||||
expectedError('This application has no successful releases.')
|
||||
exitWithExpectedError('This application has no successful releases.')
|
||||
DEFAULT_CHOICE = { 'name': LATEST, 'value': LATEST }
|
||||
choices = [ DEFAULT_CHOICE ].concat releases.map (release) ->
|
||||
name: "#{release.end_timestamp} - #{release.commit}"
|
||||
@ -152,7 +152,7 @@ module.exports =
|
||||
preload = require('resin-preload')
|
||||
visuals = require('resin-cli-visuals')
|
||||
nodeCleanup = require('node-cleanup')
|
||||
{ expectedError } = require('../utils/patterns')
|
||||
{ exitWithExpectedError } = require('../utils/patterns')
|
||||
|
||||
progressBars = {}
|
||||
|
||||
@ -184,7 +184,7 @@ module.exports =
|
||||
options.dontCheckDeviceType = options['dont-check-device-type']
|
||||
delete options['dont-check-device-type']
|
||||
if options.dontCheckDeviceType and not options.appId
|
||||
expectedError('You need to specify an app id if you disable the device type check.')
|
||||
exitWithExpectedError('You need to specify an app id if you disable the device type check.')
|
||||
|
||||
# Get a configured dockerode instance
|
||||
dockerUtils.getDocker(options)
|
||||
@ -240,7 +240,7 @@ module.exports =
|
||||
release = _.find preloader.application.owns__release, (release) ->
|
||||
release.commit.startsWith(options.commit)
|
||||
if not release
|
||||
expectedError('There is no release matching this commit')
|
||||
exitWithExpectedError('There is no release matching this commit')
|
||||
return release.commit
|
||||
selectApplicationCommit(preloader.application.owns__release)
|
||||
.then (commit) ->
|
||||
@ -254,7 +254,7 @@ module.exports =
|
||||
.then ->
|
||||
# All options are ready: preload the image.
|
||||
preloader.preload()
|
||||
.catch(resin.errors.ResinError, expectedError)
|
||||
.catch(resin.errors.ResinError, exitWithExpectedError)
|
||||
.then(resolve)
|
||||
.catch(reject)
|
||||
.then(done)
|
||||
|
@ -108,7 +108,7 @@ module.exports =
|
||||
console.info("Connecting to: #{uuid}")
|
||||
resin.models.device.get(uuid)
|
||||
.then (device) ->
|
||||
patterns.expectedError('Device is not online') if not device.is_online
|
||||
patterns.exitWithExpectedError('Device is not online') if not device.is_online
|
||||
|
||||
Promise.props
|
||||
username: resin.auth.whoami()
|
||||
|
@ -77,7 +77,7 @@ actions = require('./actions')
|
||||
errors = require('./errors')
|
||||
events = require('./events')
|
||||
update = require('./utils/update')
|
||||
{ expectedError } = require('./utils/patterns')
|
||||
{ exitWithExpectedError } = require('./utils/patterns')
|
||||
|
||||
# Assign bluebird as the global promise library
|
||||
# stream-to-promise will produce native promises if not
|
||||
@ -88,7 +88,7 @@ require('any-promise/register/bluebird')
|
||||
capitano.permission 'user', (done) ->
|
||||
resin.auth.isLoggedIn().then (isLoggedIn) ->
|
||||
if not isLoggedIn
|
||||
expectedError('''
|
||||
exitWithExpectedError('''
|
||||
You have to log in to continue
|
||||
|
||||
Run the following command to go through the login wizard:
|
||||
|
@ -174,6 +174,6 @@ exports.createClient = createClient = do ->
|
||||
return new Docker(opts)
|
||||
|
||||
ensureDockerSeemsAccessible = (docker) ->
|
||||
{ expectedError } = require('./patterns')
|
||||
{ exitWithExpectedError } = require('./patterns')
|
||||
docker.ping().catch ->
|
||||
expectedError('Docker seems to be unavailable. Is it installed and running?')
|
||||
exitWithExpectedError('Docker seems to be unavailable. Is it installed and running?')
|
||||
|
@ -250,7 +250,7 @@ export function printErrorMessage(message: string) {
|
||||
console.error(chalk.red(`\n${messages.getHelp}\n`));
|
||||
}
|
||||
|
||||
export function expectedError(message: string | Error) {
|
||||
export function exitWithExpectedError(message: string | Error) {
|
||||
if (message instanceof Error) {
|
||||
({ message } = message);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user