Skip to content

Commit 8e4d718

Browse files
author
José Valim
committed
Provide a quick introduction to OptionParser in mdocs
1 parent 3ad9193 commit 8e4d718

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

lib/elixir/lib/option_parser.ex

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
defmodule OptionParser do
22
@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.
421
"""
522

623
@type argv :: [String.t()]
@@ -65,10 +82,9 @@ defmodule OptionParser do
6582
* `:switches` - defines some switches and their types. This function
6683
still attempts to parse switches that are not in this list.
6784
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).
7288
7389
Note that you should only supply the `:switches` or the `:strict` option.
7490
If you supply both, an `ArgumentError` exception will be raised.

0 commit comments

Comments
 (0)