Skip to content

Commit

Permalink
Add output mode option to logs command (#1131)
Browse files Browse the repository at this point in the history
* Fix readme typo

* Add raw output mode
  • Loading branch information
cpetzold authored and leo committed Feb 26, 2018
1 parent f5fefa8 commit a6fe795
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -244,7 +244,7 @@ All feedback and suggestions are welcome!
- 📣 Stay up to date on new features and announcments on [@zeithq](https://twitter.com/zeithq).
- 🔐 Subscribe to our [security](http://zeit.us12.list-manage1.com/subscribe?u=3c9e9e13d7e6dae8faf375bed&id=110e586914) mailing list to stay up-to-date on urgent security disclosures.

Please note: we adhere to the [contributor coventant](http://contributor-covenant.org/) for
Please note: we adhere to the [contributor covenant](http://contributor-covenant.org/) for
all interactions in our community.

#### Contributions
Expand Down
25 changes: 22 additions & 3 deletions src/providers/sh/commands/logs.js
Expand Up @@ -47,6 +47,9 @@ const help = () => {
'UNTIL'
)} Only return logs before date (ISO 8601), ignored for ${'`-f`'}
-T, --team Set a custom team scope
-o ${chalk.bold.underline('MODE')}, --output=${chalk.bold.underline(
'MODE'
)} Specify the output format (${Object.keys(logPrinters).join('|')}) [short]
${chalk.dim('Examples:')}
Expand All @@ -67,21 +70,23 @@ let limit
let query
let follow
let types
let outputMode

let since
let until
let instanceId

const main = async ctx => {
argv = mri(ctx.argv.slice(2), {
string: ['query', 'since', 'until'],
string: ['query', 'since', 'until', 'output'],
boolean: ['help', 'all', 'debug', 'follow'],
alias: {
help: 'h',
all: 'a',
debug: 'd',
query: 'q',
follow: 'f'
follow: 'f',
output: 'o'
}
})

Expand Down Expand Up @@ -124,6 +129,7 @@ const main = async ctx => {
query = argv.query || ''
follow = argv.f
types = argv.all ? [] : ['command', 'stdout', 'stderr', 'exit']
outputMode = argv.output in logPrinters ? argv.output : 'short'

const {authConfig: { credentials }, config: { sh }} = ctx
const {token} = credentials.find(item => item.provider === 'sh')
Expand Down Expand Up @@ -238,7 +244,7 @@ function printLogs({ token, sh: { currentTeam } }) {
})
}

function printLog(log) {
function printLogShort(log) {
let data
const obj = log.object
if (log.type === 'request') {
Expand Down Expand Up @@ -267,6 +273,19 @@ function printLog(log) {
})
}

function printLogRaw(log) {
console.log(log.object ? JSON.stringify(log.object) : log.text)
}

const logPrinters = {
short: printLogShort,
raw: printLogRaw
}

function printLog(log) {
logPrinters[outputMode](log)
}

async function fetchLogs({ token, currentTeam, since, until } = {}) {
const now = new Now({ apiUrl, token, debug, currentTeam })

Expand Down

0 comments on commit a6fe795

Please sign in to comment.