logentries-query-cli
Advanced tools
Comparing version 0.1.0 to 0.1.1
57
index.js
#!/usr/bin/env node | ||
'use strict'; | ||
const args = require('yargs').argv; | ||
const pkg = require('./package.json'); | ||
const yargs = require('yargs') | ||
.alias('h', 'help') | ||
.alias('v', 'version') | ||
.alias('l', 'log') | ||
.alias('t', 'time') | ||
.alias('s', 'start') | ||
.alias('e', 'end') | ||
.alias('u', 'utc') | ||
.alias('f', 'format') | ||
.alias('T', 'show-time') | ||
.alias('N', 'log-name') | ||
.alias('L', 'limit') | ||
.string('log') | ||
.boolean('utc') | ||
.boolean('show-time') | ||
.boolean('log-name') | ||
.default('log-name', undefined) | ||
.number('limit') | ||
.string('time') | ||
.string('start') | ||
.string('end') | ||
.string('format') | ||
.usage('Query log records in Logentries.\nUsage: $0 -l log1 [-l log2 ...] -t time query') | ||
.describe({ | ||
'log' : 'Choose one or more logs to query', | ||
'time' : 'Duration to query', | ||
'start' : 'Start time to query from', | ||
'end' : 'End time to query to', | ||
'utc' : 'Use UTC as input and output format', | ||
'format' : 'Format each log record', | ||
'show-time' : 'Show received time for each log record', | ||
'log-name' : 'Show name of log for each log record', | ||
'limit' : 'Maximum number of records to display' | ||
}) | ||
.version(pkg.version) | ||
.help(); | ||
const args = yargs.argv; | ||
const chalk = require('chalk'); | ||
const path = require('path'); | ||
const os = require('os'); | ||
const pkg = require('./package.json'); | ||
const castArray = require('cast-array'); | ||
@@ -79,10 +116,5 @@ | ||
// we use that as default. | ||
let argsLog = []; | ||
if ('log' in args) { | ||
argsLog = castArray(args.log).map(alias => ''+alias); | ||
} else { | ||
if (logList.length === 1) { | ||
argsLog = [ logList[0] ]; | ||
} | ||
} | ||
let argsLog = args.log !== undefined ? | ||
castArray(args.log).map(alias => ''+alias) : | ||
[]; | ||
@@ -92,5 +124,6 @@ // Go through list of logs. If any of them are unknown, we display an error. | ||
if (argsLogNotFound.length > 0) { | ||
console.error('Unknown log alias%s: %s', | ||
console.error('Unknown log alias%s: %s\n', | ||
argsLogNotFound.length > 1 ? 'es' : '', | ||
argsLogNotFound.map(alias => alias || '(empty)').join(', ')); | ||
yargs.showHelp(); | ||
process.exit(1); | ||
@@ -101,3 +134,3 @@ } | ||
if (argsLog.length === 0) { | ||
console.log('\nLogs:\n\n%s\n', | ||
console.log('\nLogs:\n\n%s\n\nSpecify --help for available options.\n', | ||
Object.keys(logs) | ||
@@ -104,0 +137,0 @@ .map(alias => ' - ' + alias + ' ' + |
{ | ||
"name": "logentries-query-cli", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "CLI tool to query and stream logs from Logentries.", | ||
@@ -5,0 +5,0 @@ "bin": { |
17446
223