From 52ce6b135853b6f04a3b61498a2a16ecb3a8fb24 Mon Sep 17 00:00:00 2001 From: Jitendra Adhikari Date: Tue, 12 Dec 2017 15:25:55 +0700 Subject: [PATCH 1/3] fix(args): always parse command args and interpolate all occurances --- src/cli.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/cli.js b/src/cli.js index 39a13fe..e13b1a3 100644 --- a/src/cli.js +++ b/src/cli.js @@ -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') { @@ -172,17 +172,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] : []; From cb5320c2b1d01c14b2b9daf9daaaa9a26caacbbd Mon Sep 17 00:00:00 2001 From: Jitendra Adhikari Date: Tue, 12 Dec 2017 15:30:44 +0700 Subject: [PATCH 2/3] feat(args.default): add a default argument for %args% placeholder --- src/cli.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cli.js b/src/cli.js index e13b1a3..c3b89d5 100644 --- a/src/cli.js +++ b/src/cli.js @@ -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) { From bb5f27633d413f06744b35b05de2311147c3684f Mon Sep 17 00:00:00 2001 From: Jitendra Adhikari Date: Tue, 12 Dec 2017 15:31:03 +0700 Subject: [PATCH 3/3] docs(args): add default args documentaion --- readme.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/readme.md b/readme.md index 97047a5..412ab1a 100644 --- a/readme.md +++ b/readme.md @@ -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%" } } } @@ -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