Socket
Socket
Sign inDemoInstall

bandersnatch

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bandersnatch - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

2

lib/command.d.ts

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc