jdx / jdx/usage

Allow handing of completion by an external command's shell completion

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

Description

We have a wrapper script around `terraform` and it would be nice to be able to profit from the completion available for the wrapped command.

What we currently do:

```kdl
arg "" help="Layer to run"
arg "" var=#true help="Terraform command to run"
complete "command" descriptions=#true run=#"terraform -help 2>&1 | awk '/^ [a-z]/ {cmd=$1; $1=""; sub(/^ +/,""); print cmd":"$0}'"#
```

It would be nice if the completion could not require `awk` and support further stuff like `terraform plan -o` completing to `-out`.

To demonstrate what would need to happen technically (with fish as an example):

```kdl
arg "" help="Layer to run"
arg "" var=#true help="Terraform command to run"
complete "command" descriptions=#true run=#"fish -c 'complete -C "terraform {{words[CURRENT]}"'"#
// The `words[CURRENT]` is not really correct, as we need all the words that belong to the `command` arg for this to work properly.
// (I don't know if that is currently possible)
```

As `usage` already must be aware of all the completion frameworks it supports, I feel like handing that over would be natural.

I am not sure that the `arg var=#true` style to model this situation is the best way to support this new functionality. I just chose this to bring the point across.

Contributor guide

Open the contributing guide

Research direction

Start by tracing usage's existing completion handling and the shell-framework entry points it already supports. Compare the requested external-command flow with the current `complete` and `arg var=#true` model, including how words belonging to the command argument are passed onward. Done means a defined approach for delegated completion, support for nested arguments such as `terraform plan -o`, and coverage for the supported shell frameworks.

Written by the indexing model from the issue text.

Assessment

Tech stack
fish, rust, shell
Domain
cli, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.