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
Copy file name to clipboardExpand all lines: README.md
+29-21Lines changed: 29 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,8 +18,8 @@ Typically, modeling a CLI tool will begin with a `TopLevelCommandRepresentable`.
18
18
```swift
19
19
structMyCommand: TopLevelCommandRepresentable {
20
20
funccommandValue() -> Command { "my-command" }
21
-
var flagFormatter: FlagFormatter { .doubleDashPrefix }
22
-
var optionFormatter: OptionFormatter { .doubleDashPrefix }
21
+
let flagFormatter=FlagFormatter(prefix: .doubleDash) }
22
+
let optionFormatter=OptionFormatter(prefix: .doubleDash) }
23
23
}
24
24
```
25
25
@@ -30,23 +30,39 @@ Within `MyCommand` we need the ability to model a boolean value to enable/disabl
30
30
```swift
31
31
structMyCommand: TopLevelCommandRepresentable {
32
32
funccommandValue() -> Command { "my-command" }
33
-
var flagFormatter: FlagFormatter { .doubleDashPrefix }
34
-
var optionFormatter: OptionFormatter { .doubleDashPrefix }
33
+
let flagFormatter=FlagFormatter(prefix: .doubleDash) }
34
+
let optionFormatter=OptionFormatter(prefix: .doubleDash) }
35
35
36
36
@Flagvar myFlag: Bool=false
37
37
}
38
38
```
39
39
40
-
In addition to modeling the ability to enable/disable a feature, we need to set a value against some variable. For this, we can use `Option`.
40
+
In addition to modeling the ability to enable/disable a feature, we need to set a value against some variable. For this, we can use `Option`. For options that can have multiple values, there is `OptionSet`.
41
41
42
42
```swift
43
43
structMyCommand: TopLevelCommandRepresentable {
44
44
funccommandValue() -> Command { "my-command" }
45
-
var flagFormatter: FlagFormatter { .doubleDashPrefix }
46
-
var optionFormatter: OptionFormatter { .doubleDashPrefix }
45
+
let flagFormatter=FlagFormatter(prefix: .doubleDash) }
46
+
let optionFormatter=OptionFormatter(prefix: .doubleDash) }
0 commit comments