-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
unlok
committed
Aug 11, 2021
1 parent
4ac2f23
commit c8d3663
Showing
2 changed files
with
42 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
declare module "gemini-configparser" { | ||
type PartialConfig = never; | ||
type Locator = never; | ||
type UnsanitizedRootConfig = any; | ||
type UnsanitizedConfigNode = any; | ||
|
||
type Parser<T> = (locator: Locator, config: PartialConfig) => T; | ||
|
||
type RootPrefixes = { | ||
envPrefix: string; | ||
cliPrefix: string; | ||
}; | ||
|
||
type OptionParserConfig<T> = { | ||
defaultValue: T | ((config: UnsanitizedRootConfig, currNode: UnsanitizedConfigNode) => T); | ||
parseCli?(input: string): T; | ||
parseEnv?(input: string): T; | ||
validate?(value: T, config: UnsanitizedRootConfig, currNode: UnsanitizedConfigNode): void; | ||
}; | ||
|
||
type MappedOptionParserConfig<S, T> = OptionParserConfig<S> & { | ||
map(value: S, config: UnsanitizedRootConfig, currNode: UnsanitizedConfigNode): T; | ||
}; | ||
|
||
type SectionProperties<T> = { [name in keyof T]: Parser<T[name]> }; | ||
|
||
export function option<T>(description: OptionParserConfig<T>): Parser<T>; | ||
export function option<S, T>(description: MappedOptionParserConfig<S, T>): Parser<T>; | ||
export function section<T>(properties: SectionProperties<T>): Parser<T>; | ||
|
||
type RootParserArg = { | ||
options: UnsanitizedRootConfig; | ||
env: NodeJS.ProcessEnv; | ||
argv: Array<string>; | ||
}; | ||
type RootParser<T> = (arg: RootParserArg) => T; | ||
export function root<T>(rootParser: Parser<T>, prefixes: RootPrefixes): RootParser<T>; | ||
|
||
export class MissingOptionError extends Error {} | ||
export class UnknownKeysError extends Error {} | ||
} |