From 5cfa615e3c095df8915377609924fab39cb4e00d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20W=C3=B3dkiewicz?= Date: Wed, 11 Aug 2021 10:51:16 +0200 Subject: [PATCH 1/2] fix: print default arg/flag if equal to 0 When the default value for an arg/flag was set to `0` then the `--help` was not displaying it, as if the default was not set. There is probably a typing bug in oclif/config or oclif/parser (depending on what's the desired outcome). The default values typing is `string`, however the actual values can be set to numbers. --- src/command.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/command.ts b/src/command.ts index cbfd0a2b..f7463e03 100644 --- a/src/command.ts +++ b/src/command.ts @@ -100,7 +100,8 @@ export default class CommandHelp { const body = renderList(args.map(a => { const name = a.name.toUpperCase() let description = a.description || '' - if (a.default) description = `[default: ${a.default}] ${description}` + // `a.default` is actually not always a string (typing bug), hence `toString()` + if (a.default || a.default.toString() === '0') description = `[default: ${a.default}] ${description}` if (a.options) description = `(${a.options.join('|')}) ${description}` return [name, description ? dim(description) : undefined] }), {stripAnsi: this.opts.stripAnsi, maxWidth: this.opts.maxWidth - 2}) @@ -144,7 +145,8 @@ export default class CommandHelp { } let right = flag.description || '' - if (flag.type === 'option' && flag.default) { + // `flag.default` is not always a string (typing bug), hence `toString()` + if (flag.type === 'option' && (flag.default || flag.default.toString() === '0')) { right = `[default: ${flag.default}] ${right}` } if (flag.required) right = `(required) ${right}` From 10733c44b810517870b7a7cbbdb4eb860b80a833 Mon Sep 17 00:00:00 2001 From: Rodrigo Espinosa de los Monteros <1084688+RodEsp@users.noreply.github.com> Date: Wed, 11 Aug 2021 09:23:20 -0400 Subject: [PATCH 2/2] chore: please TSC --- src/command.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/command.ts b/src/command.ts index f7463e03..4aa47ef2 100644 --- a/src/command.ts +++ b/src/command.ts @@ -101,7 +101,7 @@ export default class CommandHelp { const name = a.name.toUpperCase() let description = a.description || '' // `a.default` is actually not always a string (typing bug), hence `toString()` - if (a.default || a.default.toString() === '0') description = `[default: ${a.default}] ${description}` + if (a.default || a.default?.toString() === '0') description = `[default: ${a.default}] ${description}` if (a.options) description = `(${a.options.join('|')}) ${description}` return [name, description ? dim(description) : undefined] }), {stripAnsi: this.opts.stripAnsi, maxWidth: this.opts.maxWidth - 2}) @@ -146,7 +146,7 @@ export default class CommandHelp { let right = flag.description || '' // `flag.default` is not always a string (typing bug), hence `toString()` - if (flag.type === 'option' && (flag.default || flag.default.toString() === '0')) { + if (flag.type === 'option' && (flag.default || flag.default?.toString() === '0')) { right = `[default: ${flag.default}] ${right}` } if (flag.required) right = `(required) ${right}`