Skip to content

Commit 5cfa615

Browse files
committed
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.
1 parent 095b4b4 commit 5cfa615

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/command.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ export default class CommandHelp {
100100
const body = renderList(args.map(a => {
101101
const name = a.name.toUpperCase()
102102
let description = a.description || ''
103-
if (a.default) description = `[default: ${a.default}] ${description}`
103+
// `a.default` is actually not always a string (typing bug), hence `toString()`
104+
if (a.default || a.default.toString() === '0') description = `[default: ${a.default}] ${description}`
104105
if (a.options) description = `(${a.options.join('|')}) ${description}`
105106
return [name, description ? dim(description) : undefined]
106107
}), {stripAnsi: this.opts.stripAnsi, maxWidth: this.opts.maxWidth - 2})
@@ -144,7 +145,8 @@ export default class CommandHelp {
144145
}
145146

146147
let right = flag.description || ''
147-
if (flag.type === 'option' && flag.default) {
148+
// `flag.default` is not always a string (typing bug), hence `toString()`
149+
if (flag.type === 'option' && (flag.default || flag.default.toString() === '0')) {
148150
right = `[default: ${flag.default}] ${right}`
149151
}
150152
if (flag.required) right = `(required) ${right}`

0 commit comments

Comments
 (0)