mirror of
https://github.com/danbulant/docker-compose
synced 2026-06-15 20:51:27 +00:00
feat: make result for config --volumes command type safe
This commit is contained in:
parent
6f105ca160
commit
51b20b43d6
3 changed files with 20 additions and 5 deletions
20
src/index.ts
20
src/index.ts
|
|
@ -31,6 +31,10 @@ export type DockerComposeConfigServicesResult = {
|
|||
services: string[]
|
||||
}
|
||||
|
||||
export type DockerComposeConfigVolumesResult = {
|
||||
volumes: string[]
|
||||
}
|
||||
|
||||
export interface IDockerComposeLogOptions extends IDockerComposeOptions {
|
||||
follow?: boolean
|
||||
}
|
||||
|
|
@ -335,10 +339,20 @@ export const configServices = async function (
|
|||
}
|
||||
}
|
||||
|
||||
export const configVolumes = function (
|
||||
export const configVolumes = async function (
|
||||
options?: IDockerComposeOptions
|
||||
): Promise<IDockerComposeResult> {
|
||||
return execCompose('config', ['--volumes'], options)
|
||||
): Promise<TypedDockerComposeResult<DockerComposeConfigVolumesResult>> {
|
||||
try {
|
||||
const result = await execCompose('config', ['--volumes'], options)
|
||||
const nonEmpty = (v: string) => v !== ''
|
||||
const volumes = result.out.split('\n').filter(nonEmpty)
|
||||
return {
|
||||
...result,
|
||||
data: { volumes }
|
||||
}
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
export const ps = function (
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ services:
|
|||
image: nginx:1.19.9-alpine
|
||||
command: 'nginx -g "daemon off;"'
|
||||
volumes:
|
||||
- ./volume:/mountedvolume
|
||||
# - ./volume:/mountedvolume
|
||||
- db-data:/mountedsecondvolume
|
||||
|
||||
volumes:
|
||||
|
|
|
|||
|
|
@ -540,8 +540,9 @@ test('config show data for docker-compose files (volumes)', async (): Promise<vo
|
|||
config: 'docker-compose-42.yml'
|
||||
})
|
||||
|
||||
expect(std.data.volumes.length).toBe(1)
|
||||
expect(std.data.volumes[0]).toBe('db-data')
|
||||
expect(std.err).toBeFalsy()
|
||||
expect(std.out.includes('db-data')).toBeTruthy()
|
||||
})
|
||||
|
||||
test('ps shows status data for started containers', async (): Promise<void> => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue