An option is resolved from the root before the matched command, so a short name means one thing for the whole line
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 56/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- javascript, typescript
- Domaine
- cli
Piste de recherche
Commencez par RootCommand#shouldCompleteFlags() et #stripOptions(), puis suivez comment matchCommand() appelle ce dernier et comment handleFlagCompletion() utilise la commande correspondante. Exécutez la reproduction fournie avec Node et comparez la complétion pour les quatre cas argv. C’est terminé lorsque l’arité des options suit la commande déterminée à chaque position, tandis que les options racine placées avant une commande continuent de fonctionner comme auparavant.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
What happens
RootCommand#shouldCompleteFlags() and #stripOptions() decide whether the word after an option is that option's value. Both resolve the option with findOption(this, arg) — the root first — and fall back to the registered commands only when the root does not have it. An option therefore has one arity for the whole line, whichever command the cursor is in.
A CLI whose root carries the program's own options, and whose sub-command gives one of those letters to an option that takes a value, cannot be completed there.
Reproduction
// repro.mjs — `npm i @bomb.sh/[email protected]`, then `node repro.mjs`
import { RootCommand } from '@bomb.sh/tab'
const build = () => {
const root = new RootCommand()
root.option('help', 'Display this help message', 'h') // boolean, takes no value
const serve = root.command('serve', 'Serve the app')
serve.option('host', 'Host name', c => c('localhost', ''), 'h') // takes a value, same letter
serve.argument('env', c => {
c('prod', '')
c('staging', '')
})
return root
}
for (const argv of [
['serve', '-h', ''],
['serve', '-h', 'localhost', ''],
['serve', '--host', ''],
['-h', '']
]) {
process.stdout.write(`${JSON.stringify(argv).padEnd(36)} => `)
build().parse([...argv])
}
Actual output (@bomb.sh/tab 0.0.22, Node 24.21.0). Each request prints its candidates one per line; they are joined with / here:
["serve","-h",""] => prod / staging / :4
["serve","-h","localhost",""] => :4
["serve","--host",""] => localhost / :4
["-h",""] => serve / :4
serve -h <TAB>offers the positional, because-hwas read as the root's booleanhelp. Expected:localhost, the value of the command's--host.serve -h localhost <TAB>offers nothing, becauselocalhostwas counted as the positional. Expected:prod,staging.- The last two lines are the controls, and both are right: the long name resolves against the command, and
-hin front of a command name is the root's.
Why it is not simply "look at the matched command"
stripOptions() is what matchCommand() calls to find the command, so the command is not known when the question is asked. Fixing it means walking the words in order and resolving each option against the command that is settled at that point — the root until a command name is matched, then that command, and so on.
handleFlagCompletion() already resolves against the matched command, so once shouldCompleteFlags() answers correctly for a letter typed behind a command name, the value completion follows.
Related
Issue #110 (closed) is the same family: handlePositionalCompletion() counted words without stripping options. This is the other half — the stripping itself does not know where it is.
Downstream
gunshi (kazupon/gunshi#744) works around it by re-registering the root's entry for that one letter, for the duration of one completion request, and only when the letter was typed behind the matched command's name
(PR #753, corrected in PR #754 — the first attempt re-registered the root's entry under the option's long name, which flipped the arity of --help too). The workaround cannot express the same letter on both sides of a command name, because one Option carries one arity for the request. If the lookup here becomes positional, that workaround is deleted whole.
- Langage dominant
- TypeScript
- Étoiles
- 282
- Forks
- 11
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de bombshell-dev/tab
-
enhancement
Difficulté 3/5 1-2 jours Accessibilité débutants 55/100
bombshell-dev/tab#127 · 2 commentaires ·
-
support completions for npx/bunxOuverte
Difficulté 3/5 1-2 jours Accessibilité débutants 55/100
bombshell-dev/tab#118 ·
-
provide installation utilitiesPeut-être pris @theoephraim l’a pris il y a 136 jours. Ouverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
bombshell-dev/tab#117 ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
bombshell-dev/tab#107 · 3 commentaires ·
-
documentation enhancement
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 30/100
bombshell-dev/tab#106 · 1 commentaire ·
Toutes les issues de bombshell-dev/tab
Issues similaires
-
cleanName keeps a state code that's joined to the word before it (SavannahGa → "Savannah Ga")Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
openwatersio/slackwater-database#281 ·
Les mainteneurs répondent en général sous 1 jour
-
accepted bug via-triage
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
pingdotgg/t3code#18690 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Bayern feature:Application ready web
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
digitalfabrik/entitlementcard#3176 ·
Les mainteneurs répondent en général sous 7 jours
-
[BUG] 运行位置的分支列表不自动刷新,外部新建的分支看不到Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
NanmiCoder/cc-haha#1533 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
Les mainteneurs répondent en général sous 1 jour