diff --git a/README.md b/README.md index 8a93fac3..dd715a82 100755 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ - 🌊 [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 -- 🔜 Autocompletes arguments +- 🔜 Autocompletion - 🔙 Command history - 🤯 Fully typed - ⚡ Uses the power of `yargs` and `enquirer` @@ -27,45 +27,44 @@ intuitive to work with. ## Table of contents - - - - -- [Getting started](#getting-started) - - [Installation](#installation) - - [Simple example](#simple-example) - - [Error handling](#error-handling) - - [REPL example](#repl-example) - - [Prompt](#prompt) - - [TypeScript](#typescript) -- [API](#api) - - [`program(options)`](#programoptions) - - [`program.description(description)`](#programdescriptiondescription) - - [`program.prompt(prompt)`](#programpromptprompt) - - [`program.add(command)`](#programaddcommand) - - [`program.default(command)`](#programdefaultcommand) - - [`program.run(command)`](#programruncommand) - - [`program.repl()`](#programrepl) - - [`program.runOrRepl()`](#programrunorrepl) - - [`program.isRepl()`](#programisrepl) - - [`program.on(event, listener)`](#programonevent-listener) - - [`command(name, options)`](#commandname-options) - - [`command.description(description)`](#commanddescriptiondescription) - - [`command.hidden()`](#commandhidden) - - [`command.argument(name, options)`](#commandargumentname-options) - - [`command.option(name, options)`](#commandoptionname-options) - - [`command.command(command)`](#commandcommandcommand) - - [`command.default()`](#commanddefault) - - [`command.action(function)`](#commandactionfunction) -- [Design principles](#design-principles) - - [Errors](#errors) - - [Output](#output) -- [Bundle](#bundle) -- [Todo](#todo) -- [Contributing](#contributing) -- [License](#license) - - + + + +- [Getting started](#getting-started) + - [Installation](#installation) + - [Simple example](#simple-example) + - [Error handling](#error-handling) + - [REPL example](#repl-example) + - [Prompt](#prompt) + - [TypeScript](#typescript) +- [API](#api) + - [`program(options)`](#programoptions) + - [`program.description(description)`](#programdescriptiondescription) + - [`program.prompt(prompt)`](#programpromptprompt) + - [`program.add(command)`](#programaddcommand) + - [`program.default(command)`](#programdefaultcommand) + - [`program.run(command)`](#programruncommand) + - [`program.repl()`](#programrepl) + - [`program.runOrRepl()`](#programrunorrepl) + - [`program.isRepl()`](#programisrepl) + - [`program.on(event, listener)`](#programonevent-listener) + - [`command(name, options)`](#commandname-options) + - [`command.description(description)`](#commanddescriptiondescription) + - [`command.hidden()`](#commandhidden) + - [`command.argument(name, options)`](#commandargumentname-options) + - [`command.option(name, options)`](#commandoptionname-options) + - [`command.command(command)`](#commandcommandcommand) + - [`command.default()`](#commanddefault) + - [`command.action(function)`](#commandactionfunction) +- [Design principles](#design-principles) + - [Errors](#errors) + - [Output](#output) +- [Bundle](#bundle) +- [Todo](#todo) +- [Contributing](#contributing) +- [License](#license) + + ## Getting started @@ -223,8 +222,8 @@ $ ts-node dice.ts 5 ``` -The REPL can autocomplete commands, arguments and options. Try typing only the -letter `r` and then hit _TAB_. This works for options as well: +The REPL can autocomplete commands, arguments, options and choices. Try typing +only the letter `r` and then hit _TAB_. This works for options as well: ``` $ ts-node dice.ts @@ -737,8 +736,7 @@ Optionally deploy to GitHub, S3, etc. using your preferred CD method if needed. - [ ] Better code coverage - [ ] Consider resolving ambiguity in _prompt_ param/method -- [ ] Async autocomplete method -- [ ] Choices autocompletion in REPL mode (open upstream PR in yargs) +- [ ] Async autocomplete method for arg values ## Contributing diff --git a/examples/repl.ts b/examples/repl.ts index aa36063e..112ee97a 100644 --- a/examples/repl.ts +++ b/examples/repl.ts @@ -11,18 +11,23 @@ const app = program() prompt: true, }) .argument('port', { - default: '443', - type: 'number', + default: 443, prompt: true, }) .argument('tls', { default: true, - type: 'boolean', prompt: true, }) - .action(async ({ host, port, tls }) => { - url = `${tls ? 'https' : 'http'}://${host}:${port}` - console.log(`Connecting to ${url}...`) + .option('protocol', { + default: 'http', + choices: ['http', 'ftp', 'imap', 'ldap', 'pop3'] as const, + }) + .option('timeout', { + default: 60, + }) + .action(async ({ host, port, tls, protocol, timeout }) => { + url = `${protocol}${tls && 's'}://${host}:${port}` + console.log(`Connecting to ${url} (timeout set to ${timeout}s)...`) }) ) .add(