mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-07 19:34:13 +00:00
Move log and errors to resin module
This commit is contained in:
parent
8b81fbdbbd
commit
edcee1c9cf
@ -2,8 +2,6 @@ _ = require('lodash')
|
||||
async = require('async')
|
||||
device = require('../device/device')
|
||||
table = require('../table/table')
|
||||
errors = require('../errors/errors')
|
||||
log = require('../log/log')
|
||||
resin = require('../resin')
|
||||
widgets = require('../widgets/widgets')
|
||||
patterns = require('../patterns/patterns')
|
||||
@ -32,12 +30,12 @@ exports.create = authHooks.failIfNotLoggedIn (name, program) ->
|
||||
return callback()
|
||||
.catch(callback)
|
||||
|
||||
], errors.handle
|
||||
], resin.errors.handle
|
||||
|
||||
exports.list = authHooks.failIfNotLoggedIn ->
|
||||
resin.models.application.getAll().then (applications) ->
|
||||
|
||||
log.out table.horizontal applications, (application) ->
|
||||
resin.log.out table.horizontal applications, (application) ->
|
||||
application.device_type = device.getDisplayName(application.device_type)
|
||||
application['Online Devices'] = _.where(application.device, is_online: 1).length
|
||||
application['All Devices'] = application.device?.length or 0
|
||||
@ -46,27 +44,27 @@ exports.list = authHooks.failIfNotLoggedIn ->
|
||||
return application
|
||||
, [ 'ID', 'Name', 'Device Type', 'Online Devices', 'All Devices' ]
|
||||
|
||||
.catch(errors.handle)
|
||||
.catch(resin.errors.handle)
|
||||
|
||||
exports.info = authHooks.failIfNotLoggedIn (id) ->
|
||||
resin.models.application.get(id).then (application) ->
|
||||
|
||||
log.out table.vertical application, (application) ->
|
||||
resin.log.out table.vertical application, (application) ->
|
||||
application.device_type = device.getDisplayName(application.device_type)
|
||||
delete application.device
|
||||
return application
|
||||
, [ 'ID', 'Name', 'Device Type', 'Git Repository', 'Commit' ]
|
||||
|
||||
.catch(errors.handle)
|
||||
.catch(resin.errors.handle)
|
||||
|
||||
exports.restart = authHooks.failIfNotLoggedIn (id) ->
|
||||
|
||||
# TODO: Move this URL to config
|
||||
resin.server.post("/application/#{id}/restart", errors.handle)
|
||||
resin.server.post("/application/#{id}/restart", resin.errors.handle)
|
||||
|
||||
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
|
||||
patterns.remove 'application', program.parent.yes, (callback) ->
|
||||
resin.models.application.remove(id).then ->
|
||||
return callback()
|
||||
.catch(callback)
|
||||
, errors.handle
|
||||
, resin.errors.handle
|
||||
|
@ -1,7 +1,6 @@
|
||||
open = require('open')
|
||||
async = require('async')
|
||||
auth = require('../auth/auth')
|
||||
errors = require('../errors/errors')
|
||||
authHooks = require('../hooks/auth')
|
||||
widgets = require('../widgets/widgets')
|
||||
config = require('../config')
|
||||
@ -18,7 +17,7 @@ exports.login = (credentials) ->
|
||||
(credentials, callback) ->
|
||||
auth.login(credentials, callback)
|
||||
|
||||
], errors.handle
|
||||
], resin.errors.handle
|
||||
|
||||
exports.logout = authHooks.failIfNotLoggedIn ->
|
||||
auth.logout()
|
||||
|
@ -1,7 +1,5 @@
|
||||
getDeviceDisplayName = require('../device/device').getDisplayName
|
||||
log = require('../log/log')
|
||||
table = require('../table/table')
|
||||
errors = require('../errors/errors')
|
||||
resin = require('../resin')
|
||||
widgets = require('../widgets/widgets')
|
||||
patterns = require('../patterns/patterns')
|
||||
@ -11,7 +9,7 @@ config = require('../config')
|
||||
exports.list = authHooks.failIfNotLoggedIn (applicationId) ->
|
||||
resin.models.device.getAll(applicationId).then (devices) ->
|
||||
|
||||
log.out table.horizontal devices, (device) ->
|
||||
resin.log.out table.horizontal devices, (device) ->
|
||||
device.application = device.application[0].app_name
|
||||
device.device_type = getDeviceDisplayName(device.device_type)
|
||||
delete device.note
|
||||
@ -21,14 +19,14 @@ exports.list = authHooks.failIfNotLoggedIn (applicationId) ->
|
||||
return device
|
||||
, [ 'ID', 'Name', 'Device Type', 'Is Online', 'IP Address', 'Application', 'Status', 'Last Seen' ]
|
||||
|
||||
.catch(errors.handle)
|
||||
.catch(resin.errors.handle)
|
||||
|
||||
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
|
||||
patterns.remove 'device', program.parent.yes, (callback) ->
|
||||
resin.models.device.remove(id).then ->
|
||||
return callback()
|
||||
.catch(callback)
|
||||
, errors.handle
|
||||
, resin.errors.handle
|
||||
|
||||
exports.identify = authHooks.failIfNotLoggedIn (uuid) ->
|
||||
resin.server.post(config.urls.identify, { uuid }, errors.handle)
|
||||
resin.server.post(config.urls.identify, { uuid }, resin.errors.handle)
|
||||
|
@ -1,8 +1,6 @@
|
||||
_ = require('lodash')
|
||||
table = require('../table/table')
|
||||
errors = require('../errors/errors')
|
||||
patterns = require('../patterns/patterns')
|
||||
log = require('../log/log')
|
||||
resin = require('../resin')
|
||||
authHooks = require('../hooks/auth')
|
||||
|
||||
@ -15,19 +13,19 @@ exports.list = authHooks.failIfNotLoggedIn (program) ->
|
||||
applicationId = program.parent?.application
|
||||
|
||||
if not applicationId?
|
||||
errors.handle(new Error('You have to specify an application'))
|
||||
resin.errors.handle(new Error('You have to specify an application'))
|
||||
|
||||
resin.models.environmentVariables.getAll(applicationId).then (environmentVariables) ->
|
||||
|
||||
if not program.parent.verbose?
|
||||
environmentVariables = _.reject(environmentVariables, isSystemVariable)
|
||||
|
||||
log.out(table.horizontal(environmentVariables))
|
||||
.catch(errors.handle)
|
||||
resin.log.out(table.horizontal(environmentVariables))
|
||||
.catch(resin.errors.handle)
|
||||
|
||||
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
|
||||
patterns.remove 'environment variable', program.parent.yes, (callback) ->
|
||||
resin.models.environmentVariables.remove(id).then ->
|
||||
return callback()
|
||||
.catch(callback)
|
||||
, errors.handle
|
||||
, resin.errors.handle
|
||||
|
@ -1,17 +1,15 @@
|
||||
_ = require('lodash')
|
||||
resin = require('../resin')
|
||||
authHooks = require('../hooks/auth')
|
||||
log = require('../log/log')
|
||||
patterns = require('../patterns/patterns')
|
||||
table = require('../table/table')
|
||||
helpers = require('../helpers/helpers')
|
||||
errors = require('../errors/errors')
|
||||
config = require('../config')
|
||||
|
||||
exports.list = authHooks.failIfNotLoggedIn ->
|
||||
resin.server.get config.urls.keys, (error, response, keys) ->
|
||||
errors.handle(error) if error?
|
||||
log.out table.horizontal keys, (key) ->
|
||||
resin.errors.handle(error) if error?
|
||||
resin.log.out table.horizontal keys, (key) ->
|
||||
delete key.public_key
|
||||
return key
|
||||
, [ 'ID', 'Title' ]
|
||||
@ -23,15 +21,15 @@ exports.info = authHooks.failIfNotLoggedIn (id) ->
|
||||
# As a workaround, we request all of them, and filter
|
||||
# the one we need. Fix once we have a better way.
|
||||
resin.server.get config.urls.keys, (error, response, keys) ->
|
||||
errors.handle(error) if error?
|
||||
resin.errors.handle(error) if error?
|
||||
key = _.findWhere(keys, { id })
|
||||
if not key?
|
||||
errors.handle(new errors.NotFound("key #{id}"))
|
||||
resin.errors.handle(new resin.errors.NotFound("key #{id}"))
|
||||
|
||||
key.public_key = '\n' + helpers.formatLongString(key.public_key, config.sshKeyWidth)
|
||||
log.out(table.vertical(key, _.identity, [ 'ID', 'Title', 'Public Key' ]))
|
||||
resin.log.out(table.vertical(key, _.identity, [ 'ID', 'Title', 'Public Key' ]))
|
||||
|
||||
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
|
||||
patterns.remove 'key', program.parent.yes, (callback) ->
|
||||
resin.server.delete("/user/keys/#{id}", callback)
|
||||
, errors.handle
|
||||
, resin.errors.handle
|
||||
|
@ -1,6 +1,6 @@
|
||||
_ = require('lodash')
|
||||
data = require('./data/data')
|
||||
log = require('./log/log')
|
||||
resin = require('./resin')
|
||||
config = require('./config')
|
||||
packageJSON = require('../package.json')
|
||||
|
||||
@ -94,7 +94,7 @@ program
|
||||
.command('version')
|
||||
.description('Show version')
|
||||
.action ->
|
||||
log.out(packageJSON.version)
|
||||
resin.log.out(packageJSON.version)
|
||||
|
||||
# ---------- Keys Module ----------
|
||||
keys = require('./actions/keys')
|
||||
@ -130,4 +130,4 @@ program
|
||||
data.prefix.set config.dataPrefix, (error) ->
|
||||
throw error if error?
|
||||
program.parse(process.argv)
|
||||
log.setQuiet(program.quiet)
|
||||
resin.log.setQuiet(program.quiet)
|
||||
|
@ -1,3 +1,5 @@
|
||||
module.exports =
|
||||
server: require('./server/server')
|
||||
models: require('./models')
|
||||
log: require('./log/log')
|
||||
errors: require('./errors/errors')
|
||||
|
@ -1,7 +1,7 @@
|
||||
_ = require('lodash')
|
||||
Promise = require('bluebird')
|
||||
canvas = require('./_canvas')
|
||||
errors = require('../../errors/errors')
|
||||
errors = require('../errors/errors')
|
||||
|
||||
exports.getAll = ->
|
||||
return canvas.get
|
||||
|
@ -1,7 +1,7 @@
|
||||
canvas = require('./_canvas')
|
||||
_ = require('lodash')
|
||||
Promise = require('bluebird')
|
||||
errors = require('../../errors/errors')
|
||||
errors = require('../errors/errors')
|
||||
|
||||
exports.getAll = (applicationId) ->
|
||||
return canvas.get
|
||||
|
@ -1,6 +1,6 @@
|
||||
Promise = require('bluebird')
|
||||
canvas = require('./_canvas')
|
||||
errors = require('../../errors/errors')
|
||||
errors = require('../errors/errors')
|
||||
|
||||
exports.getAll = (applicationId) ->
|
||||
return canvas.get
|
||||
|
Loading…
x
Reference in New Issue
Block a user