Skip to content

Commit

Permalink
chore: remote choices todo
Browse files Browse the repository at this point in the history
Choices autocompletion is now available from upstream yargs, see yargs/yargs#2018
  • Loading branch information
hongaar committed Sep 23, 2021
1 parent dc67dcd commit 5a9cd9b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 50 deletions.
86 changes: 42 additions & 44 deletions README.md
Expand Up @@ -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`
Expand All @@ -27,45 +27,44 @@ intuitive to work with.

## Table of contents

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [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)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [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)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Getting started

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
17 changes: 11 additions & 6 deletions examples/repl.ts
Expand Up @@ -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(
Expand Down

0 comments on commit 5a9cd9b

Please sign in to comment.