apple / apple/swift-argument-parser

Support completion for command alias arguments (i.e. flags, options, option values, positional arguments, and/or subcommands)

Open
#847 6 comments 1 reaction 0 assignees View on GitHub
Dominant language
Swift
Stars
3.8k
Forks
411
Avg merge
7d 14h
Merged PRs (30d)
15

Description

Support completion for command alias arguments (i.e. flags, options, option values, positional arguments, and/or subcommands).

I think that, at least by default, only the "real" command names (not aliases) should be offered to be completed, but, if an alias is used on the command line, its flags, options, option values, arguments, and subcommands should be offered as completions.

e.g. if you have a command `c` with a subcommand named `real` with an alias `alias` that has flags, options, arguments , and/or subcommands:

```shell
# offer real if you tab after r
c r

# do not offer alias if you tab after a
c a

# complete the flags, options, option values, arguments, and/or subcommands for real/alias
c real …

# complete the flags, options, option values, arguments, and/or subcommands for real/alias
c alias …
```

Maybe there could be a setting to also offer aliases when potentially completing to them (e.g., offering `alias` when tabbing after `a`), but I don't think that should be the default. The setting could be on a per overall command basis, per subcommands of a specific command, per specific subcommand, or per alias. If I submit a PR for this issue, however, I'd probably leave out any such setting.

**ArgumentParser version:** `main`
**Swift version:** n/a

### Checklist

- [x] If possible, I've reproduced the issue using the `main` branch of this package
- [x] I've searched for [existing GitHub issues](https://github.com/apple/swift-argument-parser/issues)

### Steps to Reproduce

1. Create a command with an alias & some flags
2. Build
3. Generate completion scripts
4. Try to complete one of the flags after the alias
5. See that no completions offered

### Expected behavior

I expect completions for flags, options, option values, arguments, and subcommands to be offered after aliases.

### Actual behavior

Completions aren't offered for the alias's args.

Contributor guide

Open the contributing guide

Research direction

Start by tracing completion-script generation for command aliases after reproducing the example with a command, alias, flags, options, arguments, and subcommands. Verify completion after the real command and its alias offers the same arguments, while default name completion offers the real command name but not the alias.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.