Skip to content

Commit

Permalink
Merge pull request #30 from crazyfactory/29-improve-args
Browse files Browse the repository at this point in the history
Improve args
  • Loading branch information
wmathes authored Dec 13, 2017
2 parents e1c88e5 + bb5f276 commit 2059fe2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ Configuration of DOPR can be done either via `package.json` under the `dopr` key
"host-cmd": {
"service": "@host",
"command": "docker-compose version"
},
"composer": {
"args": "install --prefer-dist --no-scripts",
"command": "%action% %args%"
}
}
}
Expand All @@ -100,6 +104,7 @@ Configuration of DOPR can be done either via `package.json` under the `dopr` key
- The `"actions".[$key]."command"` can be either array or string.
- The command can be reused or recalled by prefixing it with `@` (see sample above).
- The command that should run in host context will need `"service"` value of `"@host"` (see sample above).
- The action can optionally provide default arguments in `"args"` used to interpolate `%args%` when no other argument is provided (see `"composer"."args"` above).

## Usage

Expand Down
20 changes: 12 additions & 8 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ if (!packageConfig && !doprConfig) {
}

// Backward compat.
if (typeof packageConfig.file === 'string') {
if (packageConfig && typeof packageConfig.file === 'string') {
packageConfig.file = [packageConfig.file];
}
if (doprConfig && typeof doprConfig.file === 'string') {
Expand Down Expand Up @@ -153,6 +153,11 @@ const exitHandler = code => {
}
};

// Default args given!
if (args.length === 0 && cliAction.args !== undefined) {
args.push(cliAction.args);
}

// Run commands synchronously one after another!
cliAction.command.forEach(command => {
if (program.verbose) {
Expand All @@ -172,17 +177,16 @@ cliAction.command.forEach(command => {
return exitHandler(spawnSync('dopr ', refArgs, cliOptions).status);
}

// Parse command
const cliCommand = command
.replace(/%action%/g, action || '')
.replace(/%args%/g, args.join(' '));

// Command is expected to run in host context!
if (cliAction.service === '@host') {
return execSync(command, cliOptions);
return execSync(cliCommand, cliOptions);
}

// Parse command
const cliCommand = command
.replace('%action%', action || '')
.replace('%args%', args.join(' '))
.split(' ');

// Args
const user = cliAction.user ? ['--user', cliAction.user] : [];

Expand Down

0 comments on commit 2059fe2

Please sign in to comment.