Skip to content

Commit cc640c3

Browse files
committed
Fix and extend documentation.
1 parent 27eaed6 commit cc640c3

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ let prelude = flags.string("p", "prelude",
8181
description: "Path to prelude file which gets executed after " +
8282
"loading all provided libraries.")
8383
let prompt = flags.string("r", "prompt",
84-
description: "String used as prompt in REPL.", value: AppInfo.prompt)
84+
description: "String used as prompt in REPL.", value: "> ")
8585
let quiet = flags.option("q", "quiet",
8686
description: "In quiet mode, optional messages are not printed.")
8787
let help = flags.option("h", "help",
8888
description: "Show description of usage and options of this tools.")
8989

9090
// Parse the command-line arguments and return error message if parsing fails
91-
if let failure = self.parsingFailure() {
91+
if let failure = flags.parsingFailure() {
9292
print(failure)
9393
exit(1)
9494
}
@@ -122,6 +122,40 @@ Command-line tools can inspect whether a flag was set via the `Flag.wasSet` fiel
122122
parameters, the parameters are stored in the `Flag.value` field. The type of this field is dependent on the
123123
flag type. For repeated flags, an array is used.
124124

125+
Here is an example how the flags defined by the code snippet above could be used:
126+
127+
```swift
128+
// If help flag was provided, print usage description and exit tool
129+
if help.wasSet {
130+
print(flags.usageDescription(usageName: TextStyle.bold.properties.apply(to: "usage:"),
131+
synopsis: "[<option> ...] [---] [<program> <arg> ...]",
132+
usageStyle: TextProperties.none,
133+
optionsName: TextStyle.bold.properties.apply(to: "options:"),
134+
flagStyle: TextStyle.italic.properties),
135+
terminator: "")
136+
exit(0)
137+
}
138+
...
139+
// Define how optional messages and errors are printed
140+
func printOpt(_ message: String) {
141+
if !quiet.wasSet {
142+
print(message)
143+
}
144+
}
145+
...
146+
// Set heap size (assuming 1234 is the default if the flag is not set)
147+
virtualMachine.setHeapSize(heapSize.value ?? 1234)
148+
...
149+
// Register all file paths
150+
for path in filePaths.value {
151+
virtualMachine.fileHandler.register(path)
152+
}
153+
...
154+
// Load prelude file if it was provided via flag `prelude`
155+
if let file = prelude.value {
156+
virtualMachine.load(file)
157+
}
158+
```
125159

126160
## Text style and colors
127161

0 commit comments

Comments
 (0)