mirror of
https://github.com/danbulant/docker-compose
synced 2026-06-24 17:31:53 +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[]
|
services: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type DockerComposeConfigVolumesResult = {
|
||||||
|
volumes: string[]
|
||||||
|
}
|
||||||
|
|
||||||
export interface IDockerComposeLogOptions extends IDockerComposeOptions {
|
export interface IDockerComposeLogOptions extends IDockerComposeOptions {
|
||||||
follow?: boolean
|
follow?: boolean
|
||||||
}
|
}
|
||||||
|
|
@ -335,10 +339,20 @@ export const configServices = async function (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const configVolumes = function (
|
export const configVolumes = async function (
|
||||||
options?: IDockerComposeOptions
|
options?: IDockerComposeOptions
|
||||||
): Promise<IDockerComposeResult> {
|
): Promise<TypedDockerComposeResult<DockerComposeConfigVolumesResult>> {
|
||||||
return execCompose('config', ['--volumes'], options)
|
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 (
|
export const ps = function (
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ services:
|
||||||
image: nginx:1.19.9-alpine
|
image: nginx:1.19.9-alpine
|
||||||
command: 'nginx -g "daemon off;"'
|
command: 'nginx -g "daemon off;"'
|
||||||
volumes:
|
volumes:
|
||||||
- ./volume:/mountedvolume
|
# - ./volume:/mountedvolume
|
||||||
- db-data:/mountedsecondvolume
|
- db-data:/mountedsecondvolume
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
|
|
|
||||||
|
|
@ -540,8 +540,9 @@ test('config show data for docker-compose files (volumes)', async (): Promise<vo
|
||||||
config: 'docker-compose-42.yml'
|
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.err).toBeFalsy()
|
||||||
expect(std.out.includes('db-data')).toBeTruthy()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('ps shows status data for started containers', async (): Promise<void> => {
|
test('ps shows status data for started containers', async (): Promise<void> => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue