cli zsh completions nit

This commit is contained in:
Ruben Fiszel
2026-02-23 09:09:16 +00:00
parent b60f309a0c
commit f0b7c96d04
2 changed files with 28 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
import { Command } from "@cliffy/command"; import { Command } from "@cliffy/command";
import { CompletionsCommand } from "@cliffy/command/completions"; import { generateShellCompletions } from "@cliffy/command/completions";
import { UpgradeCommand } from "@cliffy/command/upgrade"; import { UpgradeCommand } from "@cliffy/command/upgrade";
import * as log from "./core/log.ts"; import * as log from "./core/log.ts";
@@ -172,7 +172,20 @@ const command = new Command()
); );
}) })
) )
.command("completions", new CompletionsCommand()); .command(
"completions",
new Command()
.description("Generate shell completions.")
.command("bash", new Command().description("Generate bash completions.").action(() => {
process.stdout.write(generateShellCompletions(command, "bash") + "\n");
}))
.command("zsh", new Command().description("Generate zsh completions.").action(() => {
process.stdout.write(generateShellCompletions(command, "zsh") + "\n");
}))
.command("fish", new Command().description("Generate fish completions.").action(() => {
process.stdout.write(generateShellCompletions(command, "fish") + "\n");
}))
);
async function main() { async function main() {
try { try {

13
cli/test_completions4.ts Normal file
View File

@@ -0,0 +1,13 @@
import { Command } from "@cliffy/command";
import { ZshCompletionsGenerator } from "@cliffy/command/completions/_zsh_completions_generator";
const { default: command } = await import("./src/main.ts");
// Generate completions manually
const output = ZshCompletionsGenerator.generate("wmill", command);
console.error(`output length: ${output.length}`);
// Write using process.stdout.write with callback
process.stdout.write(output + "\n", () => {
console.error("write callback called");
process.stdin.destroy();
});