Skip to content

Commit 3d93ec1

Browse files
committed
Documentation update
1 parent 22547f1 commit 3d93ec1

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

J4JCommandLine.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FancyHelpError", "FancyHelp
1515
EndProject
1616
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{473DDAC4-C8B9-4FBC-97C9-51AB11F038EF}"
1717
ProjectSection(SolutionItems) = preProject
18+
docs\allocation.md = docs\allocation.md
1819
docs\allocator.md = docs\allocator.md
1920
docs\di.md = docs\di.md
2021
docs\diagrams.md = docs\diagrams.md

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Console.WriteLine( Unkeyed.Count == 0
5151
- [Goal and Concept](docs/goal-concept.md)
5252
- [Terminology](docs/terminology.md)
5353
- [Usage](docs/usage.md)
54+
- [How Command Lines Are Allocated](docs/allocation.md)
5455
- Examples
5556
- [Binding to static properties](docs/example-static.md)
5657
- [Binding to a configuration object](docs/example-instance.md)

docs/allocation.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
### Allocation
2+
3+
Allocation is what I call the first stage of parsing. It's where the various
4+
text values on the command line are allocated/assigned to collections
5+
keyed by option keys (and to one unkeyed collection). For details on how
6+
that works please refer to [this article](allocator.md).
7+
8+
This article focuses on what a command line could look like an be
9+
allocated, and then parsed, successfully. To do so it helps to distinguish
10+
between options -- what the framework refers to as keyed options -- and
11+
plain old command line parameters.
12+
13+
For a piece of text to be considered a (keyed) option it must be preceded by
14+
an **option key**, which is composed of two parts: an allowed prefix (e.g., -, --
15+
or /) and some text, terminated by a terminator character.
16+
17+
Spaces are always terminator characters unless they occur inside a piece of
18+
quoted text. So the space in `-x 1` terminates the option key while the
19+
second and third spaces in `-x "some quoted text"` are part of the text
20+
element's value and don't terminate anything.
21+
22+
Every option must be preceded by an option key. Conversely, any text element
23+
not preceded by an option key is considered merely a value to be assigned
24+
to either a keyed option collection or the overall unkeyed option collection.
25+
There's only one unkeyed option collection for each parsing action.
26+
27+
During the allocation phase all the parameters associated with the same
28+
option key are stored in the same collection. Multiple values do not need
29+
to be specified sequentially but each must be preceded by the same option
30+
key.
31+
32+
For example, the allocator converts `-x abc -y -x def` into two collections,
33+
one keyed by **x** containing two values *abc* and *def* and one keyed by
34+
**y** containing no values (**y** is presumably a switch option).
35+
36+
However, while the allocator converts `-x abc def -y` into the same two
37+
collections, the **x** collection in the second example *only* contains
38+
*abc*. The *def* parameter value is stored in the **unkeyed option collection**.
39+
That latter collection is where what are traditionally thought
40+
of as plain old command line parameters end up. They can be converted
41+
in the parsing phase to a collection of any type for which a text converter
42+
is defined.

0 commit comments

Comments
 (0)