|
1 | 1 | defmodule OptionParser do |
2 | 2 | @moduledoc """ |
3 | | - This module contains functions to parse command line options. |
| 3 | + Functions for parsing command line options. |
| 4 | +
|
| 5 | + The main function in this module is `parse/2`, which allows |
| 6 | + developers to parse a list of arguments into options: |
| 7 | +
|
| 8 | + iex> OptionParser.parse(["--debug"], strict: [debug: :boolean]) |
| 9 | + {[debug: true], [], []} |
| 10 | +
|
| 11 | + `OptionParser` provides some conveniences out of the box, |
| 12 | + such as aliases and automatic handling of negation switches. |
| 13 | +
|
| 14 | + The `parse_head/2` function is an alternative to `parse/2` |
| 15 | + which stops parsing as soon as it finds a value that is not |
| 16 | + a switch nor a value for a previous switch. |
| 17 | +
|
| 18 | + This module also provides low-level functions, such as `next/2`, |
| 19 | + for parsing switches manually, as well as `split/1` and `to_argv/1` |
| 20 | + for parsing from and converting switches to strings. |
4 | 21 | """ |
5 | 22 |
|
6 | 23 | @type argv :: [String.t()] |
@@ -65,10 +82,9 @@ defmodule OptionParser do |
65 | 82 | * `:switches` - defines some switches and their types. This function |
66 | 83 | still attempts to parse switches that are not in this list. |
67 | 84 |
|
68 | | - Both these options accept a keyword list of `{name, type}` tuples where `name` |
69 | | - is an atom defining the name of the switch and `type` is an atom that |
70 | | - specifies the type for the value of this switch (see the "Types" section below |
71 | | - for the possible types and more information about type casting). |
| 85 | + Both these options accept a keyword list where the key is an atom |
| 86 | + defining the name of the switch and value is the `type` of the |
| 87 | + switch (see the "Types" section below for more information). |
72 | 88 |
|
73 | 89 | Note that you should only supply the `:switches` or the `:strict` option. |
74 | 90 | If you supply both, an `ArgumentError` exception will be raised. |
|
0 commit comments