Skip to content

Commit

Permalink
Merge branch 'main' into mdonnalley/inferred-flags
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Aug 18, 2022
2 parents bdbc890 + 56698d6 commit ec3f319
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [1.14.2](https://github.com/oclif/core/compare/v1.14.1...v1.14.2) (2022-08-18)


### Bug Fixes

* add overloads to enum flag ([799455b](https://github.com/oclif/core/commit/799455bbb526b221c806bf8feff6b625dcf50a56))

### [1.14.1](https://github.com/oclif/core/compare/v1.14.0...v1.14.1) (2022-08-16)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@oclif/core",
"description": "base library for oclif CLIs",
"version": "1.14.1",
"version": "1.14.2",
"author": "Salesforce",
"bugs": "https://github.com/oclif/core/issues",
"dependencies": {
Expand Down
10 changes: 7 additions & 3 deletions src/flags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {OptionFlag, Definition, BooleanFlag, EnumFlagOptions} from './interfaces'
import {OptionFlag, Definition, BooleanFlag, EnumFlagOptions, Default} from './interfaces'
import * as Parser from './parser'
import Command from './command'

Expand All @@ -12,15 +12,19 @@ export function option<T>(options: {parse: OptionFlag<T>['parse']} & Partial<Opt
return build<T>(options)()
}

const _enum = <T = string>(opts: EnumFlagOptions<T>): OptionFlag<T> => {
export function _enum<T = string>(opts: EnumFlagOptions<T> & {multiple: true} & ({required: true} | { default: Default<T> })): OptionFlag<T[]>
export function _enum<T = string>(opts: EnumFlagOptions<T> & {multiple: true}): OptionFlag<T[] | undefined>
export function _enum<T = string>(opts: EnumFlagOptions<T> & ({required: true} | { default: Default<T> })): OptionFlag<T>
export function _enum<T = string>(opts: EnumFlagOptions<T>): OptionFlag<T | undefined>
export function _enum<T = string>(opts: EnumFlagOptions<T>): OptionFlag<T> | OptionFlag<T[]> | OptionFlag<T | undefined> | OptionFlag<T[] | undefined> {
return build<T>({
async parse(input) {
if (!opts.options.includes(input)) throw new Error(`Expected --${this.name}=${input} to be one of: ${opts.options.join(', ')}`)
return input as unknown as T
},
helpValue: `(${opts.options.join('|')})`,
...opts,
})() as OptionFlag<T>
})()
}

export {_enum as enum}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function directory(opts: { exists?: boolean } & Partial<OptionFlag<string

export function file(opts: Partial<OptionFlag<string>> & { exists?: boolean } & {multiple: true} & ({required: true} | { default: Default<string> })): OptionFlag<string[]>
export function file(opts: Partial<OptionFlag<string>> & { exists?: boolean } & {multiple: true}): OptionFlag<string[] | undefined>
export function file(opts: { exists?: boolean } & Partial<OptionFlag<string>> & ({required: true} | { default: string })): OptionFlag<string>
export function file(opts: { exists?: boolean } & Partial<OptionFlag<string>> & ({required: true} | { default: Default<string> })): OptionFlag<string>
export function file(opts?: { exists?: boolean } & Partial<OptionFlag<string>>): OptionFlag<string | undefined>
export function file(opts: { exists?: boolean } & Partial<OptionFlag<string>> = {}): OptionFlag<string> | OptionFlag<string[]> | OptionFlag<string | undefined> | OptionFlag<string[] | undefined> {
return build<string>({
Expand Down

0 comments on commit ec3f319

Please sign in to comment.