51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu'
|
|
import chalk = require('chalk');
|
|
import { confirmMessage, defaultMenuSettings } from '../../../globals';
|
|
const { AutoComplete } = require('enquirer');
|
|
const { spawn } = require('child_process');
|
|
|
|
module.exports = {
|
|
name: 'logs',
|
|
alias: ['l'],
|
|
description: 'Tail a log in cloudwatch (l)',
|
|
hidden: false,
|
|
run: async (toolbox: GluegunMenuToolbox) => {
|
|
|
|
const { system, strings } = toolbox
|
|
|
|
const groups = JSON.parse(strings.trim(await system.run(`aws logs describe-log-groups`)));
|
|
|
|
const options = groups.logGroups.map(item => {
|
|
return item.logGroupName;
|
|
});
|
|
|
|
const prompt = new AutoComplete({
|
|
name: 'logGroups',
|
|
message: 'Choose a logGroup',
|
|
limit: 30,
|
|
initial: options.length - 1,
|
|
choices: options
|
|
});
|
|
|
|
const logGroup = await prompt.run();
|
|
if (await confirmMessage(`Tail logs from ${chalk.yellow(logGroup)}?`)) {
|
|
const child = spawn('aws', ['logs', 'tail', `${logGroup}`, '--follow', '--format', 'short']);
|
|
child.stdout.setEncoding('utf8');
|
|
child.stdout.on('data', function(data) {
|
|
//Here is where the output goes
|
|
console.log(data);
|
|
});
|
|
child.stderr.on('data', (data) => {
|
|
console.error(`stderr: ${data}`);
|
|
});
|
|
child.on('close', (code) => {
|
|
console.log(`child process exited with code ${code}`);
|
|
});
|
|
}
|
|
|
|
if (toolbox.fromMenu()) {
|
|
await toolbox.menu.showMenu('aws', defaultMenuSettings);
|
|
}
|
|
}
|
|
}
|