Merge pull request #34 from falinsky/feature/add-ps-command

Provide ability to run docker-compose ps command
This commit is contained in:
Alexander Zeitler 2019-01-15 16:46:10 +01:00 committed by GitHub
commit 40540703c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 1 deletions

1
index.d.ts vendored
View file

@ -12,6 +12,7 @@ declare module "docker-compose" {
buildAll(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
buildMany(services:String[], options: IDockerComposeOptions): Promise<IDockerComposeResult>;
buildOne(service:String, options: IDockerComposeOptions): Promise<IDockerComposeResult>;
ps(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
}
interface IDockerComposeOptions {

View file

@ -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 };

View file

@ -24,6 +24,7 @@ npm install --save-dev docker-compose
* `buildAll(options)` - Build or rebuild services
* `buildMany(services, options)` - Build or rebuild services
* `buildOne(service, options)` - Build or rebuild service
* `ps(options)` - Lists containers information
All commands return a `Promise({object})` with an stdout and stderr strings
```javascript

View file

@ -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();
});