Merge pull request #1639 from balena-io/use-capitano-promise-support

Make use of capitano's promise support to simplify the code
This commit is contained in:
Page- 2020-02-28 15:24:53 +00:00 committed by GitHub
commit 0c7947e185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 144 additions and 192 deletions

View File

@ -18,8 +18,8 @@ export const generate: CommandDefinition<{
$ balena api-key generate "Jenkins Key" $ balena api-key generate "Jenkins Key"
`, `,
async action(params, _options, done) { async action(params) {
getBalenaSdk() await getBalenaSdk()
.models.apiKey.create(params.name) .models.apiKey.create(params.name)
.then(key => { .then(key => {
console.log(stripIndent` console.log(stripIndent`
@ -29,7 +29,6 @@ export const generate: CommandDefinition<{
This key will not be shown again, so please save it now. This key will not be shown again, so please save it now.
`); `);
}) });
.finally(done);
}, },
}; };

View File

@ -54,7 +54,7 @@ Examples:
}, },
], ],
permission: 'user', permission: 'user',
async action(params, options, done) { async action(params, options) {
const balena = getBalenaSdk(); const balena = getBalenaSdk();
const patterns = await import('../utils/patterns'); const patterns = await import('../utils/patterns');
@ -82,8 +82,7 @@ Examples:
console.info( console.info(
`Application created: ${application.app_name} (${application.device_type}, id ${application.id})`, `Application created: ${application.app_name} (${application.device_type}, id ${application.id})`,
), ),
) );
.nodeify(done);
}, },
}; };
@ -102,7 +101,7 @@ Examples:
`, `,
permission: 'user', permission: 'user',
primary: true, primary: true,
async action(_params, _options, done) { async action() {
const _ = await import('lodash'); const _ = await import('lodash');
const balena = getBalenaSdk(); const balena = getBalenaSdk();
const visuals = await import('resin-cli-visuals'); const visuals = await import('resin-cli-visuals');
@ -135,8 +134,7 @@ Examples:
]), ]),
); );
}, },
) );
.nodeify(done);
}, },
}; };
@ -154,7 +152,7 @@ Examples:
`, `,
permission: 'user', permission: 'user',
primary: true, primary: true,
async action(params, _options, done) { async action(params) {
const visuals = await import('resin-cli-visuals'); const visuals = await import('resin-cli-visuals');
return getBalenaSdk() return getBalenaSdk()
@ -169,8 +167,7 @@ Examples:
'commit', 'commit',
]), ]),
); );
}) });
.nodeify(done);
}, },
}; };
@ -187,10 +184,8 @@ Examples:
$ balena app restart MyApp\ $ balena app restart MyApp\
`, `,
permission: 'user', permission: 'user',
async action(params, _options, done) { async action(params) {
return getBalenaSdk() return getBalenaSdk().models.application.restart(params.name);
.models.application.restart(params.name)
.nodeify(done);
}, },
}; };
@ -213,7 +208,7 @@ Examples:
`, `,
options: [commandOptions.yes], options: [commandOptions.yes],
permission: 'user', permission: 'user',
async action(params, options, done) { async action(params, options) {
const patterns = await import('../utils/patterns'); const patterns = await import('../utils/patterns');
return patterns return patterns
@ -221,7 +216,6 @@ Examples:
options.yes ?? false, options.yes ?? false,
'Are you sure you want to delete the application?', 'Are you sure you want to delete the application?',
) )
.then(() => getBalenaSdk().models.application.remove(params.name)) .then(() => getBalenaSdk().models.application.remove(params.name));
.nodeify(done);
}, },
}; };

View File

@ -115,7 +115,7 @@ module.exports =
alias: 'a' alias: 'a'
}, },
] ]
action: (params, options, done) -> action: (params, options) ->
# compositions with many services trigger misleading warnings # compositions with many services trigger misleading warnings
require('events').defaultMaxListeners = 1000 require('events').defaultMaxListeners = 1000
@ -181,4 +181,3 @@ module.exports =
convertEol: options.convertEol convertEol: options.convertEol
}) })
) )
.asCallback(done)

View File

@ -46,7 +46,7 @@ exports.read =
] ]
permission: 'user' permission: 'user'
root: true root: true
action: (params, options, done) -> action: (params, options) ->
Promise = require('bluebird') Promise = require('bluebird')
config = require('balena-config-json') config = require('balena-config-json')
visuals = require('resin-cli-visuals') visuals = require('resin-cli-visuals')
@ -60,7 +60,6 @@ exports.read =
return config.read(drive, options.type) return config.read(drive, options.type)
.tap (configJSON) -> .tap (configJSON) ->
console.info(prettyjson.render(configJSON)) console.info(prettyjson.render(configJSON))
.nodeify(done)
exports.write = exports.write =
signature: 'config write <key> <value>' signature: 'config write <key> <value>'
@ -91,7 +90,7 @@ exports.write =
] ]
permission: 'user' permission: 'user'
root: true root: true
action: (params, options, done) -> action: (params, options) ->
Promise = require('bluebird') Promise = require('bluebird')
_ = require('lodash') _ = require('lodash')
config = require('balena-config-json') config = require('balena-config-json')
@ -112,7 +111,6 @@ exports.write =
return config.write(drive, options.type, configJSON) return config.write(drive, options.type, configJSON)
.tap -> .tap ->
console.info('Done') console.info('Done')
.nodeify(done)
exports.inject = exports.inject =
signature: 'config inject <file>' signature: 'config inject <file>'
@ -143,7 +141,7 @@ exports.inject =
] ]
permission: 'user' permission: 'user'
root: true root: true
action: (params, options, done) -> action: (params, options) ->
Promise = require('bluebird') Promise = require('bluebird')
config = require('balena-config-json') config = require('balena-config-json')
visuals = require('resin-cli-visuals') visuals = require('resin-cli-visuals')
@ -158,7 +156,6 @@ exports.inject =
return config.write(drive, options.type, configJSON) return config.write(drive, options.type, configJSON)
.tap -> .tap ->
console.info('Done') console.info('Done')
.nodeify(done)
exports.reconfigure = exports.reconfigure =
signature: 'config reconfigure' signature: 'config reconfigure'
@ -195,7 +192,7 @@ exports.reconfigure =
] ]
permission: 'user' permission: 'user'
root: true root: true
action: (params, options, done) -> action: (params, options) ->
Promise = require('bluebird') Promise = require('bluebird')
config = require('balena-config-json') config = require('balena-config-json')
visuals = require('resin-cli-visuals') visuals = require('resin-cli-visuals')
@ -216,7 +213,6 @@ exports.reconfigure =
return runCommand(configureCommand) return runCommand(configureCommand)
.then -> .then ->
console.info('Done') console.info('Done')
.nodeify(done)
exports.generate = exports.generate =
signature: 'config generate' signature: 'config generate'
@ -285,7 +281,7 @@ exports.generate =
} }
] ]
permission: 'user' permission: 'user'
action: (params, options, done) -> action: (params, options) ->
normalizeUuidProp(options, 'device') normalizeUuidProp(options, 'device')
Promise = require('bluebird') Promise = require('bluebird')
writeFileAsync = Promise.promisify(require('fs').writeFile) writeFileAsync = Promise.promisify(require('fs').writeFile)
@ -355,4 +351,3 @@ exports.generate =
return writeFileAsync(options.output, JSON.stringify(config)) return writeFileAsync(options.output, JSON.stringify(config))
console.log(prettyjson.render(config)) console.log(prettyjson.render(config))
.nodeify(done)

View File

@ -194,7 +194,7 @@ module.exports =
boolean: true boolean: true
}, },
] ]
action: (params, options, done) -> action: (params, options) ->
# compositions with many services trigger misleading warnings # compositions with many services trigger misleading warnings
require('events').defaultMaxListeners = 1000 require('events').defaultMaxListeners = 1000
sdk = getBalenaSdk() sdk = getBalenaSdk()
@ -217,7 +217,7 @@ module.exports =
options.convertEol = options['convert-eol'] || false options.convertEol = options['convert-eol'] || false
delete options['convert-eol'] delete options['convert-eol']
if options.convertEol and not options.build if options.convertEol and not options.build
return done(new ExpectedError('The --eol-conversion flag is only valid with --build.')) return Promise.reject(new ExpectedError('The --eol-conversion flag is only valid with --build.'))
Promise.try -> Promise.try ->
if not appName? if not appName?
@ -264,4 +264,3 @@ module.exports =
convertEol: options.convertEol convertEol: options.convertEol
}) })
) )
.asCallback(done)

View File

@ -41,7 +41,7 @@ exports.list =
options: [ commandOptions.optionalApplication ] options: [ commandOptions.optionalApplication ]
permission: 'user' permission: 'user'
primary: true primary: true
action: (params, options, done) -> action: (params, options) ->
Promise = require('bluebird') Promise = require('bluebird')
balena = getBalenaSdk() balena = getBalenaSdk()
visuals = require('resin-cli-visuals') visuals = require('resin-cli-visuals')
@ -71,7 +71,6 @@ exports.list =
'os_version' 'os_version'
'dashboard_url' 'dashboard_url'
] ]
.nodeify(done)
exports.info = exports.info =
signature: 'device <uuid>' signature: 'device <uuid>'
@ -85,7 +84,7 @@ exports.info =
''' '''
permission: 'user' permission: 'user'
primary: true primary: true
action: (params, options, done) -> action: (params, options) ->
normalizeUuidProp(params) normalizeUuidProp(params)
balena = getBalenaSdk() balena = getBalenaSdk()
visuals = require('resin-cli-visuals') visuals = require('resin-cli-visuals')
@ -116,7 +115,6 @@ exports.info =
'os_version' 'os_version'
'dashboard_url' 'dashboard_url'
] ]
.nodeify(done)
exports.register = exports.register =
signature: 'device register <application>' signature: 'device register <application>'
@ -138,7 +136,7 @@ exports.register =
alias: 'u' alias: 'u'
} }
] ]
action: (params, options, done) -> action: (params, options) ->
Promise = require('bluebird') Promise = require('bluebird')
balena = getBalenaSdk() balena = getBalenaSdk()
@ -150,7 +148,6 @@ exports.register =
return balena.models.device.register(application.id, uuid) return balena.models.device.register(application.id, uuid)
) )
.get('uuid') .get('uuid')
.nodeify(done)
exports.remove = exports.remove =
signature: 'device rm <uuid>' signature: 'device rm <uuid>'
@ -168,14 +165,13 @@ exports.remove =
''' '''
options: [ commandOptions.yes ] options: [ commandOptions.yes ]
permission: 'user' permission: 'user'
action: (params, options, done) -> action: (params, options) ->
normalizeUuidProp(params) normalizeUuidProp(params)
balena = getBalenaSdk() balena = getBalenaSdk()
patterns = require('../utils/patterns') patterns = require('../utils/patterns')
patterns.confirm(options.yes, 'Are you sure you want to delete the device?').then -> patterns.confirm(options.yes, 'Are you sure you want to delete the device?').then ->
balena.models.device.remove(params.uuid) balena.models.device.remove(params.uuid)
.nodeify(done)
exports.identify = exports.identify =
signature: 'device identify <uuid>' signature: 'device identify <uuid>'
@ -190,10 +186,10 @@ exports.identify =
$ balena device identify 23c73a1 $ balena device identify 23c73a1
''' '''
permission: 'user' permission: 'user'
action: (params, options, done) -> action: (params, options) ->
normalizeUuidProp(params) normalizeUuidProp(params)
balena = getBalenaSdk() balena = getBalenaSdk()
balena.models.device.identify(params.uuid).nodeify(done) balena.models.device.identify(params.uuid)
exports.reboot = exports.reboot =
signature: 'device reboot <uuid>' signature: 'device reboot <uuid>'
@ -207,10 +203,10 @@ exports.reboot =
''' '''
options: [ commandOptions.forceUpdateLock ] options: [ commandOptions.forceUpdateLock ]
permission: 'user' permission: 'user'
action: (params, options, done) -> action: (params, options) ->
normalizeUuidProp(params) normalizeUuidProp(params)
balena = getBalenaSdk() balena = getBalenaSdk()
balena.models.device.reboot(params.uuid, options).nodeify(done) balena.models.device.reboot(params.uuid, options)
exports.shutdown = exports.shutdown =
signature: 'device shutdown <uuid>' signature: 'device shutdown <uuid>'
@ -224,10 +220,10 @@ exports.shutdown =
''' '''
options: [ commandOptions.forceUpdateLock ] options: [ commandOptions.forceUpdateLock ]
permission: 'user' permission: 'user'
action: (params, options, done) -> action: (params, options) ->
normalizeUuidProp(params) normalizeUuidProp(params)
balena = getBalenaSdk() balena = getBalenaSdk()
balena.models.device.shutdown(params.uuid, options).nodeify(done) balena.models.device.shutdown(params.uuid, options)
exports.enableDeviceUrl = exports.enableDeviceUrl =
signature: 'device public-url enable <uuid>' signature: 'device public-url enable <uuid>'
@ -240,10 +236,10 @@ exports.enableDeviceUrl =
$ balena device public-url enable 23c73a1 $ balena device public-url enable 23c73a1
''' '''
permission: 'user' permission: 'user'
action: (params, options, done) -> action: (params, options) ->
normalizeUuidProp(params) normalizeUuidProp(params)
balena = getBalenaSdk() balena = getBalenaSdk()
balena.models.device.enableDeviceUrl(params.uuid).nodeify(done) balena.models.device.enableDeviceUrl(params.uuid)
exports.disableDeviceUrl = exports.disableDeviceUrl =
signature: 'device public-url disable <uuid>' signature: 'device public-url disable <uuid>'
@ -256,10 +252,10 @@ exports.disableDeviceUrl =
$ balena device public-url disable 23c73a1 $ balena device public-url disable 23c73a1
''' '''
permission: 'user' permission: 'user'
action: (params, options, done) -> action: (params, options) ->
normalizeUuidProp(params) normalizeUuidProp(params)
balena = getBalenaSdk() balena = getBalenaSdk()
balena.models.device.disableDeviceUrl(params.uuid).nodeify(done) balena.models.device.disableDeviceUrl(params.uuid)
exports.getDeviceUrl = exports.getDeviceUrl =
signature: 'device public-url <uuid>' signature: 'device public-url <uuid>'
@ -272,12 +268,11 @@ exports.getDeviceUrl =
$ balena device public-url 23c73a1 $ balena device public-url 23c73a1
''' '''
permission: 'user' permission: 'user'
action: (params, options, done) -> action: (params, options) ->
normalizeUuidProp(params) normalizeUuidProp(params)
balena = getBalenaSdk() balena = getBalenaSdk()
balena.models.device.getDeviceUrl(params.uuid).then (url) -> balena.models.device.getDeviceUrl(params.uuid).then (url) ->
console.log(url) console.log(url)
.nodeify(done)
exports.hasDeviceUrl = exports.hasDeviceUrl =
signature: 'device public-url status <uuid>' signature: 'device public-url status <uuid>'
@ -290,12 +285,11 @@ exports.hasDeviceUrl =
$ balena device public-url status 23c73a1 $ balena device public-url status 23c73a1
''' '''
permission: 'user' permission: 'user'
action: (params, options, done) -> action: (params, options) ->
normalizeUuidProp(params) normalizeUuidProp(params)
balena = getBalenaSdk() balena = getBalenaSdk()
balena.models.device.hasDeviceUrl(params.uuid).then (hasDeviceUrl) -> balena.models.device.hasDeviceUrl(params.uuid).then (hasDeviceUrl) ->
console.log(hasDeviceUrl) console.log(hasDeviceUrl)
.nodeify(done)
exports.rename = exports.rename =
signature: 'device rename <uuid> [newName]' signature: 'device rename <uuid> [newName]'
@ -311,7 +305,7 @@ exports.rename =
$ balena device rename 7cf02a6 MyPi $ balena device rename 7cf02a6 MyPi
''' '''
permission: 'user' permission: 'user'
action: (params, options, done) -> action: (params, options) ->
normalizeUuidProp(params) normalizeUuidProp(params)
Promise = require('bluebird') Promise = require('bluebird')
balena = getBalenaSdk() balena = getBalenaSdk()
@ -325,7 +319,6 @@ exports.rename =
type: 'input' type: 'input'
.then(_.partial(balena.models.device.rename, params.uuid)) .then(_.partial(balena.models.device.rename, params.uuid))
.nodeify(done)
exports.move = exports.move =
signature: 'device move <uuid>' signature: 'device move <uuid>'
@ -342,7 +335,7 @@ exports.move =
''' '''
permission: 'user' permission: 'user'
options: [ commandOptions.optionalApplication ] options: [ commandOptions.optionalApplication ]
action: (params, options, done) -> action: (params, options) ->
normalizeUuidProp(params) normalizeUuidProp(params)
balena = getBalenaSdk() balena = getBalenaSdk()
patterns = require('../utils/patterns') patterns = require('../utils/patterns')
@ -370,7 +363,6 @@ exports.move =
return balena.models.device.move(params.uuid, application) return balena.models.device.move(params.uuid, application)
.then (application) -> .then (application) ->
console.info("#{params.uuid} was moved to #{application}") console.info("#{params.uuid} was moved to #{application}")
.nodeify(done)
exports.init = exports.init =
signature: 'device init' signature: 'device init'
@ -399,7 +391,7 @@ exports.init =
} }
] ]
permission: 'user' permission: 'user'
action: (params, options, done) -> action: (params, options) ->
Promise = require('bluebird') Promise = require('bluebird')
rimraf = Promise.promisify(require('rimraf')) rimraf = Promise.promisify(require('rimraf'))
tmp = require('tmp') tmp = require('tmp')
@ -449,7 +441,5 @@ exports.init =
console.log('Done') console.log('Done')
return device.uuid return device.uuid
.nodeify(done)
tsActions = require('./device_ts') tsActions = require('./device_ts')
exports.osUpdate = tsActions.osUpdate exports.osUpdate = tsActions.osUpdate

View File

@ -46,7 +46,7 @@ export const osUpdate: CommandDefinition<OsUpdate.Args, OsUpdate.Options> = {
`, `,
options: [commandOptions.optionalOsVersion, commandOptions.yes], options: [commandOptions.optionalOsVersion, commandOptions.yes],
permission: 'user', permission: 'user',
async action(params, options, done) { async action(params, options) {
normalizeUuidProp(params); normalizeUuidProp(params);
const _ = await import('lodash'); const _ = await import('lodash');
const sdk = getBalenaSdk(); const sdk = getBalenaSdk();
@ -109,7 +109,6 @@ export const osUpdate: CommandDefinition<OsUpdate.Args, OsUpdate.Options> = {
.then(() => sdk.models.device.startOsUpdate(uuid, version)) .then(() => sdk.models.device.startOsUpdate(uuid, version))
.then(() => patterns.awaitDeviceOsUpdate(uuid, version)), .then(() => patterns.awaitDeviceOsUpdate(uuid, version)),
); );
}) });
.nodeify(done);
}, },
}; };

View File

@ -25,7 +25,7 @@ exports.osInit =
''' '''
hidden: true hidden: true
root: true root: true
action: (params, options, done) -> action: (params) ->
Promise = require('bluebird') Promise = require('bluebird')
init = require('balena-device-init') init = require('balena-device-init')
helpers = require('../utils/helpers') helpers = require('../utils/helpers')
@ -35,7 +35,6 @@ exports.osInit =
Promise.join configPromise, manifestPromise, (config, manifest) -> Promise.join configPromise, manifestPromise, (config, manifest) ->
init.initialize(params.image, manifest, config) init.initialize(params.image, manifest, config)
.then(helpers.osProgressHandler) .then(helpers.osProgressHandler)
.nodeify(done)
exports.scanDevices = exports.scanDevices =
signature: 'internal scandevices' signature: 'internal scandevices'
@ -45,7 +44,7 @@ exports.scanDevices =
''' '''
hidden: true hidden: true
root: true root: true
action: (params, options, done) -> action: ->
Promise = require('bluebird') Promise = require('bluebird')
{ forms } = require('balena-sync') { forms } = require('balena-sync')
@ -53,4 +52,3 @@ exports.scanDevices =
forms.selectLocalBalenaOsDevice() forms.selectLocalBalenaOsDevice()
.then (hostnameOrIp) -> .then (hostnameOrIp) ->
console.error("==> Selected device: #{hostnameOrIp}") console.error("==> Selected device: #{hostnameOrIp}")
.nodeify(done)

View File

@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import * as Bluebird from 'bluebird';
import { CommandDefinition } from 'capitano'; import { CommandDefinition } from 'capitano';
import { stripIndent } from 'common-tags'; import { stripIndent } from 'common-tags';
import { getBalenaSdk } from '../utils/lazy'; import { getBalenaSdk } from '../utils/lazy';
@ -64,13 +63,11 @@ export const join: CommandDefinition<Args, Options> = {
permission: 'user', permission: 'user',
primary: true, primary: true,
async action(params, options, done) { async action(params, options) {
const Logger = await import('../utils/logger'); const Logger = await import('../utils/logger');
const promote = await import('../utils/promote'); const promote = await import('../utils/promote');
const sdk = getBalenaSdk(); const sdk = getBalenaSdk();
const logger = Logger.getLogger(); const logger = Logger.getLogger();
return Bluebird.try(() => { return promote.join(logger, sdk, params.deviceIp, options.application);
return promote.join(logger, sdk, params.deviceIp, options.application);
}).nodeify(done);
}, },
}; };

View File

@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import * as Bluebird from 'bluebird';
import { CommandDefinition } from 'capitano'; import { CommandDefinition } from 'capitano';
import { stripIndent } from 'common-tags'; import { stripIndent } from 'common-tags';
import { getBalenaSdk } from '../utils/lazy'; import { getBalenaSdk } from '../utils/lazy';
@ -47,13 +46,11 @@ export const leave: CommandDefinition<Args, {}> = {
permission: 'user', permission: 'user',
primary: true, primary: true,
async action(params, _options, done) { async action(params) {
const Logger = await import('../utils/logger'); const Logger = await import('../utils/logger');
const promote = await import('../utils/promote'); const promote = await import('../utils/promote');
const sdk = getBalenaSdk(); const sdk = getBalenaSdk();
const logger = Logger.getLogger(); const logger = Logger.getLogger();
return Bluebird.try(() => { return promote.leave(logger, sdk, params.deviceIp);
return promote.leave(logger, sdk, params.deviceIp);
}).nodeify(done);
}, },
}; };

View File

@ -203,7 +203,7 @@ module.exports =
$ balena local configure path/to/image.img $ balena local configure path/to/image.img
''' '''
root: true root: true
action: (params, options, done) -> action: (params, options) ->
Promise = require('bluebird') Promise = require('bluebird')
path = require('path') path = require('path')
umount = require('umount') umount = require('umount')
@ -234,4 +234,3 @@ module.exports =
denymount params.target, dmHandler, dmOpts denymount params.target, dmHandler, dmOpts
.then -> .then ->
console.log('Done!') console.log('Done!')
.asCallback(done)

View File

@ -62,7 +62,7 @@ module.exports =
alias: 'p' alias: 'p'
] ]
root: true root: true
action: (params, options, done) -> action: (params, options) ->
child_process = require('child_process') child_process = require('child_process')
Promise = require 'bluebird' Promise = require 'bluebird'
_ = require('lodash') _ = require('lodash')
@ -111,4 +111,3 @@ module.exports =
subShellCommand = getSubShellCommand(command) subShellCommand = getSubShellCommand(command)
child_process.spawn subShellCommand.program, subShellCommand.args, child_process.spawn subShellCommand.program, subShellCommand.args,
stdio: 'inherit' stdio: 'inherit'
.nodeify(done)

View File

@ -44,7 +44,7 @@ module.exports =
alias: 'a' alias: 'a'
] ]
root: true root: true
action: (params, options, done) -> action: (params, options) ->
Promise = require('bluebird') Promise = require('bluebird')
chalk = require('chalk') chalk = require('chalk')
{ forms, config, BalenaLocalDockerUtils } = require('balena-sync') { forms, config, BalenaLocalDockerUtils } = require('balena-sync')

View File

@ -56,7 +56,7 @@ exports.versions =
$ balena os versions raspberrypi3 $ balena os versions raspberrypi3
''' '''
action: (params, options, done) -> action: (params, options) ->
balena = getBalenaSdk() balena = getBalenaSdk()
balena.models.os.getSupportedVersions(params.type) balena.models.os.getSupportedVersions(params.type)
@ -98,7 +98,7 @@ exports.download =
} }
commandOptions.osVersionOrSemver commandOptions.osVersionOrSemver
] ]
action: (params, options, done) -> action: (params, options) ->
Promise = require('bluebird') Promise = require('bluebird')
unzip = require('node-unzip-2') unzip = require('node-unzip-2')
fs = require('fs') fs = require('fs')
@ -145,7 +145,6 @@ exports.download =
return rindle.wait(stream.pipe(output)).return(options.output) return rindle.wait(stream.pipe(output)).return(options.output)
.tap (output) -> .tap (output) ->
console.info('The image was downloaded successfully') console.info('The image was downloaded successfully')
.nodeify(done)
buildConfigForDeviceType = (deviceType, advanced = false) -> buildConfigForDeviceType = (deviceType, advanced = false) ->
form = require('resin-cli-form') form = require('resin-cli-form')
@ -192,7 +191,7 @@ exports.buildConfig =
parameter: 'output' parameter: 'output'
} }
] ]
action: (params, options, done) -> action: (params, options) ->
fs = require('fs') fs = require('fs')
Promise = require('bluebird') Promise = require('bluebird')
writeFileAsync = Promise.promisify(fs.writeFile) writeFileAsync = Promise.promisify(fs.writeFile)
@ -200,7 +199,6 @@ exports.buildConfig =
buildConfig(params.image, params['device-type'], options.advanced) buildConfig(params.image, params['device-type'], options.advanced)
.then (answers) -> .then (answers) ->
writeFileAsync(options.output, JSON.stringify(answers, null, 4)) writeFileAsync(options.output, JSON.stringify(answers, null, 4))
.nodeify(done)
INIT_WARNING_MESSAGE = ''' INIT_WARNING_MESSAGE = '''
Note: Initializing the device may ask for administrative permissions Note: Initializing the device may ask for administrative permissions
@ -231,7 +229,7 @@ exports.initialize =
} }
commandOptions.drive commandOptions.drive
] ]
action: (params, options, done) -> action: (params, options) ->
Promise = require('bluebird') Promise = require('bluebird')
umountAsync = Promise.promisify(require('umount').umount) umountAsync = Promise.promisify(require('umount').umount)
form = require('resin-cli-form') form = require('resin-cli-form')
@ -288,4 +286,3 @@ exports.initialize =
umountAsync(answers.drive).tap -> umountAsync(answers.drive).tap ->
console.info("You can safely remove #{answers.drive} now") console.info("You can safely remove #{answers.drive} now")
.nodeify(done)

View File

@ -70,7 +70,7 @@ module.exports =
] ]
primary: true primary: true
root: true root: true
action: (params, options, done) -> action: (params, options) ->
Promise = require('bluebird') Promise = require('bluebird')
_ = require('lodash') _ = require('lodash')
prettyjson = require('prettyjson') prettyjson = require('prettyjson')
@ -111,4 +111,3 @@ module.exports =
return { host, address, dockerInfo, dockerVersion } return { host, address, dockerInfo, dockerVersion }
.then (devicesInfo) -> .then (devicesInfo) ->
console.log(prettyjson.render(devicesInfo, noColor: true)) console.log(prettyjson.render(devicesInfo, noColor: true))
.nodeify(done)

View File

@ -27,13 +27,12 @@ Examples:
$ balena settings\ $ balena settings\
`, `,
async action(_params, _options, done) { async action() {
const prettyjson = await import('prettyjson'); const prettyjson = await import('prettyjson');
return getBalenaSdk() return getBalenaSdk()
.settings.getAll() .settings.getAll()
.then(prettyjson.render) .then(prettyjson.render)
.then(console.log) .then(console.log);
.nodeify(done);
}, },
}; };

View File

@ -54,7 +54,7 @@ export const list: CommandDefinition<
commandOptions.optionalRelease, commandOptions.optionalRelease,
], ],
permission: 'user', permission: 'user',
async action(_params, options, done) { async action(_params, options) {
normalizeUuidProp(options, 'device'); normalizeUuidProp(options, 'device');
const Bluebird = await import('bluebird'); const Bluebird = await import('bluebird');
const _ = await import('lodash'); const _ = await import('lodash');
@ -104,21 +104,19 @@ export const list: CommandDefinition<
// return never, so that TS typings are happy // return never, so that TS typings are happy
return exitWithExpectedError(wrongParametersError); return exitWithExpectedError(wrongParametersError);
}, },
) ).tap(function(environmentVariables) {
.tap(function(environmentVariables) { if (_.isEmpty(environmentVariables)) {
if (_.isEmpty(environmentVariables)) { exitWithExpectedError('No tags found');
exitWithExpectedError('No tags found'); }
}
console.log( console.log(
visuals.table.horizontal(environmentVariables, [ visuals.table.horizontal(environmentVariables, [
'id', 'id',
'tag_key', 'tag_key',
'value', 'value',
]), ]),
); );
}) });
.nodeify(done);
}, },
}; };
@ -159,24 +157,22 @@ export const set: CommandDefinition<
commandOptions.optionalRelease, commandOptions.optionalRelease,
], ],
permission: 'user', permission: 'user',
async action(params, options, done) { async action(params, options) {
normalizeUuidProp(options, 'device'); normalizeUuidProp(options, 'device');
const Bluebird = await import('bluebird');
const _ = await import('lodash'); const _ = await import('lodash');
const balena = getBalenaSdk(); const balena = getBalenaSdk();
const { exitWithExpectedError } = await import('../utils/patterns'); const { exitWithExpectedError } = await import('../utils/patterns');
return Bluebird.try(async () => { if (_.isEmpty(params.tagKey)) {
if (_.isEmpty(params.tagKey)) { return exitWithExpectedError('No tag key was provided');
return exitWithExpectedError('No tag key was provided'); }
}
if ( if (
_.filter([options.application, options.device, options.release]) _.filter([options.application, options.device, options.release])
.length !== 1 .length !== 1
) { ) {
return exitWithExpectedError(stripIndent` return exitWithExpectedError(stripIndent`
To set a resource tag, you must provide exactly one of: To set a resource tag, you must provide exactly one of:
* An application, with --application <appname> * An application, with --application <appname>
@ -187,40 +183,39 @@ export const set: CommandDefinition<
$ balena help tag set $ balena help tag set
`); `);
} }
if (params.value == null) { if (params.value == null) {
params.value = ''; params.value = '';
} }
if (options.application) { if (options.application) {
return balena.models.application.tags.set( return balena.models.application.tags.set(
options.application, options.application,
params.tagKey, params.tagKey,
params.value, params.value,
); );
} }
if (options.device) { if (options.device) {
return balena.models.device.tags.set( return balena.models.device.tags.set(
options.device, options.device,
params.tagKey, params.tagKey,
params.value, params.value,
); );
} }
if (options.release) { if (options.release) {
const releaseParam = await disambiguateReleaseParam( const releaseParam = await disambiguateReleaseParam(
balena, balena,
options.release, options.release,
options.release_raw, options.release_raw,
); );
return balena.models.release.tags.set( return balena.models.release.tags.set(
releaseParam, releaseParam,
params.tagKey, params.tagKey,
params.value, params.value,
); );
} }
}).nodeify(done);
}, },
}; };
@ -253,52 +248,49 @@ export const remove: CommandDefinition<
commandOptions.optionalRelease, commandOptions.optionalRelease,
], ],
permission: 'user', permission: 'user',
async action(params, options, done) { async action(params, options) {
const Bluebird = await import('bluebird');
const _ = await import('lodash'); const _ = await import('lodash');
const balena = getBalenaSdk(); const balena = getBalenaSdk();
const { exitWithExpectedError } = await import('../utils/patterns'); const { exitWithExpectedError } = await import('../utils/patterns');
return Bluebird.try(async () => { if (_.isEmpty(params.tagKey)) {
if (_.isEmpty(params.tagKey)) { return exitWithExpectedError('No tag key was provided');
return exitWithExpectedError('No tag key was provided'); }
}
if ( if (
_.filter([options.application, options.device, options.release]) _.filter([options.application, options.device, options.release])
.length !== 1 .length !== 1
) { ) {
return exitWithExpectedError(stripIndent` return exitWithExpectedError(stripIndent`
To remove a resource tag, you must provide exactly one of: To remove a resource tag, you must provide exactly one of:
* An application, with --application <appname> * An application, with --application <appname>
* A device, with --device <uuid> * A device, with --device <uuid>
* A release, with --release <id or commit> * A release, with --release <id or commit>
See the help page for examples: See the help page for examples:
$ balena help tag rm $ balena help tag rm
`); `);
} }
if (options.application) { if (options.application) {
return balena.models.application.tags.remove( return balena.models.application.tags.remove(
options.application, options.application,
params.tagKey, params.tagKey,
); );
} }
if (options.device) { if (options.device) {
return balena.models.device.tags.remove(options.device, params.tagKey); return balena.models.device.tags.remove(options.device, params.tagKey);
} }
if (options.release) { if (options.release) {
const releaseParam = await disambiguateReleaseParam( const releaseParam = await disambiguateReleaseParam(
balena, balena,
options.release, options.release,
options.release_raw, options.release_raw,
); );
return balena.models.release.tags.remove(releaseParam, params.tagKey); return balena.models.release.tags.remove(releaseParam, params.tagKey);
} }
}).nodeify(done);
}, },
}; };