Skip to content

Commit 01d8c8f

Browse files
authored
Consistently use . to finish sentences. (#8)
Give more guidance on how to write text.
1 parent e11574d commit 01d8c8f

File tree

6 files changed

+270
-247
lines changed

6 files changed

+270
-247
lines changed

examples/main.toit

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,25 @@ The command will have the following help:
1313
```
1414
This is an imaginary fleet manager for a fleet of Toit devices.
1515
16-
It can not be used to manage the fleet, for example by adding or removing devices.
16+
It can not be used to manage the fleet, for example
17+
by adding or removing devices.
1718
1819
Usage:
1920
examples/main.toit <command>
2021
2122
Commands:
2223
device Manage a particular device.
23-
help Show help for a command
24-
status Shows the status of the fleet
24+
help Show help for a command.
25+
status Shows the status of the fleet.
2526
2627
Options:
27-
-h, --help Show help for this command
28+
-h, --help Show help for this command.
2829
2930
Examples:
30-
# Do a soft-reset of device 'foo'.
31+
# Do a soft-reset of device 'foo':
3132
fleet_manager device --device=foo reset -m soft
3233
33-
# Show a detailed status of the fleet
34+
# Show a detailed status of the fleet:
3435
fleet_manager status --verbose
3536
```
3637
@@ -44,18 +45,18 @@ Usage:
4445
examples/main.toit device reset --mode=<hard|soft> [<options>]
4546
4647
Options:
47-
-f, --force Force the reset even if the device is active
48-
-h, --help Show help for this command
49-
-m, --mode hard|soft The reset mode to use (required)
48+
-f, --force Force the reset even if the device is active.
49+
-h, --help Show help for this command.
50+
-m, --mode hard|soft The reset mode to use. (required)
5051
5152
Global options:
52-
-d, --device string The device to operate on
53+
-d, --device string The device to operate on.
5354
5455
Examples:
55-
# Do a soft-reset of device 'foo'.
56+
# Do a soft-reset of device 'foo':
5657
fleet_manager device --device=foo reset -m soft
5758
58-
# Do a hard-reset
59+
# Do a hard-reset:
5960
fleet_manager device reset --mode=hard
6061
```
6162
*/
@@ -67,7 +68,8 @@ main arguments:
6768
--long_help="""
6869
This is an imaginary fleet manager for a fleet of Toit devices.
6970
70-
It can not be used to manage the fleet, for example by adding or removing devices.
71+
It can not be used to manage the fleet, for example
72+
by adding or removing devices.
7173
"""
7274

7375
root_cmd.add create_status_command
@@ -79,14 +81,14 @@ main arguments:
7981
8082
create_status_command -> cli.Command:
8183
return cli.Command "status"
82-
--short_help="Shows the status of the fleet"
84+
--short_help="Shows the status of the fleet:"
8385
--options=[
8486
cli.Flag "verbose" --short_name="v" --short_help="Show more details." --multi,
8587
cli.OptionInt "max-lines" --short_help="Maximum number of lines to show." --default=10,
8688
]
8789
--examples=[
88-
cli.Example "Show the status of the fleet" --arguments="",
89-
cli.Example "Show a detailed status of the fleet" --arguments="--verbose"
90+
cli.Example "Show the status of the fleet:" --arguments="",
91+
cli.Example "Show a detailed status of the fleet:" --arguments="--verbose"
9092
--global_priority=7, // Show this example for the root command.
9193
]
9294
--run=:: fleet_status it
@@ -118,7 +120,7 @@ create_device_command -> cli.Command:
118120
"""
119121
--options=[
120122
cli.OptionString "device" --short_name="d"
121-
--short_help="The device to operate on"
123+
--short_help="The device to operate on."
122124
]
123125
device_cmd.add create_reset_command
124126
return device_cmd
@@ -132,19 +134,19 @@ create_reset_command -> cli.Command:
132134
"""
133135
--options=[
134136
cli.OptionEnum "mode" ["hard", "soft"]
135-
--short_help="The reset mode to use"
137+
--short_help="The reset mode to use."
136138
--short_name="m"
137139
--required,
138140
cli.Flag "force" --short_name="f"
139-
--short_help="Force the reset even if the device is active",
141+
--short_help="Force the reset even if the device is active.",
140142
]
141143
--examples=[
142144
cli.Example
143-
"Do a soft-reset of device 'foo'."
145+
"Do a soft-reset of device 'foo':"
144146
--arguments="--device=foo -m soft"
145147
--global_priority=5, // Include this example for super commands.
146148
cli.Example
147-
"Do a hard-reset"
149+
"Do a hard-reset:"
148150
--arguments="--mode=hard",
149151
]
150152
--run=:: reset_device it

src/cli.toit

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,12 @@ class Command:
7575
The $usage is usually constructed from the name and the arguments of the command, but can
7676
be provided explicitly if a different usage string is desired.
7777
78-
The $short_help is a short (one line) description of the command.
78+
The $long_help is a longer description of the command that can span multiple lines. Use
79+
indented lines to continue paragraphs (just like toitdoc).
7980
80-
The $long_help is a longer description of the command that can span multiple lines.
81+
The $short_help is a short description of the command. In most cases this help is a single
82+
line, but it can span multiple lines/paragraphs if necessary. Use indented lines to
83+
continue paragraphs (just like toitdoc).
8184
*/
8285
constructor .name --.usage=null --.short_help=null --.long_help=null --.examples=[] \
8386
--.aliases=[] --.options=[] --.rest=[] --.subcommands=[] --hidden/bool=false \
@@ -222,6 +225,29 @@ abstract class Option:
222225
is_multi/bool
223226
should_split_commas/bool
224227

228+
/**
229+
Creates an option with the given $name.
230+
231+
The $name sets the name of the option. It must be unique among all options of a command.
232+
It is also used to extract the parsed value from the $Parsed object.
233+
234+
The $short_name is optional and must be a single-character string when provided.
235+
236+
The $short_help is optional and is used for help output. It should be a full sentence, starting
237+
with a capital letter and ending with a period.
238+
239+
If $required is true, then the option must be provided. Otherwise, it is optional.
240+
241+
If $hidden is true, then the option is not shown in help output. Rest arguments must not be
242+
hidden.
243+
244+
If $multi is true, then the option can be provided multiple times. The parsed value will
245+
be a list of strings.
246+
247+
If $split_commas is true, then $multi must be true too. Values given to this option are then
248+
split on commas. For example, `--option a,b,c` will result in the list `["a", "b", "c"]`.
249+
250+
*/
225251
constructor .name --.short_name --.short_help --required --hidden --multi --split_commas:
226252
is_required = required
227253
is_hidden = hidden
@@ -277,27 +303,12 @@ class OptionString extends Option:
277303
/**
278304
Creates a new string option.
279305
280-
The $name sets the name of the option. It must be unique among all options of a command.
281-
It is also used to extract the parsed value from the $Parsed object.
282-
283306
The $default value is null.
307+
284308
The $type is set to 'string', but can be changed to something else. The $type is
285309
only used for help output.
286310
287-
The $short_name is optional and must be a single-character string when provided.
288-
289-
The $short_help is optional and is used for help output.
290-
291-
If $required is true, then the option must be provided. Otherwise, it is optional.
292-
293-
If $hidden is true, then the option is not shown in help output. Rest arguments must not be
294-
hidden.
295-
296-
If $multi is true, then the option can be provided multiple times. The parsed value will
297-
be a list of strings.
298-
299-
If $split_commas is true, then $multi must be true too. Values given to this option are then
300-
split on commas. For example, `--option a,b,c` will result in the list `["a", "b", "c"]`.
311+
See $Option.constructor for the other parameters.
301312
*/
302313
constructor name/string
303314
--.default=null
@@ -337,7 +348,10 @@ class OptionEnum extends Option:
337348
338349
The $values list provides the list of valid values for this option.
339350
340-
See $OptionString.constructor for the other parameters.
351+
The $default value is null.
352+
The $type defaults to a string joining all $values with a '|'.
353+
354+
See $Option.constructor for the other parameters.
341355
*/
342356
constructor name/string .values/List
343357
--.default=null
@@ -367,7 +381,6 @@ class OptionEnum extends Option:
367381
An option that must be an integer value.
368382
369383
The $parse function ensures that the value is an integer.
370-
The $type defaults to "int".
371384
*/
372385
class OptionInt extends Option:
373386
default/int?
@@ -376,7 +389,10 @@ class OptionInt extends Option:
376389
/**
377390
Creates a new integer option.
378391
379-
See $OptionString.constructor for a description of the parameters.
392+
The $default value is null.
393+
The $type defaults to "int".
394+
395+
See $Option.constructor for the other parameters.
380396
*/
381397
constructor name/string
382398
--.default=null
@@ -414,7 +430,10 @@ class Flag extends Option:
414430
/**
415431
Creates a new flag.
416432
417-
See $OptionString.constructor for a description of the parameters.
433+
The $default value is null.
434+
The $type is only visible when using this option as a rest argument and is then "true|false"
435+
436+
See $Option.constructor for the other parameters.
418437
*/
419438
constructor name/string
420439
--.default=null
@@ -452,7 +471,9 @@ class Example:
452471
Creates an example.
453472
454473
The $description should describe the example without any context. This is especially true
455-
if the $global_priority is greater than 0 (see below).
474+
if the $global_priority is greater than 0 (see below). It should start with a capital
475+
letter and finish with a ":". It may contain newlines. Use indentation to group
476+
paragraphs (just like toitdoc).
456477
457478
The $arguments is a string containing the arguments to this command (or to super commands).
458479
The help generator parses the arguments and assigns all options to the corresponding commands.

src/help_generator_.toit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class HelpGenerator:
199199
commands_and_help.add [subcommand.name, help_str]
200200

201201
if not has_help_subcommand and is_root_command_:
202-
commands_and_help.add ["help", "Show help for a command"]
202+
commands_and_help.add ["help", "Show help for a command."]
203203

204204
sorted_commands := commands_and_help.sort: | a/List b/List | a[0].compare_to b[0]
205205
write_table_ sorted_commands --indentation=2
@@ -236,7 +236,7 @@ class HelpGenerator:
236236
if not has_help_flag:
237237
options = options.copy
238238
short_name := has_short_help_flag ? null : "h"
239-
help_flag := Flag "help" --short_name=short_name --short_help="Show help for this command"
239+
help_flag := Flag "help" --short_name=short_name --short_help="Show help for this command."
240240
options.add help_flag
241241

242242
sorted_options := options.sort: | a/Option b/Option | a.name.compare_to b.name

0 commit comments

Comments
 (0)