bandersnatch
Advanced tools
Comparing version 1.10.1 to 1.10.2
{ | ||
"name": "bandersnatch", | ||
"description": "Simple TypeScript CLI / REPL framework", | ||
"version": "1.10.1", | ||
"version": "1.10.2", | ||
"repository": { | ||
@@ -48,3 +48,3 @@ "type": "git", | ||
"format:toc": "doctoc README.md", | ||
"format:todos": "leasot --exit-nicely --reporter markdown \"{src,tests}/**/*.ts\" > TODO.md", | ||
"format:todos": "leasot --exit-nicely --reporter markdown --ignore \"**/node_modules\" \"**/*.ts\" > TODO.md", | ||
"test": "yarn test:unit && yarn test:types && yarn test:smoke", | ||
@@ -58,7 +58,7 @@ "test:unit": "jest", | ||
"dependencies": { | ||
"@types/yargs": "^17.0.2", | ||
"@types/yargs": "17.0.2", | ||
"enquirer": "^2.3.6", | ||
"string-argv": "^0.3.1", | ||
"typed-emitter": "^2.0.0", | ||
"yargs": "^17.1.1" | ||
"typed-emitter": "^2.1.0", | ||
"yargs": "^17.4.0" | ||
}, | ||
@@ -69,3 +69,3 @@ "devDependencies": { | ||
"@types/jest": "27.4.1", | ||
"@types/node": "16.11.26", | ||
"@types/node": "17.0.23", | ||
"convert-extension": "0.3.0", | ||
@@ -75,14 +75,15 @@ "doctoc": "2.1.0", | ||
"jest": "27.5.1", | ||
"leasot": "12.2.0", | ||
"leasot": "13.1.0", | ||
"mock-argv": "2.0.8", | ||
"prettier": "2.6.0", | ||
"prettier": "2.6.2", | ||
"semantic-release": "19.0.2", | ||
"ts-jest": "27.1.3", | ||
"ts-jest": "27.1.4", | ||
"ts-node": "10.7.0", | ||
"tsd": "0.19.1", | ||
"typescript": "4.6.2" | ||
"tsd": "0.20.0", | ||
"typescript": "4.6.3" | ||
}, | ||
"tsd": { | ||
"directory": "tests/types" | ||
} | ||
}, | ||
"packageManager": "yarn@3.2.0" | ||
} |
153
README.md
@@ -10,20 +10,27 @@ # bandersnatch | ||
> Super lightweight and friendly CLI scaffolding for Node.js programs. | ||
```ts | ||
program() | ||
.default( | ||
command() | ||
.description('What is bandersnatch?') | ||
.action(() => console.log(description)) | ||
) | ||
.run() | ||
``` | ||
``` | ||
$ ./bandersnatch | ||
Simple and intuitive yet powerful and versatile framework for Node.js CLI programs | ||
``` | ||
## Features | ||
- 🌊 [Fluid](https://www.martinfowler.com/bliki/FluentInterface.html) syntax | ||
- ➰ Built-in [REPL](https://en.wikipedia.org/wiki/Read–eval–print_loop) | ||
- 💬 Prompts for missing arguments | ||
- 🔜 Autocompletion | ||
- 🔙 Command history | ||
- 🤯 Fully typed | ||
- ⚡ Uses the power of `yargs` and `enquirer` | ||
- 🌊 [Fluid](https://www.martinfowler.com/bliki/FluentInterface.html) syntax, intuitive to use | ||
- 🔜 Autocompletion of commands, arguments, options and choices | ||
- ➰ Built-in [REPL](https://en.wikipedia.org/wiki/Read–eval–print_loop) for interactive programs with 🔙 Command history | ||
- 💬 Can prompt for missing arguments | ||
- 🤯 Built for TypeScript, command arguments are fully typed | ||
- 🪆 Supports singular (e.g. `foo`) and nested commands (e.g. `foo bar`) | ||
- 🏃 Argument types are guaranteed at runtime (coming soon) | ||
It's built in TypeScript and command arguments are fully typed. | ||
Bandersnatch is not designed to be used as a full CLI framework like oclif, and | ||
tries to minimize the assumptions made about your program to make it easy and | ||
intuitive to work with. | ||
## Table of contents | ||
@@ -34,3 +41,2 @@ | ||
- [Getting started](#getting-started) | ||
@@ -70,3 +76,3 @@ - [Installation](#installation) | ||
- [Devcontainer](#devcontainer) | ||
- [License](#license) | ||
- [Credits](#credits) | ||
@@ -84,4 +90,4 @@ <!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
_ℹ We recommend using a **Active LTS** or **Maintenance LTS** | ||
[Node.js version](https://nodejs.org/en/about/releases/). **Current** versions | ||
ℹ _We recommend using a_ Active LTS _or_ Maintenance LTS | ||
_[Node.js version](https://nodejs.org/en/about/releases/)._ Current _versions | ||
are tested, but not guaranteed to work._ | ||
@@ -91,12 +97,15 @@ | ||
Let's create a simple program `foo.ts`: | ||
Let's create a simple program `foo.js`: | ||
```ts | ||
```js | ||
import { program, command } from 'bandersnatch' | ||
const foo = command('foo') | ||
const cmd = command() | ||
.default() | ||
.description('Outputs "bar".') | ||
.action(() => console.log('bar')) | ||
program().default(foo).run() | ||
const app = program().description('foo').add(cmd) | ||
app.run() | ||
``` | ||
@@ -110,13 +119,11 @@ | ||
``` | ||
$ ts-node foo.ts | ||
$ node foo.js | ||
bar | ||
``` | ||
_ℹ Assuming you have `ts-node` installed._ | ||
Try running `node foo.js --help` to see the auto-generated help output: | ||
Try running `ts-node foo.ts help` to see the auto-generated help output: | ||
``` | ||
$ ts-node foo.ts help | ||
bin.js | ||
$ node foo.js help | ||
foo.js | ||
@@ -126,3 +133,3 @@ Outputs "bar". | ||
Commands: | ||
bin.js Outputs "bar". [default] | ||
foo.js Outputs "bar". [default] | ||
@@ -134,11 +141,8 @@ Options: | ||
_ℹ You see `bin.js` here instead of `foo.ts` because we're running the program | ||
with `ts-node`._ | ||
### Error handling | ||
We first create a new program called `cat.ts` which is a simple version of the | ||
We first create a new program called `cat.js` which is a naive version of the | ||
`cat` program we all know: | ||
```ts | ||
```js | ||
import { readFileSync } from 'fs' | ||
@@ -162,3 +166,3 @@ import { program, command } from 'bandersnatch' | ||
``` | ||
$ ts-node cat.ts somefile | ||
$ node cat.js somefile | ||
contents of somefile | ||
@@ -186,3 +190,3 @@ ``` | ||
``` | ||
$ ts-node cat.ts somefile | ||
$ node cat.js somefile | ||
There was a problem running this command: | ||
@@ -192,3 +196,3 @@ Error: ENOENT: no such file or directory, open 'somefile' | ||
### REPL example | ||
### REPL | ||
@@ -200,8 +204,8 @@ A program can also show an interactive | ||
Let's create a new program `dice.ts` with a command to roll a dice: | ||
Let's create a new program `dice.js` with a command to roll a dice: | ||
```ts | ||
```js | ||
import { program, command } from 'bandersnatch' | ||
async function rng(bounds: [number, number]) { | ||
async function rng(bounds) { | ||
const [min, max] = bounds | ||
@@ -235,3 +239,3 @@ return Math.floor(Math.random() * (max - min + 1)) + min | ||
``` | ||
$ ts-node dice.ts | ||
$ node dice.js | ||
> roll | ||
@@ -245,3 +249,3 @@ 5 | ||
``` | ||
$ ts-node dice.ts | ||
$ node dice.js | ||
> r | ||
@@ -261,5 +265,5 @@ [TAB] | ||
Let's say we want to write a program `pizza.ts` which takes pizza orders: | ||
Let's say we want to write a program `pizza.js` which takes pizza orders: | ||
```ts | ||
```js | ||
import { program, command } from 'bandersnatch' | ||
@@ -303,3 +307,3 @@ | ||
``` | ||
$ ts-node pizza.ts | ||
$ node pizza.js | ||
? Your address The Netherlands | ||
@@ -323,3 +327,3 @@ ? Your name Joram | ||
``` | ||
$ ts-node pizza.ts "The Netherlands" --name Joram --confirmed | ||
$ node pizza.js "The Netherlands" --name Joram --confirmed | ||
? Choose pizza size small | ||
@@ -337,6 +341,6 @@ ? Pick some toppings veggies | ||
⚠ Please note that even though `--confirmed` was specified on the command line, | ||
⚠ _Please note that even though `--confirmed` was specified on the command line, | ||
it was still being prompted. This is a known issue. In this case, the default | ||
value was the same as the input, in which case bandersnatch doesn't know whether | ||
a value was explicitly passed in or inherited from the default value. | ||
a value was explicitly passed in or inherited from the default value._ | ||
@@ -348,3 +352,4 @@ ### TypeScript | ||
Let's slightly improve the example program above to illustrate this: | ||
Let's rename the example program to `pizza.ts` and add some minor type hints to | ||
illustrate this: | ||
@@ -382,5 +387,5 @@ ```diff | ||
ℹ More examples in the | ||
ℹ _More examples in the | ||
[examples](https://github.com/hongaar/bandersnatch/tree/main/examples) | ||
directory. | ||
directory._ | ||
@@ -422,3 +427,3 @@ ## API | ||
```ts | ||
```js | ||
program().add(command(...)) | ||
@@ -431,3 +436,3 @@ ``` | ||
```ts | ||
```js | ||
program().add(command(...).default()) | ||
@@ -441,3 +446,3 @@ ``` | ||
```ts | ||
```js | ||
program() | ||
@@ -452,3 +457,3 @@ .add(command(...)) | ||
```ts | ||
```js | ||
program() | ||
@@ -464,3 +469,3 @@ .add(command(...)) | ||
```ts | ||
```js | ||
program() | ||
@@ -480,3 +485,3 @@ .add(command(...)) | ||
```ts | ||
```js | ||
// Fired before a command action is invoked | ||
@@ -576,3 +581,3 @@ program().on('run', (cmd) => logger.debug(`Running ${cmd}`)) | ||
```ts | ||
```js | ||
program() | ||
@@ -587,3 +592,3 @@ .default( | ||
.runOrRepl() | ||
.catch((error: any) => { | ||
.catch((error) => { | ||
console.error('[failed]', String(error)) | ||
@@ -619,5 +624,5 @@ | ||
ℹ An example can be found in the | ||
ℹ _An example can be found in the | ||
[examples/bundle](https://github.com/hongaar/bandersnatch/tree/main/examples/bundle) | ||
directory. | ||
directory._ | ||
@@ -643,9 +648,7 @@ Init a `package.json` if needed: | ||
export default program() | ||
.withHelp() | ||
.default( | ||
command('echo', 'Echo something in the terminal') | ||
.argument('words', 'Say some kind words', { variadic: true }) | ||
.action(console.log) | ||
) | ||
export default program().default( | ||
command('echo', 'Echo something in the terminal') | ||
.argument('words', 'Say some kind words', { variadic: true }) | ||
.action(console.log) | ||
) | ||
``` | ||
@@ -765,3 +768,3 @@ | ||
_ℹ Omit `-t host` to create binaries for all platforms._ | ||
ℹ _Omit `-t host` to create binaries for all platforms._ | ||
@@ -799,8 +802,8 @@ Run `yarn bundle` and then `./echo --help`. 💪 | ||
## License | ||
## Credits | ||
Copyright (c) 2022 Joram van den Boezem. Licensed under the MIT license. | ||
--- | ||
Inspired by [vorpal](https://vorpal.js.org/) | ||
©️ Copyright 2022 [Joram van den Boezem](https://joram.dev) | ||
♻️ Licensed under the [MIT license](LICENSE) | ||
💡 Inspired by [vorpal](https://vorpal.js.org/) | ||
⚡ Powered by [yargs](http://yargs.js.org) and | ||
[enquirer](https://github.com/enquirer/enquirer) |
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
778
96235
+ Added@types/yargs@17.0.2(transitive)
- Removed@types/yargs@17.0.33(transitive)
Updated@types/yargs@17.0.2
Updatedtyped-emitter@^2.1.0
Updatedyargs@^17.4.0