An option is resolved from the root before the matched command, so a short name means one thing for the whole line
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 56/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, typescript
- 領域
- cli
調査の方向性
RootCommand#shouldCompleteFlags() と #stripOptions() から始め、次に matchCommand() が後者をどのように呼び出し、handleFlagCompletion() が一致したコマンドをどのように使用するかを追跡します。提供されている再現手順を Node で実行し、4 つの argv ケースの補完を比較します。各位置で確定したコマンドにオプションのアリティが従い、コマンドの前にある root オプションがこれまでどおり動作すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- TypeScript
- スター
- 280
- フォーク
- 11
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
bombshell-dev/tab のほかの issue
-
enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
bombshell-dev/tab#127 · コメント 2 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
bombshell-dev/tab#118 ·
-
provide installation utilities対応中かも @theoephraim が 134 日前に担当しました。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
bombshell-dev/tab#117 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
bombshell-dev/tab#107 · コメント 3 件 ·
-
documentation enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
bombshell-dev/tab#106 · コメント 1 件 ·
bombshell-dev/tab の issue をすべて見る
似ている issue
-
check:passed streams:add
難易度 1/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
beta technical-medium ui
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
walletbeat/walletbeat#1625 ·
メンテナーはふだん 1 日以内に返信
-
Good First Issue hacktoberfest
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
hiero-ledger/hiero-sdk-js#4489 ·
メンテナーはふだん 1 日以内に返信
-
[Bug] The clients language filter cannot select the rows the page labels as unknown対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
apache/rocketmq-dashboard#6103 ·
メンテナーはふだん 4 日以内に返信
-
Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
payloadcms/payload#18652 ·
メンテナーはふだん 1 日以内に返信