mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-31 16:36:24 +00:00
Implement log tail option
This commit is contained in:
parent
25af7a2231
commit
8f13e9bf44
@ -5,7 +5,22 @@ helpers = require('../helpers/helpers')
|
||||
|
||||
LOGS_HISTORY_COUNT = 200
|
||||
|
||||
getLogData = (logs) ->
|
||||
return logs[0] if _.isArray(logs)
|
||||
return logs
|
||||
|
||||
printLogs = (logs, number) ->
|
||||
logs = getLogData(logs)
|
||||
logs = _.last(logs, number) if _.isNumber(number)
|
||||
resin.log.array(logs, resin.log.out)
|
||||
|
||||
exports.logs = (uuid) ->
|
||||
numberOfLines = resin.cli.getArgument('num', _.parseInt)
|
||||
tailOutput = resin.cli.getArgument('tail') or false
|
||||
|
||||
if numberOfLines? and not _.isNumber(numberOfLines)
|
||||
resin.errors.handle(new Error('n/num should be a number'))
|
||||
|
||||
helpers.isDeviceUUIDValid uuid, (error, isValidUUID) ->
|
||||
resin.errors.handle(error) if error?
|
||||
|
||||
@ -19,26 +34,15 @@ exports.logs = (uuid) ->
|
||||
|
||||
channel = "device-#{uuid}-logs"
|
||||
|
||||
numberOfLines = resin.cli.getArgument('num', _.parseInt)
|
||||
if numberOfLines? and not _.isNumber(numberOfLines)
|
||||
resin.errors.handle(new Error('n/num should be a number'))
|
||||
|
||||
printLogs = (logs) ->
|
||||
logs = logs[0] if _.isArray(logs)
|
||||
|
||||
if numberOfLines?
|
||||
logs = _.last(logs, numberOfLines)
|
||||
resin.log.array(logs, resin.log.out)
|
||||
process.exit(0)
|
||||
|
||||
resin.log.array(logs, resin.log.out)
|
||||
|
||||
pubnub.history
|
||||
count: LOGS_HISTORY_COUNT
|
||||
channel: channel
|
||||
callback: printLogs
|
||||
callback: (logs) ->
|
||||
printLogs(logs, numberOfLines)
|
||||
if not tailOutput or numberOfLines?
|
||||
process.exit(0)
|
||||
|
||||
if not numberOfLines?
|
||||
if tailOutput
|
||||
pubnub.subscribe
|
||||
channel: channel
|
||||
callback: printLogs
|
||||
|
@ -27,6 +27,10 @@ resin.cli.addOption
|
||||
option: '-n, --num <num>'
|
||||
description: 'number of lines to display'
|
||||
|
||||
resin.cli.addOption
|
||||
option: '--tail'
|
||||
description: 'continuously stream output'
|
||||
|
||||
# TODO: I have to use 'application' instead of 'app' here
|
||||
# as Commander gets confused with the app command
|
||||
resin.cli.addOption
|
||||
|
@ -13,9 +13,6 @@ exports.getArgument = (name, coerceFunction) ->
|
||||
if _.isFunction(coerceFunction)
|
||||
argument = coerceFunction(argument)
|
||||
|
||||
if not argument? or _.isNaN(argument)
|
||||
throw new Error('Coerce function failed')
|
||||
|
||||
return argument
|
||||
|
||||
exports.setVersion = (version) ->
|
||||
|
Loading…
x
Reference in New Issue
Block a user