diff --git a/index.d.ts b/index.d.ts index 55b6882..b808a89 100644 --- a/index.d.ts +++ b/index.d.ts @@ -12,6 +12,7 @@ declare module "docker-compose" { buildAll(options: IDockerComposeOptions): Promise; buildMany(services:String[], options: IDockerComposeOptions): Promise; buildOne(service:String, options: IDockerComposeOptions): Promise; + ps(options: IDockerComposeOptions): Promise; } interface IDockerComposeOptions { diff --git a/index.js b/index.js index 1bf0c23..09399fb 100644 --- a/index.js +++ b/index.js @@ -221,4 +221,16 @@ const buildOne = function (service, options) { return execCompose('build', [ service ], options); }; -module.exports = { upAll, upMany, upOne, kill, down, stop, rm, exec, run, buildAll, buildMany, buildOne }; +/** + * Ps command + * @param {object} options + * @param {string} options.cwd + * @param {boolean} [options.log] + * @param {?(string|string[])} [options.config] + * @param {?object} [options.env] + */ +const ps = function (options) { + return execCompose('ps', [], options); +}; + +module.exports = { upAll, upMany, upOne, kill, down, stop, rm, exec, run, buildAll, buildMany, buildOne, ps }; diff --git a/test/index.js b/test/index.js index 435beaa..963b001 100644 --- a/test/index.js +++ b/test/index.js @@ -220,3 +220,28 @@ test('teardown', async assert => { assert.end(); }); + +test('ps shows status data for started containers', async assert => { + await compose.upAll({ cwd: path.join(__dirname), log: true }); + + const std = await compose.ps({ cwd: path.join(__dirname), log: true }); + + assert.false(std.err); + assert.true(std.out.includes('compose_test_alpine')); + assert.true(std.out.includes('compose_test_mongodb')); + + assert.end(); +}); + +test('ps does not show status data for stopped containers', async assert => { + await compose.down({ cwd: path.join(__dirname), log: true }); + await compose.upOne('alpine', { cwd: path.join(__dirname), log: true }); + + const std = await compose.ps({ cwd: path.join(__dirname), log: true }); + + assert.false(std.err); + assert.true(std.out.includes('compose_test_alpine')); + assert.false(std.out.includes('compose_test_mongodb')); + + assert.end(); +});