mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 13:47:52 +00:00
Move log out of resin sdk
This commit is contained in:
parent
5ae3077df9
commit
2351fa25a0
@ -3,6 +3,7 @@ async = require('async')
|
||||
gitCli = require('git-cli')
|
||||
resin = require('../resin')
|
||||
ui = require('../ui')
|
||||
log = require('../log/log')
|
||||
permissions = require('../permissions/permissions')
|
||||
|
||||
exports.create = permissions.user (params, options) ->
|
||||
@ -31,7 +32,7 @@ exports.list = permissions.user ->
|
||||
resin.models.application.getAll (error, applications) ->
|
||||
resin.errors.handle(error) if error?
|
||||
|
||||
resin.log.out ui.widgets.table.horizontal applications, (application) ->
|
||||
log.out ui.widgets.table.horizontal applications, (application) ->
|
||||
application.device_type = resin.device.getDisplayName(application.device_type)
|
||||
application['Online Devices'] = _.where(application.device, is_online: 1).length
|
||||
application['All Devices'] = application.device?.length or 0
|
||||
@ -44,7 +45,7 @@ exports.info = permissions.user (params) ->
|
||||
resin.models.application.get params.id, (error, application) ->
|
||||
resin.errors.handle(error) if error?
|
||||
|
||||
resin.log.out ui.widgets.table.vertical application, (application) ->
|
||||
log.out ui.widgets.table.vertical application, (application) ->
|
||||
application.device_type = resin.device.getDisplayName(application.device_type)
|
||||
delete application.device
|
||||
return application
|
||||
|
@ -3,6 +3,7 @@ open = require('open')
|
||||
async = require('async')
|
||||
resin = require('../resin')
|
||||
ui = require('../ui')
|
||||
log = require('../log/log')
|
||||
permissions = require('../permissions/permissions')
|
||||
|
||||
exports.login = (params) ->
|
||||
@ -35,4 +36,4 @@ exports.whoami = permissions.user ->
|
||||
error = new Error('Username not found')
|
||||
resin.errors.handle(error)
|
||||
|
||||
resin.log.out(username)
|
||||
log.out(username)
|
||||
|
@ -2,13 +2,14 @@ _ = require('lodash')
|
||||
async = require('async')
|
||||
resin = require('../resin')
|
||||
ui = require('../ui')
|
||||
log = require('../log/log')
|
||||
permissions = require('../permissions/permissions')
|
||||
|
||||
exports.list = permissions.user (params) ->
|
||||
resin.models.device.getAllByApplication params.id, (error, devices) ->
|
||||
resin.errors.handle(error) if error?
|
||||
|
||||
resin.log.out ui.widgets.table.horizontal devices, (device) ->
|
||||
log.out ui.widgets.table.horizontal devices, (device) ->
|
||||
device.application = device.application[0].app_name
|
||||
device.device_type = resin.device.getDisplayName(device.device_type)
|
||||
delete device.note
|
||||
@ -22,7 +23,7 @@ exports.info = permissions.user (params) ->
|
||||
resin.models.device.get params.id, (error, device) ->
|
||||
resin.errors.handle(error) if error?
|
||||
|
||||
resin.log.out ui.widgets.table.vertical device, (device) ->
|
||||
log.out ui.widgets.table.vertical device, (device) ->
|
||||
device.device_type = resin.device.getDisplayName(device.device_type)
|
||||
device.application = device.application[0].app_name
|
||||
return device
|
||||
|
@ -2,6 +2,7 @@ _ = require('lodash')
|
||||
resin = require('../resin')
|
||||
ui = require('../ui')
|
||||
permissions = require('../permissions/permissions')
|
||||
log = require('../log/log')
|
||||
|
||||
SYSTEM_VAR_REGEX = /^RESIN_/
|
||||
|
||||
@ -18,7 +19,7 @@ exports.list = permissions.user (params, options) ->
|
||||
if not options.verbose
|
||||
environmentVariables = _.reject(environmentVariables, isSystemVariable)
|
||||
|
||||
resin.log.out(ui.widgets.table.horizontal(environmentVariables))
|
||||
log.out(ui.widgets.table.horizontal(environmentVariables))
|
||||
|
||||
exports.remove = permissions.user (params, options) ->
|
||||
ui.patterns.remove 'environment variable', options.yes, (callback) ->
|
||||
@ -35,7 +36,7 @@ exports.add = permissions.user (params, options) ->
|
||||
if not params.value?
|
||||
resin.errors.handle(new Error("Environment value not found for key: #{params.key}"))
|
||||
else
|
||||
resin.log.info("Warning: using #{params.key}=#{params.value} from host environment")
|
||||
log.info("Warning: using #{params.key}=#{params.value} from host environment")
|
||||
|
||||
resin.models.environmentVariables.create options.application, params.key, params.value, (error) ->
|
||||
resin.errors.handle(error) if error?
|
||||
|
@ -6,6 +6,7 @@ gitCli = require('git-cli')
|
||||
resin = require('../resin')
|
||||
permissions = require('../permissions/permissions')
|
||||
ui = require('../ui')
|
||||
log = require('../log/log')
|
||||
examplesData = require('../data/examples.json')
|
||||
|
||||
exports.list = permissions.user ->
|
||||
@ -14,7 +15,7 @@ exports.list = permissions.user ->
|
||||
example.id = index + 1
|
||||
return example
|
||||
|
||||
resin.log.out ui.widgets.table.horizontal examplesData, (example) ->
|
||||
log.out ui.widgets.table.horizontal examplesData, (example) ->
|
||||
delete example.description
|
||||
delete example.name
|
||||
example.author ?= 'Unknown'
|
||||
@ -29,7 +30,7 @@ exports.info = permissions.user (params) ->
|
||||
error = new Error("Unknown example: #{id}")
|
||||
resin.errors.handle(error)
|
||||
|
||||
resin.log.out ui.widgets.table.vertical example, (example) ->
|
||||
log.out ui.widgets.table.vertical example, (example) ->
|
||||
delete example.name
|
||||
example.id = id
|
||||
example.author ?= 'Unknown'
|
||||
@ -60,7 +61,7 @@ exports.clone = permissions.user (params) ->
|
||||
return callback(error)
|
||||
|
||||
(callback) ->
|
||||
resin.log.info("Cloning #{example.display_name} to #{example.name}")
|
||||
log.info("Cloning #{example.display_name} to #{example.name}")
|
||||
gitCli.Repository.clone(example.repository, example.name, callback)
|
||||
|
||||
], (error) ->
|
||||
|
@ -2,6 +2,7 @@ _ = require('lodash')
|
||||
_.str = require('underscore.string')
|
||||
resin = require('../resin')
|
||||
capitano = require('capitano')
|
||||
log = require('../log/log')
|
||||
|
||||
# TODO: Refactor this terrible mess
|
||||
|
||||
@ -61,14 +62,14 @@ getOptionHelp = (option, maxLength) ->
|
||||
return result
|
||||
|
||||
exports.general = ->
|
||||
resin.log.out("Usage: #{process.argv[0]} [COMMAND] [OPTIONS]\n")
|
||||
resin.log.out('Commands:\n')
|
||||
log.out("Usage: #{process.argv[0]} [COMMAND] [OPTIONS]\n")
|
||||
log.out('Commands:\n')
|
||||
|
||||
for command in capitano.state.commands
|
||||
continue if command.isWildcard()
|
||||
resin.log.out(getCommandHelp(command))
|
||||
log.out(getCommandHelp(command))
|
||||
|
||||
resin.log.out('\nGlobal Options:\n')
|
||||
log.out('\nGlobal Options:\n')
|
||||
|
||||
options = _.map capitano.state.globalOptions, (option) ->
|
||||
option.signature = buildOptionSignatureHelp(option)
|
||||
@ -78,9 +79,9 @@ exports.general = ->
|
||||
return option.signature.length
|
||||
|
||||
for option in options
|
||||
resin.log.out(getOptionHelp(option, optionSignatureMaxLength))
|
||||
log.out(getOptionHelp(option, optionSignatureMaxLength))
|
||||
|
||||
resin.log.out()
|
||||
log.out()
|
||||
|
||||
exports.command = (params) ->
|
||||
command = capitano.state.getMatchCommand(params.command)
|
||||
@ -88,15 +89,15 @@ exports.command = (params) ->
|
||||
if not command? or command.isWildcard()
|
||||
return capitano.defaults.actions.commandNotFound(params.command)
|
||||
|
||||
resin.log.out("Usage: #{command.signature}")
|
||||
log.out("Usage: #{command.signature}")
|
||||
|
||||
if command.help?
|
||||
resin.log.out("\n#{command.help}")
|
||||
log.out("\n#{command.help}")
|
||||
else if command.description?
|
||||
resin.log.out("\n#{_.str.humanize(command.description)}")
|
||||
log.out("\n#{_.str.humanize(command.description)}")
|
||||
|
||||
if not _.isEmpty(command.options)
|
||||
resin.log.out('\nOptions:\n')
|
||||
log.out('\nOptions:\n')
|
||||
|
||||
options = _.map command.options, (option) ->
|
||||
option.signature = buildOptionSignatureHelp(option)
|
||||
@ -106,6 +107,6 @@ exports.command = (params) ->
|
||||
return option.signature.toString().length
|
||||
|
||||
for option in options
|
||||
resin.log.out(getOptionHelp(option, optionSignatureMaxLength))
|
||||
log.out(getOptionHelp(option, optionSignatureMaxLength))
|
||||
|
||||
resin.log.out()
|
||||
log.out()
|
||||
|
@ -5,12 +5,13 @@ fs = require('fs')
|
||||
resin = require('../resin')
|
||||
helpers = require('../helpers/helpers')
|
||||
ui = require('../ui')
|
||||
log = require('../log/log')
|
||||
permissions = require('../permissions/permissions')
|
||||
|
||||
exports.list = permissions.user ->
|
||||
resin.server.get resin.settings.get('urls.keys'), (error, response, keys) ->
|
||||
resin.errors.handle(error) if error?
|
||||
resin.log.out ui.widgets.table.horizontal keys, (key) ->
|
||||
log.out ui.widgets.table.horizontal keys, (key) ->
|
||||
delete key.public_key
|
||||
return key
|
||||
, [ 'ID', 'Title' ]
|
||||
@ -27,7 +28,7 @@ exports.info = permissions.user (params) ->
|
||||
resin.errors.handle(new resin.errors.NotFound("key #{params.id}"))
|
||||
|
||||
key.public_key = '\n' + _.str.chop(key.public_key, resin.settings.get('sshKeyWidth')).join('\n')
|
||||
resin.log.out(ui.widgets.table.vertical(key, _.identity, [ 'ID', 'Title', 'Public Key' ]))
|
||||
log.out(ui.widgets.table.vertical(key, _.identity, [ 'ID', 'Title', 'Public Key' ]))
|
||||
|
||||
exports.remove = permissions.user (params, options) ->
|
||||
ui.patterns.remove 'key', options.yes, (callback) ->
|
||||
|
@ -3,6 +3,7 @@ PubNub = require('pubnub')
|
||||
resin = require('../resin')
|
||||
helpers = require('../helpers/helpers')
|
||||
permissions = require('../permissions/permissions')
|
||||
log = require('../log/log')
|
||||
|
||||
LOGS_HISTORY_COUNT = 200
|
||||
|
||||
@ -13,7 +14,7 @@ getLogData = (logs) ->
|
||||
printLogs = (logs, number) ->
|
||||
logs = getLogData(logs)
|
||||
logs = _.last(logs, number) if _.isNumber(number)
|
||||
resin.log.array(logs, resin.log.out)
|
||||
log.array(logs, log.out)
|
||||
|
||||
exports.logs = permissions.user (params, options) ->
|
||||
|
||||
|
@ -6,6 +6,7 @@ url = require('url')
|
||||
resin = require('../resin')
|
||||
connection = require('../connection/connection')
|
||||
ui = require('../ui')
|
||||
log = require('../log/log')
|
||||
permissions = require('../permissions/permissions')
|
||||
|
||||
exports.download = (params, options) ->
|
||||
@ -41,4 +42,4 @@ exports.download = (params, options) ->
|
||||
|
||||
], (error) ->
|
||||
resin.errors.handle(error) if error?
|
||||
resin.log.info("\nFinished downloading #{outputFile}")
|
||||
log.info("\nFinished downloading #{outputFile}")
|
||||
|
@ -1,6 +1,6 @@
|
||||
_ = require('lodash')
|
||||
TypedError = require('typed-error')
|
||||
log = require('../log/log')
|
||||
log = require('../../log/log')
|
||||
|
||||
exports.NotFound = class NotFound extends TypedError
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
expect = require('chai').expect
|
||||
sinon = require('sinon')
|
||||
log = require('../log/log')
|
||||
log = require('../../log/log')
|
||||
errors = require('./errors')
|
||||
|
||||
describe 'Errors:', ->
|
||||
|
@ -1,7 +1,6 @@
|
||||
module.exports =
|
||||
server: require('./server/server')
|
||||
models: require('./models')
|
||||
log: require('./log/log')
|
||||
errors: require('./errors/errors')
|
||||
token: require('./token/token')
|
||||
data: require('./data/data')
|
||||
|
Loading…
Reference in New Issue
Block a user