mirror of
https://github.com/danbulant/docker-compose
synced 2026-05-19 20:38:35 +00:00
feat: make result for version command type safe
This commit is contained in:
parent
90421b7eb2
commit
a7da0380a8
2 changed files with 18 additions and 5 deletions
19
src/index.ts
19
src/index.ts
|
|
@ -14,6 +14,10 @@ export type DockerComposePortResult = {
|
|||
port: number
|
||||
}
|
||||
|
||||
export type DockerComposeVersionResult = {
|
||||
version: string
|
||||
}
|
||||
|
||||
export interface IDockerComposeLogOptions extends IDockerComposeOptions {
|
||||
follow?: boolean
|
||||
}
|
||||
|
|
@ -377,8 +381,17 @@ export const port = async function (
|
|||
}
|
||||
}
|
||||
|
||||
export const version = function (
|
||||
export const version = async function (
|
||||
options?: IDockerComposeOptions
|
||||
): Promise<IDockerComposeResult> {
|
||||
return execCompose('version', ['--short'], options)
|
||||
): Promise<TypedDockerComposeResult<DockerComposeVersionResult>> {
|
||||
try {
|
||||
const result = await execCompose('version', ['--short'], options)
|
||||
const version = result.out.replace('\n', '')
|
||||
return {
|
||||
...result,
|
||||
data: { version }
|
||||
}
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -641,7 +641,7 @@ test('removes container', async (): Promise<void> => {
|
|||
})
|
||||
|
||||
test('returns version information', async (): Promise<void> => {
|
||||
const version = await compose.version()
|
||||
const version = await (await compose.version()).data.version
|
||||
|
||||
expect(version.out).toBeTruthy()
|
||||
expect(version).toMatch(/^(\d+\.)?(\d+\.)?(\*|\d+)$/)
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue