Skip to content

Commit

Permalink
add description to the exec command
Browse files Browse the repository at this point in the history
  • Loading branch information
ejnshtein committed Feb 8, 2022
1 parent 53e3427 commit 3216492
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions build-packages/magento-scripts/lib/commands/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,46 @@ const executeInContainer = require('../tasks/execute');
* @param {import('yargs')} yargs
*/
module.exports = (yargs) => {
yargs.command('exec <container name> [commands...]', 'Execute command in docker container', () => {}, async (argv) => {
const containers = (await docker).getContainers();
const services = Object.keys(containers);
yargs.command(
'exec <container name> [commands...]',
'Execute command in docker container',
(yargs) => {
yargs.usage(`Usage: npm run exec <container name> [commands...]
if (services.includes(argv.containername) || services.some((service) => service.includes(argv.containername))) {
const container = containers[argv.containername]
? containers[argv.containername]
: Object.entries(containers).find(([key]) => key.includes(argv.containername))[1];
Available containers:
- mysql
- nginx
- redis
- elasticsearch`);
},
async (argv) => {
const containers = (await docker).getContainers();
const services = Object.keys(containers);

if (argv.commands.length === 0) {
if (services.includes(argv.containername) || services.some((service) => service.includes(argv.containername))) {
const container = containers[argv.containername]
? containers[argv.containername]
: Object.entries(containers).find(([key]) => key.includes(argv.containername))[1];

if (argv.commands.length === 0) {
// if we have default connect command then use it
if (container.connectCommand) {
if (container.connectCommand) {
// eslint-disable-next-line no-param-reassign
argv.commands = container.connectCommand;
} else {
argv.commands = container.connectCommand;
} else {
// otherwise fall back to bash (if it exists inside container)
argv.commands.push('bash');
argv.commands.push('bash');
}
}
await executeInContainer({
containerName: container.name,
commands: argv.commands
});

return;
}
await executeInContainer({
containerName: container.name,
commands: argv.commands
});

return;
logger.error(`No container found "${argv.containername}"`);
}

logger.error(`No container found "${argv.containername}"`);
});
);
};

0 comments on commit 3216492

Please sign in to comment.