-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add InferredFlags type * chore: add test for flag types * chore: more type tests * chore: clean up * feat: add custom flag builder * chore: fix tests * fix: custom flag builder Co-authored-by: Shane McLaughlin <m.shane.mclaughlin@gmail.com>
- Loading branch information
1 parent
56698d6
commit ee5ce65
Showing
11 changed files
with
533 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {FlagInput} from './parser' | ||
|
||
/** | ||
* Infer the flags that are returned by Command.parse. This is useful for when you want to assign the flags as a class property. | ||
* | ||
* @example | ||
* export type StatusFlags = Interfaces.InferredFlags<typeof Status.flags & typeof Status.globalFlags> | ||
* | ||
* export abstract class BaseCommand extends Command { | ||
* static enableJsonFlag = true | ||
* | ||
* static globalFlags = { | ||
* config: Flags.string({ | ||
* description: 'specify config file', | ||
* }), | ||
* } | ||
* } | ||
* | ||
* export default class Status extends BaseCommand { | ||
* static flags = { | ||
* force: Flags.boolean({char: 'f', description: 'a flag'}), | ||
* } | ||
* | ||
* public flags!: StatusFlags | ||
* | ||
* public async run(): Promise<StatusFlags> { | ||
* const result = await this.parse(Status) | ||
* this.flags = result.flags | ||
* return result.flags | ||
* } | ||
* } | ||
*/ | ||
export type InferredFlags<T> = T extends FlagInput<infer F> ? F & { json: boolean | undefined; } : unknown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.