diff --git a/lib/actions/logs.coffee b/lib/actions/logs.coffee index c4f55315..a83ef2c7 100644 --- a/lib/actions/logs.coffee +++ b/lib/actions/logs.coffee @@ -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 diff --git a/lib/app.coffee b/lib/app.coffee index bbc07308..8f7d30e2 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -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 diff --git a/lib/resin/cli/cli.coffee b/lib/resin/cli/cli.coffee index e8e99cf4..8b936a7f 100644 --- a/lib/resin/cli/cli.coffee +++ b/lib/resin/cli/cli.coffee @@ -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) ->