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