-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New manifest and action level logs with new strip and tail options #303
Changes from all commits
dea95ff
3cb004e
03cc7c6
2ef9f3c
a25e1b1
48d31ec
a08f72d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,11 +13,17 @@ governing permissions and limitations under the License. | |
const { flags } = require('@oclif/command') | ||
// const { cli } = require('cli-ux') | ||
const BaseCommand = require('../../BaseCommand') | ||
const { wrapError, getLogs } = require('../../lib/app-helper') | ||
const { wrapError } = require('../../lib/app-helper') | ||
const rtLib = require('@adobe/aio-lib-runtime') | ||
const fs = require('fs-extra') | ||
|
||
class Logs extends BaseCommand { | ||
async run () { | ||
const { flags } = this.parse(Logs) | ||
const config = this.getAppConfig() | ||
if (!fs.existsSync('manifest.yml')) { | ||
this.error(wrapError(new Error('no manifest.yml'))) | ||
} | ||
|
||
if (flags.limit < 1) { | ||
this.log('--limit should be > 0, using --limit=1') | ||
|
@@ -27,10 +33,25 @@ class Logs extends BaseCommand { | |
flags.limit = 50 | ||
} | ||
|
||
try { | ||
const config = this.getAppConfig() | ||
let filterActions = [] | ||
if (flags.action) { | ||
let actionName = flags.action | ||
if (!actionName.includes('/')) { | ||
actionName = config.ow.package + '/' + actionName | ||
} | ||
filterActions = [actionName] | ||
} else { | ||
Object.entries(config.manifest.full.packages).forEach((packageTuple) => { | ||
packageTuple[0] = packageTuple[0].replace(/__APP_PACKAGE__/g, config.ow.package) | ||
|
||
Object.keys(packageTuple[1].actions).forEach((actionName) => { | ||
filterActions.push(packageTuple[0] + '/' + actionName) | ||
}) | ||
}) | ||
} | ||
|
||
await getLogs(config, flags.limit, this.log) | ||
try { | ||
await rtLib.printActionLogs(config, this.log, flags.limit, filterActions, flags.strip, flags.poll || flags.tail || flags.watch) | ||
} catch (error) { | ||
this.error(wrapError(error)) | ||
} | ||
|
@@ -46,11 +67,34 @@ Logs.flags = { | |
description: 'Limit number of activations to fetch logs from ( 1-50 )', | ||
default: 1, | ||
char: 'l' | ||
}), | ||
action: flags.string({ | ||
description: 'Fetch logs for a specific action', | ||
char: 'a' | ||
}), | ||
strip: flags.boolean({ | ||
char: 'r', | ||
description: 'strip timestamp information and output first line only', | ||
default: false | ||
}), | ||
tail: flags.boolean({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is tail our final choice? should we alias it with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thx @purplecabbage . Removed action default and added aliases. |
||
description: 'Fetch logs continuously', | ||
char: 't', | ||
default: false, | ||
exclusive: ['watch', 'poll'] | ||
}), | ||
watch: flags.boolean({ | ||
description: 'Fetch logs continuously', | ||
default: false, | ||
char: 'w', | ||
exclusive: ['tail', 'poll'] | ||
}), | ||
poll: flags.boolean({ | ||
description: 'Fetch logs continuously', | ||
default: false, | ||
char: 'o', | ||
exclusive: ['watch', 'tail'] | ||
}) | ||
} | ||
|
||
// Logs.args = [ | ||
// ...BaseCommand.args | ||
// ] | ||
|
||
module.exports = Logs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a little gnarly, not sure it could be any better though