bandersnatch
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -19,3 +19,3 @@ import { Argv, Arguments as BaseArguments } from 'yargs'; | ||
export interface HandlerFn<T> { | ||
(args: Omit<T, '_' | '$0'>): Promise<any> | any; | ||
(args: Omit<T, '_' | '$0'>, commandRunner: CommandRunner): Promise<any> | any; | ||
} | ||
@@ -22,0 +22,0 @@ /** |
@@ -199,3 +199,3 @@ "use strict"; | ||
if (this.handler) { | ||
return this.handler(args); | ||
return this.handler(args, commandRunner); | ||
} | ||
@@ -202,0 +202,0 @@ // Display help this command contains sub-commands |
{ | ||
"name": "bandersnatch", | ||
"description": "Simple TypeScript CLI / REPL framework", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
@@ -37,2 +37,3 @@ # bandersnatch | ||
- [Prompt](#prompt) | ||
- [TypeScript](#typescript) | ||
- [API](#api) | ||
@@ -193,3 +194,3 @@ - [`program(options)`](#programoptions) | ||
}) | ||
.argument('name', { | ||
.option('name', { | ||
description: 'Your name', | ||
@@ -207,4 +208,4 @@ default: 'anonymous', | ||
description: 'Pick some toppings', | ||
choices: ['mozarella', 'pepperoni', 'veggies'], | ||
default: ['mozarella'], | ||
choices: ['mozzarella', 'pepperoni', 'veggies'], | ||
default: ['mozzarella'], | ||
prompt: true, | ||
@@ -264,2 +265,38 @@ }) | ||
### TypeScript | ||
Bandersnatch works perfectly well with non-TypeScript codebases. However, when | ||
you do use TypeScript the command arguments are fully typed. | ||
Let's slightly improve the example program above to illustrate this: | ||
```diff | ||
.option('size', { | ||
description: 'Choose pizza size', | ||
- choices: ['small', 'medium', 'large'], | ||
+ choices: ['small', 'medium', 'large'] as const, | ||
default: 'medium', | ||
prompt: true, | ||
}) | ||
.option('toppings', { | ||
description: 'Pick some toppings', | ||
- choices: ['mozzarella', 'pepperoni', 'veggies'], | ||
+ choices: ['mozzarella', 'pepperoni', 'veggies'] as const, | ||
default: ['mozzarella'], | ||
prompt: true, | ||
}) | ||
``` | ||
The first argument passed to the action handler function is now typed like this: | ||
```ts | ||
type Args = { | ||
address: string | ||
name: string | ||
size: 'small' | 'medium' | 'large' | ||
toppings: ('mozzarella' | 'pepperoni' | 'veggies')[] | ||
confirmed: boolean | ||
} | ||
``` | ||
--- | ||
@@ -266,0 +303,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59244
690