Implement logs -n/--num

This commit is contained in:
Juan Cruz Viotti 2014-11-28 20:18:59 -04:00
parent 4702e7b563
commit 25af7a2231
3 changed files with 29 additions and 5 deletions

View File

@ -19,8 +19,18 @@ 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
@ -28,6 +38,7 @@ exports.logs = (uuid) ->
channel: channel
callback: printLogs
if not numberOfLines?
pubnub.subscribe
channel: channel
callback: printLogs

View File

@ -23,6 +23,10 @@ resin.cli.addOption
option: '-t, --type <type>'
description: 'specify a type when creating an application'
resin.cli.addOption
option: '-n, --num <num>'
description: 'number of lines to display'
# TODO: I have to use 'application' instead of 'app' here
# as Commander gets confused with the app command
resin.cli.addOption

View File

@ -6,8 +6,17 @@ log = require('../log/log')
errors = require('../errors/errors')
cliPermissions = require('./cli-permissions')
exports.getArgument = (name) ->
return program[name]
exports.getArgument = (name, coerceFunction) ->
argument = program[name]
return if not argument?
if _.isFunction(coerceFunction)
argument = coerceFunction(argument)
if not argument? or _.isNaN(argument)
throw new Error('Coerce function failed')
return argument
exports.setVersion = (version) ->
program.version(version)