From 146f4513c112831d9e98c9f8cce32c7857924b17 Mon Sep 17 00:00:00 2001 From: zuixinwang <59717852+zuixinwang@users.noreply.github.com> Date: Mon, 12 Jun 2023 00:05:30 +0800 Subject: [PATCH 1/3] fix: semantic does not match description close #39 --- src/types.ts | 2 +- src/usage.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/types.ts b/src/types.ts index ea6527a..b6e19a0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -11,7 +11,7 @@ export type _ArgDef = { required?: boolean; }; -export type BooleanArgDef = _ArgDef<"boolean", boolean>; +export type BooleanArgDef = _ArgDef<"boolean", boolean> & { negativeDescription?: string }; export type StringArgDef = _ArgDef<"string", string>; export type PositionalArgDef = Omit<_ArgDef<"positional", string>, "alias">; export type ArgDef = BooleanArgDef | StringArgDef | PositionalArgDef; diff --git a/src/usage.ts b/src/usage.ts index 6c6524f..c214a59 100644 --- a/src/usage.ts +++ b/src/usage.ts @@ -48,9 +48,13 @@ export async function renderUsage(cmd: CommandDef, parent?: CommandDef) { arg.valueHint ? `<${arg.valueHint}>` : `"${arg.default || ""}"` }` : ""); + let description = arg.description; + if (arg.type === "boolean" && arg.default === true) { + description = arg.negativeDescription + } argLines.push([ argStr + (isRequired ? " (required)" : ""), - arg.description || "", + description || "", ]); if (isRequired) { usageLine.push(argStr); From 15a0bbc24b7dc363ab0567e2190c865cd5af7762 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 11 Oct 2023 07:37:02 +0000 Subject: [PATCH 2/3] chore: apply automated lint fixes --- src/types.ts | 4 +++- src/usage.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/types.ts b/src/types.ts index 4e778d6..9b4de22 100644 --- a/src/types.ts +++ b/src/types.ts @@ -11,7 +11,9 @@ export type _ArgDef = { required?: boolean; }; -export type BooleanArgDef = _ArgDef<"boolean", boolean> & { negativeDescription?: string }; +export type BooleanArgDef = _ArgDef<"boolean", boolean> & { + negativeDescription?: string; +}; export type StringArgDef = _ArgDef<"string", string>; export type PositionalArgDef = Omit<_ArgDef<"positional", string>, "alias">; export type ArgDef = BooleanArgDef | StringArgDef | PositionalArgDef; diff --git a/src/usage.ts b/src/usage.ts index 706d25d..01f87cb 100644 --- a/src/usage.ts +++ b/src/usage.ts @@ -58,7 +58,7 @@ export async function renderUsage( : ""); let description = arg.description; if (arg.type === "boolean" && arg.default === true) { - description = arg.negativeDescription + description = arg.negativeDescription; } argLines.push([ "`" + argStr + (isRequired ? " (required)" : "") + "`", From b67842b06e2f4e5ac5911a7475a19e6adefdae90 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 18 Mar 2024 16:39:45 +0100 Subject: [PATCH 3/3] keep fallback --- src/usage.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/usage.ts b/src/usage.ts index 39af6f7..cb4a794 100644 --- a/src/usage.ts +++ b/src/usage.ts @@ -63,10 +63,10 @@ export async function renderUsage( (arg.type === "enum" && arg.options ? `=<${arg.options.join("|")}>` : ""); - let description = arg.description; - if (arg.type === "boolean" && arg.default === true) { - description = arg.negativeDescription; - } + const isNegative = arg.type === "boolean" && arg.default === true; + const description = isNegative + ? arg.negativeDescription || arg.description + : arg.description; argLines.push([ "`" + argStr + (isRequired ? " (required)" : "") + "`", description || "",