jdx / jdx/usage

choices from command

Open
#232 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1k
Forks
59
Avg merge
5h 58m
Merged PRs (30d)
362

Description

(comming from using usage in [mise tasks](https://mise.jdx.dev/tasks/file-tasks.html#example-file-task-with-arguments))

It would be nice to define possible `choices` values similar to the `complete` specification `complete "foo" run="my_command"`.

Currently, I have the option to manually define all possible values in `choices` and have them show up in the help/docs. Or have my autocomplete options generated by an external command, but not show the options in any docs.

But sometimes my possible choices are options belonging to an external tool (e.g., services in a compose config) and I don't want to manually write them into my spec.

### Example:

#### Manually defined choices

```bash
#!/usr/bin/env bash
# .mise/tasks/build
#MISE description="Build the docker images."
#
#USAGE arg "..." help="The services to build." default="app database" {
#USAGE choices "app" "database"
#USAGE }

# …
```

```sh
mise run build --help
# =>
# Usage: build [services]...

# Arguments:
# [services]...
# The services to build.
# [possible values: app, database]
```

```sh
mise run build
# =>
# app database
```

#### No choices, but with autocomplete

```bash
#!/usr/bin/env bash
# .mise/tasks/build
#MISE description="Build the docker images."
#
#USAGE arg "..." help="The services to build."
#USAGE complete "services" run="docker compose config | yq '.services | keys[]'"

# …
```

```sh
mise run build --help
# =>
# Usage: build [services]...

# Arguments:
# [services]...
# The services to build.
```

```sh
mise run build
# =>
# app database
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.