Skip to content

Commit 94e46f8

Browse files
fix: indicate whether an argument is optional in the help command (#1453) (#1482)
* fix: indicate whether an argument is optional in the help command (#1453) * test: update help unit tests --------- Co-authored-by: Matthew Yarmolinsky <yarmolinskymatthew@gmail.com>
1 parent 77a8969 commit 94e46f8

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/help/command.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export class CommandHelp extends HelpFormatter {
5959

6060
return args.map((a) => {
6161
// Add ellipsis to indicate that the argument takes multiple values if strict is false
62-
const name = this.command.strict === false ? `${a.name.toUpperCase()}...` : a.name.toUpperCase()
62+
let name = this.command.strict === false ? `${a.name.toUpperCase()}...` : a.name.toUpperCase()
63+
name = a.required ? `${name}` : `[${name}]`
6364
let description = a.description || ''
6465
if (a.default)
6566
description = `${colorize(this.config?.theme?.flagDefaultValue, `[default: ${a.default}]`)} ${description}`

test/help/format-command-with-options.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ multiline help`,
4646
<value>] [-l <value>]
4747
4848
ARGUMENTS
49-
APP_NAME app to use
49+
[APP_NAME] app to use
5050
5151
OPTIONS
5252
-f, --foo=foo foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoo
@@ -95,7 +95,7 @@ ALIASES
9595
<value>]
9696
9797
ARGUMENTS
98-
APP_NAME
98+
[APP_NAME]
9999
app to useapp to useapp to useapp to useapp to useapp to useapp to useapp to
100100
useapp to useapp to useapp to useapp to useapp to useapp to useapp to useapp
101101
to useapp to useapp to useapp to useapp to useapp to useapp to useapp to
@@ -144,7 +144,7 @@ ALIASES
144144
<value>]
145145
146146
ARGUMENTS
147-
APP_NAME
147+
[APP_NAME]
148148
app to useapp to useapp to useapp to useapp to useapp to useapp to useapp to
149149
useapp to useapp to useapp to useapp to useapp to useapp to useapp to useapp
150150
to useapp to useapp to useapp to useapp to useapp to useapp to useapp to
@@ -198,7 +198,7 @@ ALIASES
198198
$ oclif apps:create [APP_NAME] [--force]
199199
200200
ARGUMENTS
201-
APP_NAME app to use
201+
[APP_NAME] app to use
202202
203203
OPTIONS
204204
--force forces
@@ -269,9 +269,9 @@ OPTIONS
269269
<value>] [--flag3 <value>]
270270
271271
ARGUMENTS
272-
ARG1 [default: .]
273-
ARG2 [default: .] arg2 desc
274-
ARG3 arg3 desc
272+
[ARG1] [default: .]
273+
[ARG2] [default: .] arg2 desc
274+
[ARG3] arg3 desc
275275
276276
OPTIONS
277277
--flag1=flag1 [default: .]
@@ -312,7 +312,7 @@ OPTIONS
312312
$ oclif apps:create [ARG1]
313313
314314
ARGUMENTS
315-
ARG1 (option1|option2) Show the options`)
315+
[ARG1] (option1|option2) Show the options`)
316316
})
317317
})
318318

test/help/format-command.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ multiline help`,
4848
[-r <value>] [-l <value>]
4949
5050
ARGUMENTS
51-
APP_NAME app to use
51+
[APP_NAME] app to use
5252
5353
FLAGS
5454
-f, --foo=<value> foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo
@@ -131,7 +131,7 @@ DESCRIPTION
131131
[-r <value>]
132132
133133
ARGUMENTS
134-
APP_NAME
134+
[APP_NAME]
135135
app to useapp to useapp to useapp to useapp to useapp to useapp to useapp to
136136
useapp to useapp to useapp to useapp to useapp to useapp to useapp to useapp
137137
to useapp to useapp to useapp to useapp to useapp to useapp to useapp to
@@ -188,7 +188,7 @@ ALIASES
188188
[-r <value>]
189189
190190
ARGUMENTS
191-
APP_NAME
191+
[APP_NAME]
192192
app to useapp to useapp to useapp to useapp to useapp to useapp to useapp to
193193
useapp to useapp to useapp to useapp to useapp to useapp to useapp to useapp
194194
to useapp to useapp to useapp to useapp to useapp to useapp to useapp to
@@ -285,7 +285,7 @@ DESCRIPTION
285285
$ oclif apps:create [APP_NAME] [--json] [--force]
286286
287287
ARGUMENTS
288-
APP_NAME app to use
288+
[APP_NAME] app to use
289289
290290
FLAGS
291291
--force forces
@@ -474,9 +474,9 @@ FLAGS
474474
<value>] [--flag3 <value>]
475475
476476
ARGUMENTS
477-
ARG1 [default: .]
478-
ARG2 [default: .] arg2 desc
479-
ARG3 arg3 desc
477+
[ARG1] [default: .]
478+
[ARG2] [default: .] arg2 desc
479+
[ARG3] arg3 desc
480480
481481
FLAGS
482482
--flag1=<value> [default: .]
@@ -606,7 +606,7 @@ FLAG DESCRIPTIONS
606606
$ oclif apps:create [ARG1]
607607
608608
ARGUMENTS
609-
ARG1 (option1|option2) Show the options`)
609+
[ARG1] (option1|option2) Show the options`)
610610
})
611611

612612
it('should output arg with ... if static is false', async () => {
@@ -625,7 +625,7 @@ ARGUMENTS
625625
$ oclif apps:create [ARG1...]
626626
627627
ARGUMENTS
628-
ARG1... Show the options`)
628+
[ARG1...] Show the options`)
629629
})
630630
})
631631

0 commit comments

Comments
 (0)