addParams
tcmts.cli.complete.addParams · #yzzyzypp · term · runs anywhere
import { sourceFor } from "#codebase/tcmts/cli/complete";
import type { Sources } from "#codebase/tcmts/cli/complete";
import { isToggle, paramsOf } from "#codebase/tcmts/cli/help";
import type { RouteShape } from "#codebase/tcmts/cli/help";
import type { Command } from "@bomb.sh/tab";
export function addParams(cmd: Command, route: RouteShape, command: string, s: Sources) {
for (const p of paramsOf(route)) {
const from = sourceFor(command, p.name, s);
if (p.cli.syntax!.type === "argument") cmd.argument(p.name, from ? (complete) => from(complete) : undefined, p.cardinality === "many");
// tab reads an option with a handler as taking a value, one without as a switch
else if (isToggle(p)) cmd.option(p.name, p.description ?? "");
else cmd.option(p.name, p.description ?? "", (complete) => from?.(complete));
}
}
uses
used by