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" 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) -> printLogs = (logs) ->
logs = logs[0] if _.isArray(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) resin.log.array(logs, resin.log.out)
pubnub.history pubnub.history
@ -28,6 +38,7 @@ exports.logs = (uuid) ->
channel: channel channel: channel
callback: printLogs callback: printLogs
if not numberOfLines?
pubnub.subscribe pubnub.subscribe
channel: channel channel: channel
callback: printLogs callback: printLogs

View File

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

View File

@ -6,8 +6,17 @@ log = require('../log/log')
errors = require('../errors/errors') errors = require('../errors/errors')
cliPermissions = require('./cli-permissions') cliPermissions = require('./cli-permissions')
exports.getArgument = (name) -> exports.getArgument = (name, coerceFunction) ->
return program[name] 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) -> exports.setVersion = (version) ->
program.version(version) program.version(version)