Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
fix: remove optionType
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 5, 2018
1 parent 25f41b8 commit 15bb0d0
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export type IBooleanFlag<T> = IFlagBase<T, boolean> & {

export type IOptionFlag<T> = IFlagBase<T, string> & {
type: 'option'
optionType: string
helpValue?: string
default?: T | ((context: DefaultContext<T>) => T | undefined)
multiple: boolean
Expand Down Expand Up @@ -69,18 +68,17 @@ export function boolean<T = boolean>(options: Partial<IBooleanFlag<T>> = {}): IB
}

export const integer = build({
optionType: 'integer',
parse: input => {
if (!/^[0-9]+$/.test(input)) throw new Error(`Expected an integer but received: ${input}`)
return parseInt(input, 10)
},
})

export function option<T>(options: {parse: IOptionFlag<T>['parse']} & Partial<IOptionFlag<T>>) {
return build<T>({optionType: 'custom', ...options})()
return build<T>(options)()
}

const stringFlag = build({optionType: 'string'})
const stringFlag = build({})
export {stringFlag as string}

export const defaultFlags = {
Expand Down

0 comments on commit 15bb0d0

Please sign in to comment.