Datasets:

Modalities:
Text
Formats:
json
Languages:
code
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
Asankhaya Sharma
initial dataset
eb67da4
raw
history blame
3.43 kB
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);
}
);
};