Skip to content

Commit

Permalink
feat: support negativeDescription for args (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
zuixinwang committed Mar 18, 2024
1 parent 2a3b7d3 commit 8995534
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/types.ts
Expand Up @@ -18,7 +18,9 @@ export type _ArgDef<T extends ArgType, VT extends boolean | number | string> = {
options?: (string | number)[];
};

export type BooleanArgDef = Omit<_ArgDef<"boolean", boolean>, "options">;
export type BooleanArgDef = Omit<_ArgDef<"boolean", boolean>, "options"> & {
negativeDescription?: string;
};
export type StringArgDef = Omit<_ArgDef<"string", string>, "options">;
export type NumberArgDef = Omit<_ArgDef<"number", boolean>, "options">;
export type EnumArgDef = _ArgDef<"enum", string>;
Expand Down
6 changes: 5 additions & 1 deletion src/usage.ts
Expand Up @@ -63,9 +63,13 @@ export async function renderUsage<T extends ArgsDef = ArgsDef>(
(arg.type === "enum" && arg.options
? `=<${arg.options.join("|")}>`
: "");
const isNegative = arg.type === "boolean" && arg.default === true;
const description = isNegative
? arg.negativeDescription || arg.description
: arg.description;
argLines.push([
"`" + argStr + (isRequired ? " (required)" : "") + "`",
arg.description || "",
description || "",
]);
if (isRequired) {
usageLine.push(argStr);
Expand Down

0 comments on commit 8995534

Please sign in to comment.