Skip to content

Commit

Permalink
feat: make result for version command type safe
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexZeitler committed Apr 14, 2021
1 parent 90421b7 commit a7da038
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
19 changes: 16 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export type DockerComposePortResult = {
port: number
}

export type DockerComposeVersionResult = {
version: string
}

export interface IDockerComposeLogOptions extends IDockerComposeOptions {
follow?: boolean
}
Expand Down Expand Up @@ -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)
}
}
4 changes: 2 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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+)$/)
})

0 comments on commit a7da038

Please sign in to comment.