Skip to content

Commit ab52409

Browse files
committed
feat: support multiple command(s) as array, enable reusing command with @ prefix
1 parent a5a4ccf commit ab52409

1 file changed

Lines changed: 40 additions & 25 deletions

File tree

src/cli.js

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

33
const path = require('path');
4-
const {spawn} = require('child_process');
4+
const {spawnSync} = require('child_process');
55
const program = require('commander');
66
const chalk = require('chalk');
77
const deepAssign = require('deep-assign');
@@ -152,29 +152,44 @@ const exitHandler = code => {
152152
}
153153
};
154154

155-
// Parse command
156-
const cliCommand = cliAction.command
157-
.replace('%action%', action || '')
158-
.replace('%args%', args.join(' '))
159-
.split(' ');
160-
161-
// Args
162-
const user = cliAction.user ? ['--user', cliAction.user] : [];
163-
164-
const cliArgs = dockerComposeFiles
165-
.concat(cliAction.exec ? ['exec', ...user, cliAction.service] : [])
166-
.concat(cliAction.detached ? ['-d'] : [])
167-
.concat(cliAction.privileged ? ['--privileged'] : [])
168-
.concat(cliAction.index ? ['--index', cliAction.index] : [])
169-
.concat(cliCommand);
170-
171-
if (program.verbose) {
172-
console.log(chalk.gray('ENV: ' + env));
173-
console.log(chalk.gray('CWD: ' + basePath));
174-
console.log(chalk.gray('CMD: docker-compose ' + cliArgs.join(' ')));
175-
}
155+
cliAction.command.forEach(command => {
156+
if (program.verbose) {
157+
console.log(chalk.gray('ENV: ' + env));
158+
console.log(chalk.gray('CWD: ' + basePath));
159+
}
160+
161+
// Is it a reference to another action?
162+
if (command[0] === '@') {
163+
const refArgs = dockerProjectArgs.slice(2).concat(command.substr(1));
164+
165+
if (program.verbose) {
166+
console.log(chalk.gray('CMD: dopr ' + refArgs.join(' ')));
167+
}
168+
169+
// Fire!
170+
return exitHandler(spawnSync('dopr ', refArgs, cliOptions).status);
171+
}
176172

177-
// Fire!
178-
const childProcess = spawn('docker-compose', cliArgs, cliOptions);
173+
// Parse command
174+
const cliCommand = command
175+
.replace('%action%', action || '')
176+
.replace('%args%', args.join(' '))
177+
.split(' ');
179178

180-
childProcess.on('close', exitHandler);
179+
// Args
180+
const user = cliAction.user ? ['--user', cliAction.user] : [];
181+
182+
const cliArgs = dockerComposeFiles
183+
.concat(cliAction.exec ? ['exec', ...user, cliAction.service] : [])
184+
.concat(cliAction.detached ? ['-d'] : [])
185+
.concat(cliAction.privileged ? ['--privileged'] : [])
186+
.concat(cliAction.index ? ['--index', cliAction.index] : [])
187+
.concat(cliCommand);
188+
189+
if (program.verbose) {
190+
console.log(chalk.gray('CMD: docker-compose ' + cliArgs.join(' ')));
191+
}
192+
193+
// Fire!
194+
exitHandler(spawnSync('docker-compose', cliArgs, cliOptions).status);
195+
});

0 commit comments

Comments
 (0)