You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add 'see help' messages to usage messages and the help screen
* Update tests for new help messages.
* Update guide examples with additional help messages
% example --file --verbose file1.swift --file file2.swift
339
342
Error: Missing value for '--file <file>'
340
343
Usage: example [--file <file> ...] [--verbose]
344
+
See 'example --help' for more information.
341
345
```
342
346
343
347
The `.unconditionalSingleValue` parsing strategy uses whatever input follows the key as its value, even if that input is dash-prefixed. If `file` were defined as `@Option(parsing: .unconditionalSingleValue) var file: [String]`, then the resulting array could include strings that look like options:
% example --verbose file1.swift file2.swift --other
389
393
Error: Unexpected argument '--other'
390
394
Usage: example [--verbose] [<files> ...]
395
+
See 'example --help' for more information.
391
396
```
392
397
393
398
Any input after the `--` terminator is automatically treated as positional input, so users can provide dash-prefixed values that way even with the default configuration:
Copy file name to clipboardExpand all lines: Documentation/03 Commands and Subcommands.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,8 @@ SUBCOMMANDS:
27
27
average Print the average of the values.
28
28
stdev Print the standard deviation of the values.
29
29
quantiles Print the quantiles of the values (TBD).
30
+
31
+
See 'math help stats <subcommand>' for detailed help.
30
32
```
31
33
32
34
Start by defining the root `Math` command. You can provide a static `configuration` property for a command that specifies its subcommands and a default subcommand, if any.
Copy file name to clipboardExpand all lines: Documentation/05 Validation and Errors.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,12 +44,15 @@ When you provide useful error messages, they can guide new users to success with
44
44
% select
45
45
Error: Please provide at least one element to choose from.
46
46
Usage: select [--count <count>] [<elements> ...]
47
+
See 'select --help' for more information.
47
48
% select --count 2 hello
48
49
Error: Please specify a 'count' less than the number of elements.
49
50
Usage: select [--count <count>] [<elements> ...]
51
+
See 'select --help' for more information.
50
52
% select --count 0 hello hey hi howdy
51
53
Error: Please specify a 'count' of at least 1.
52
54
Usage: select [--count <count>] [<elements> ...]
55
+
See 'select --help' for more information.
53
56
% select --count 2 hello hey hi howdy
54
57
howdy
55
58
hey
@@ -145,6 +148,7 @@ Throwing from a transform closure benefits users by providing context and can re
145
148
% example '{"Bad JSON"}'
146
149
Error: The value '{"Bad JSON"}' is invalid for '<input-json>': dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "No value for key in object around character 11." UserInfo={NSDebugDescription=No value for key in object around character 11.})))
147
150
Usage: example <input-json> --fail-option <fail-option>
151
+
See 'select --help' for more information.
148
152
```
149
153
150
154
While throwing standard library or Foundation errors adds context, custom errors provide the best experience for users and developers.
@@ -153,4 +157,5 @@ While throwing standard library or Foundation errors adds context, custom errors
153
157
% example '{"tokenCount":0,"tokens":[],"identifier":"F77D661C-C5B7-448E-9344-267B284F66AD"}' --fail-option="Some Text Here!"
154
158
Error: The value 'Some Text Here!' is invalid for '--fail-option <fail-option>': Trying to write to failOption always produces an error. Input: Some Text Here!
155
159
Usage: example <input-json> --fail-option <fail-option>
0 commit comments