From 5bd54c304904d780c213e304b9cbd5f8cdaec483 Mon Sep 17 00:00:00 2001 From: Eduardo Weiland Date: Tue, 9 Jul 2019 15:41:13 -0300 Subject: [PATCH 1/4] Allow passing an array as command to run and exec --- index.d.ts | 4 ++-- index.js | 8 ++++---- test/index.js | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/index.d.ts b/index.d.ts index c0a81a6..9d3163c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -18,11 +18,11 @@ export declare function restartOne(service: String, options: IDockerComposeOptio export declare function rm(options: IDockerComposeOptions): Promise; -export declare function exec(container: String, command: String, options: IDockerComposeOptions): Promise; +export declare function exec(container: String, command: String | String[], options: IDockerComposeOptions): Promise; export declare function logs(services: String[], options: IDockerComposeLogOptions): Promise; -export declare function run(service: String, command: String, options: IDockerComposeOptions): Promise; +export declare function run(service: String, command: String | String[], options: IDockerComposeOptions): Promise; export declare function buildAll(options: IDockerComposeBuildOptions): Promise; diff --git a/index.js b/index.js index 9ec8f22..596a13b 100644 --- a/index.js +++ b/index.js @@ -180,7 +180,7 @@ const rm = function (options) { /** * Execute command in a running container * @param {string} container container name - * @param {string} command command to execute + * @param {string|string[]} command command to execute * @param {object} options * @param {string} options.cwd * @param {boolean} [options.log] @@ -191,7 +191,7 @@ const rm = function (options) { * @return {object} std.out / std.err */ const exec = function (container, command, options) { - const args = command.split(/\s+/); + const args = Array.isArray(command) ? command : command.split(/\s+/); return execCompose('exec', [ '-T', container ].concat(args), options); }; @@ -199,7 +199,7 @@ const exec = function (container, command, options) { /** * Run command * @param {string} container container name - * @param {string} command command to execute + * @param {string|string[]} command command to execute * @param {object} options * @param {string} options.cwd * @param {boolean} [options.log] @@ -210,7 +210,7 @@ const exec = function (container, command, options) { * @return {object} std.out / std.err */ const run = function (container, command, options) { - const args = command.split(/\s+/); + const args = Array.isArray(command) ? command : command.split(/\s+/); return execCompose('run', [ '-T', container ].concat(args), options); }; diff --git a/test/index.js b/test/index.js index 346a24e..f68db30 100644 --- a/test/index.js +++ b/test/index.js @@ -191,6 +191,38 @@ test('ensure run and exec are working', async assert => { assert.end(); }); +test('ensure run and exec with command defined as array are working', async assert => { + const checkOSID = (out, id) => { + // parse /etc/os-release contents + const re = /([\w,_]+)=(.*)/g; + let match = null; + const os = {}; + + while ((match = re.exec(out)) !== null) { // eslint-disable-line no-cond-assign + os[match[1]] = match[2]; + } + + assert.equals(os.ID, id); + }; + + const opts = { cwd: path.join(__dirname), log: false }; + + await compose.upAll(opts); + + assert.true(await isContainerRunning('/compose_test_nginx')); + + let std = await compose.exec('db', ['/bin/sh', '-c', 'cat /etc/os-release'], opts); + + assert.false(std.err); + checkOSID(std.out, 'debian'); + + std = await compose.run('alpine', ['/bin/sh', '-c', 'cat /etc/os-release'], opts); + assert.false(std.err); + checkOSID(std.out, 'alpine'); + + assert.end(); +}); + test('build single service', async assert => { const opts = { cwd: path.join(__dirname), From 1aefb96986441463b56f3eb20881c66e3f79b4e3 Mon Sep 17 00:00:00 2001 From: Eduardo Weiland Date: Tue, 9 Jul 2019 15:46:16 -0300 Subject: [PATCH 2/4] Fix linting --- test/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/index.js b/test/index.js index f68db30..7f92518 100644 --- a/test/index.js +++ b/test/index.js @@ -211,12 +211,12 @@ test('ensure run and exec with command defined as array are working', async asse assert.true(await isContainerRunning('/compose_test_nginx')); - let std = await compose.exec('db', ['/bin/sh', '-c', 'cat /etc/os-release'], opts); + let std = await compose.exec('db', [ '/bin/sh', '-c', 'cat /etc/os-release' ], opts); assert.false(std.err); checkOSID(std.out, 'debian'); - std = await compose.run('alpine', ['/bin/sh', '-c', 'cat /etc/os-release'], opts); + std = await compose.run('alpine', [ '/bin/sh', '-c', 'cat /etc/os-release' ], opts); assert.false(std.err); checkOSID(std.out, 'alpine'); From 7eba565eb51f12eac43fd04aece03341e7a4faa8 Mon Sep 17 00:00:00 2001 From: Alexander Zeitler Date: Wed, 10 Jul 2019 12:36:49 +0200 Subject: [PATCH 3/4] add download badge --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 9d085f0..45670b9 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ - + # Manage Docker-Compose via Node.js From 762b9d11207127df14ec3cfafeed1b0c2f6d1d3c Mon Sep 17 00:00:00 2001 From: Alexander Zeitler Date: Wed, 10 Jul 2019 12:37:27 +0200 Subject: [PATCH 4/4] fix badge spacing --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 45670b9..15bffbe 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ - + # Manage Docker-Compose via Node.js