Repository navigation
Description
Package
@bomb.sh/tab
Package Version
v0.0.22 (also on main f0d1e48)
Node.js Version
v26.13.0
Operating System
Linux
Describe the bug
Passing an option with --opt value completes subcommands and positional arguments on the next word, whereas passing --opt=value (or -o=value, including right after accepting --opt=<TAB>) returns no completions for the next word and swallows the following non-flag word when matching subcommands or counting positional arguments.
In src/t.ts, shouldCompleteFlags checks lastPrevArg?.startsWith('-') without checking whether lastPrevArg already contains =, so --port=3000 is not found by findOption, is treated as a non-boolean option still awaiting a value, and produces no candidates; stripOptions and scanArguments likewise fail to recognize = as an inline value and skip the following argument.
To Reproduce
Reproduction link: https://gist.github.com/trackoor/a84149f6f00d94abd8b6f86f0d02b312
// repro.mjs (npm i @bomb.sh/tab@0.0.22 && node repro.mjs)
import { RootCommand } from "@bomb.sh/tab";
function makeCli() {
const root = new RootCommand();
const dev = root.command("dev", "Start dev server");
dev.option("port", "Specify port", (complete) => complete("3000", "Dev port"), "p");
dev.argument("entry", (complete) => complete("src/index.ts", "Entry file"));
const build = root.command("dev build", "Build project");
build.argument("target", (complete) => complete("dist", "Output dir"));
return root;
}
console.log("--- space-separated ---");
makeCli().parse(["dev", "--port", "3000", ""]);
makeCli().parse(["dev", "--port", "3000", "build", ""]);
console.log("--- = syntax ---");
makeCli().parse(["dev", "--port=3000", ""]);
makeCli().parse(["dev", "-p=3000", ""]);
makeCli().parse(["dev", "--port=3000", "b"]);
makeCli().parse(["dev", "--port=3000", "build", ""]);Actual output:
--- space-separated ---
build Build project
src/index.ts Entry file
:4
dist Output dir
:4
--- = syntax ---
:4
:4
:4
build Build project
src/index.ts Entry file
:4
Expected behavior
An --opt=value or -o=value token already carries its value inline, so subsequent words should complete subcommands and positional arguments the same way as after --opt value:
["dev", "--port=3000", ""]and["dev", "-p=3000", ""]outputbuild\tBuild projectandsrc/index.ts\tEntry file.["dev", "--port=3000", "b"]outputsbuild\tBuild project.["dev", "--port=3000", "build", ""]matchesdev buildand outputsdist\tOutput dir.
Additional Information
Found with a differential-testing tool; the report was drafted with AI assistance and reviewed and edited by me.
AI assistance disclosure
- This bug report was drafted with the assistance of an AI tool.
Credit: https://ucsbplse.github.io/
Activity