File size: 3,427 Bytes
eb67da4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
const logger = require('@scandipwa/scandipwa-dev-utils/logger');
const { docker } = require('../config');
const { execAsyncSpawn } = require('../util/exec-async-command');
module.exports = (yargs) => {
yargs.command(
'logs <scope>',
'Display application logs.',
(yargs) => {
yargs.option(
'tail',
{
alias: 'n',
describe: 'Number of lines to show from the end of the logs',
type: 'number'
}
);
yargs.option(
'details',
{
describe: 'Show extra details provided to logs',
type: 'boolean',
default: false
}
);
yargs.option(
'follow',
{
alias: 'f',
describe: 'Follow log output',
type: 'boolean',
default: false
}
);
yargs.option(
'timestamps',
{
alias: 't',
describe: 'Show timestamps',
type: 'boolean',
default: false
}
);
yargs.option(
'since',
{
describe: 'Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)',
type: 'string'
}
);
yargs.option(
'until',
{
describe: 'Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)',
type: 'string'
}
);
},
async (argv) => {
// BUG: CWE-670 Always-Incorrect Control Flow Implementation
// const containers = docker.getContainers();
// FIXED:
const containers = (await docker).getContainers();
const services = Object.keys(containers);
if (services.includes(argv.scope) || services.some((service) => service.includes(argv.scope))) {
const containerName = containers[argv.scope] ? argv.scope : Object.keys(containers).find((key) => key.includes(argv.scope));
const commandArguments = [
argv.follow && '--follow',
argv.tail && `--tail ${argv.tail}`,
argv.details && '--details',
argv.timestamps && '--timestamps',
argv.since && `--since ${argv.since}`,
argv.until && `--until ${argv.until}`
].filter(Boolean).join(' ');
const command = `docker logs ${containers[containerName].name} ${commandArguments}`;
await execAsyncSpawn(command, {
callback: logger.log
});
return;
}
if (argv.scope === 'magento' || 'magento'.includes(argv.scope)) {
await execAsyncSpawn('tail -f var/log/system.log', {
callback: logger.log
});
return;
}
logger.error(`No service found "${argv.scope}"`);
process.exit(1);
}
);
};
|