Skip to content

Commit ab818b2

Browse files
committed
getopt: Improve string and string[] documentation, add examples.
1 parent fa084df commit ab818b2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/watt/text/getopt.volt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ private fn getoptImpl(ref args: string[], description: string, dgt: scope dg (st
178178
* If there are multiple instances of the flag, `_string` will have the value of the last
179179
* instance.
180180
*
181+
* Example:
182+
* ```volt
183+
* args := ["--fruit", "apple", "--fruit", "banana", "--fruit", "pear"]
184+
* fruit: string;
185+
* getopt(ref args, "fruit", ref fruit);
186+
* assert(fruit == "pear");
187+
* ```
188+
*
181189
* @Param args The array of strings to remove applicable flags and arguments from.
182190
* @Param description The description of the flag -- see `getopt`'s module documentation for details.
183191
* @Param _string This argument will be filled with the last value parsed out of `args`.
@@ -194,7 +202,16 @@ fn getopt(ref args: string[], description: string, ref _string: string) bool
194202
* Parse a flag taking multiple string argument from an array of strings.
195203
*
196204
* If a flag (described in `description`, separated by | characters) shows up in `args`[1 .. $], an argument is parsed
197-
* and put into `strings`. Both the flag and argument are then removed from `args`.
205+
* and put into `strings`. Both the flag and argument are then removed from `args`. If there are multiple instances
206+
* of the flag, then `strings` will contain all given arguments, in the order they appeared.
207+
*
208+
* Example:
209+
* ```volt
210+
* args := ["--fruit", "apple", "--fruit", "banana", "--fruit", "pear"]
211+
* fruits: string[];
212+
* getopt(ref args, "fruit", ref fruit);
213+
* assert(fruits == ["apple", "banana", "pear"]);
214+
* ```
198215
*
199216
* @Param args The array of strings to remove applicable flags and arguments from.
200217
* @Param description The description of the flag -- see `getopt`'s module documentation for details.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy