-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
breaking(flags,command): refactor type handler
To make types compatible with environment variable and arguments the arguments of the type handler has changed from: ```typescript const myType: ITypeHandler<number> = ( option: IFlagOptions, arg: IFlagArgument, value: string ): number => {}; ``` to: ```typescript const myType: ITypeHandler<number> = ( { label, name, value, type }: ITypeInfo ): number => {}; ``` This makes it possible to write a single error messages for different contexts. ```typescript throw new Error( `${ label } ${ name } must be of type ${ type } but got: ${ value }` ); ``` For options the error message will be: `Option --my-option must be of type number but got: abc` For environment variables the error message will be: `Environment variable MY_ENV_VAR must be of type number but got: abc` For arguments the error message will be: `Argument my-argument must be of type number but got: abc`
- Loading branch information
Showing
17 changed files
with
91 additions
and
75 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
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { IFlagArgument, IFlagOptions } from '../flags/types.ts'; | ||
import { ITypeInfo } from '../flags/types.ts'; | ||
import { Command } from './command.ts'; | ||
|
||
export abstract class Type<T> { | ||
|
||
public abstract parse( option: IFlagOptions, arg: IFlagArgument, value: string ): T | ||
public abstract parse( type: ITypeInfo ): T | ||
|
||
public complete?( cmd: Command, parent?: Command ): string[]; | ||
} |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { IFlagArgument, IFlagOptions } from '../../flags/types.ts'; | ||
import { ITypeInfo } from '../../flags/types.ts'; | ||
import { number } from '../../flags/types/number.ts'; | ||
import { Type } from '../type.ts'; | ||
|
||
export class NumberType extends Type<number> { | ||
|
||
public parse( option: IFlagOptions, arg: IFlagArgument, value: string ): number { | ||
return number( option, arg, value ); | ||
public parse( type: ITypeInfo ): number { | ||
return number( type ); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { IFlagArgument, IFlagOptions } from '../../flags/types.ts'; | ||
import { ITypeInfo } from '../../flags/types.ts'; | ||
import { string } from '../../flags/types/string.ts'; | ||
import { Type } from '../type.ts'; | ||
|
||
export class StringType extends Type<string> { | ||
|
||
public parse( option: IFlagOptions, arg: IFlagArgument, value: string ): string { | ||
return string( option, arg, value ); | ||
public parse( type: ITypeInfo ): string { | ||
return string( type ); | ||
} | ||
} |
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
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
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.