@drizzle-team/brocli
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -25,3 +25,3 @@ /** | ||
}; | ||
declare class OptionBuilderBase<TBuilderConfig extends BuilderConfig = BuilderConfig, TOutput extends OutputType = string, TOmit extends string = '', TDefault extends OutputType = undefined> { | ||
declare class OptionBuilderBase<TBuilderConfig extends BuilderConfig = BuilderConfig, TOutput extends OutputType = string, TOmit extends string = '', TEnums extends string | undefined = undefined> { | ||
_: { | ||
@@ -49,4 +49,4 @@ config: TBuilderConfig; | ||
required(): Omit<OptionBuilderBase<BuilderConfig, Exclude<TOutput, undefined>, TOmit | 'required' | 'default'>, TOmit | 'required' | 'default'>; | ||
default<TDefVal extends TOutput extends string ? string : Exclude<TOutput, undefined>>(value: TDefVal): Omit<OptionBuilderBase<BuilderConfig, Exclude<TOutput | TDefVal, undefined>, TOmit | 'required' | 'default'>, TOmit | 'required' | 'default'>; | ||
enum<TValues extends [string, ...string[]]>(...values: TValues): Omit<OptionBuilderBase<BuilderConfig, Exclude<TOutput | TDefault, string> | TValues[number], TOmit | 'enum'>, TOmit | 'enum'>; | ||
default<TDefVal extends TEnums extends undefined ? Exclude<TOutput, undefined> : TEnums>(value: TDefVal): Omit<OptionBuilderBase<BuilderConfig, Exclude<TOutput, undefined>, TOmit | 'enum' | 'required' | 'default', TEnums>, TOmit | 'enum' | 'required' | 'default'>; | ||
enum<TValues extends [string, ...string[]]>(...values: TValues): Omit<OptionBuilderBase<BuilderConfig, TValues[number], TOmit | 'enum', TValues[number]>, TOmit | 'enum'>; | ||
min(value: number): Omit<OptionBuilderBase<BuilderConfig, TOutput, TOmit | 'min'>, TOmit | 'min'>; | ||
@@ -53,0 +53,0 @@ max(value: number): Omit<OptionBuilderBase<BuilderConfig, TOutput, TOmit | 'max'>, TOmit | 'max'>; |
12
index.js
@@ -61,2 +61,8 @@ // src/brocli-error.ts | ||
default(value) { | ||
const enums = this.config().enumVals; | ||
if (enums && !enums.find((v) => value === v)) { | ||
throw new Error( | ||
`Option enums [ ${enums.join(", ")} ] are incompatible with default value ${value}` | ||
); | ||
} | ||
this.config().default = value; | ||
@@ -66,2 +72,8 @@ return this; | ||
enum(...values) { | ||
const defaultVal = this.config().default; | ||
if (defaultVal !== void 0 && !values.find((v) => defaultVal === v)) { | ||
throw new Error( | ||
`Option enums [ ${values.join(", ")} ] are incompatible with default value ${defaultVal}` | ||
); | ||
} | ||
this.config().enumVals = values; | ||
@@ -68,0 +80,0 @@ return this; |
@@ -5,3 +5,3 @@ { | ||
"author": "Drizzle Team", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "Typed CLI command runner", | ||
@@ -8,0 +8,0 @@ "license": "Apache-2.0", |
@@ -71,3 +71,2 @@ # BroCLI | ||
- `values` - allowed enum values | ||
:warning: - does not test default value, will add it to the output type instead | ||
@@ -74,0 +73,0 @@ - `.int()` - ensures that number is an integer |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
145074
1163
213