Skip to content

Commit fa5207b

Browse files
committed
feat(cli-args): allow sub-commands in grammar
1 parent cc32daf commit fa5207b

7 files changed

Lines changed: 163 additions & 56 deletions

File tree

Lines changed: 63 additions & 0 deletions
Loading

assets/cli-railroad/diagram/CmdIdentifier.svg

Lines changed: 9 additions & 9 deletions
Loading

assets/cli-railroad/diagram/Command.svg

Lines changed: 14 additions & 7 deletions
Loading

assets/cli-railroad/diagram/LongFlagOption.svg

Lines changed: 19 additions & 12 deletions
Loading

assets/cli-railroad/diagram/LongValueOption.svg

Lines changed: 25 additions & 18 deletions
Loading

assets/cli-railroad/index.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
![Command](diagram/Command.svg)
44

55
```
6-
Command ::= CmdIdentifier Option* Operand*
6+
Command ::= CmdIdentifier Option* ( Operand* | Command+ )
77
```
88

9+
referenced by:
10+
11+
- Command
12+
913
**CmdIdentifier:**
1014

1115
![CmdIdentifier](diagram/CmdIdentifier.svg)
1216

1317
```
1418
CmdIdentifier
15-
::= Alphanumeric*
19+
::= AlphanumericAnd*
1620
```
1721

1822
referenced by:
@@ -92,7 +96,7 @@ referenced by:
9296

9397
```
9498
LongFlagOption
95-
::= '--' Alphanumeric+
99+
::= '--' Alphanumeric AlphanumericAnd*
96100
```
97101

98102
referenced by:
@@ -105,7 +109,7 @@ referenced by:
105109

106110
```
107111
LongValueOption
108-
::= '--' Alphanumeric+ OptionValueDelimiter Value
112+
::= '--' Alphanumeric AlphanumericAnd* OptionValueDelimiter Value
109113
```
110114

111115
referenced by:
@@ -138,12 +142,26 @@ Alphanumeric
138142

139143
referenced by:
140144

141-
- CmdIdentifier
142145
- LongFlagOption
143146
- LongValueOption
144147
- ShortFlagOption
145148
- ShortValueOption
146149

150+
**AlphanumericAnd:**
151+
152+
![AlphanumericAnd](diagram/AlphanumericAnd.svg)
153+
154+
```
155+
AlphanumericAnd
156+
::= [0-9a-zA-Z_#x2D]
157+
```
158+
159+
referenced by:
160+
161+
- CmdIdentifier
162+
- LongFlagOption
163+
- LongValueOption
164+
147165
**Value:**
148166

149167
![Value](diagram/Value.svg)

cli-args.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ The POSIX standard is often cited when designing command line interfaces. Howeve
1515

1616
A command MAY accept sub-commands, options, and operands.
1717

18+
##### Note: This specification is available as a [formal grammar](#formal-grammar), or as a [railroad diagram](./assets/cli-railroad/index.md).
19+
1820
### Sub-commands
1921

2022
- A sub-command is a part of the command that acts as a command by itself. In other words, a sub-command is a recursive command.
@@ -65,23 +67,26 @@ A command MAY accept sub-commands, options, and operands.
6567

6668
## Formal Grammar
6769

68-
```grammar
70+
```C
6971
Command ::= CmdIdentifier
7072
Command ::= CmdIdentifier Operand*
7173
Command ::= CmdIdentifier Option* Operand*
72-
CmdIdentifier ::= Alphanumeric*
74+
Command ::= CmdIdentifier Command*
75+
Command ::= CmdIdentifier Option* Command*
76+
CmdIdentifier ::= AlphanumericAnd*
7377
Option ::= ShortOption | LongOption
7478
ShortOption ::= ShortFlagOption | ShortValueOption
7579
LongOption ::= LongFlagOption | LongValueOption
7680
ShortFlagOption ::= '-' Alphanumeric
7781
ShortValueOption ::= '-' Alphanumeric OptionValueDelimiter Value
78-
LongFlagOption ::= '--' Alphanumeric Alphanumeric*
79-
LongValueOption ::= '--' Alphanumeric Alphanumeric* OptionValueDelimiter Value
82+
LongFlagOption ::= '--' Alphanumeric AlphanumericAnd*
83+
LongValueOption ::= '--' Alphanumeric AlphanumericAnd* OptionValueDelimiter Value
8084
OptionValueDelimiter ::= Space | '='
8185
Alphanumeric ::= [0-9a-zA-Z]
86+
AlphanumericAnd ::= [0-9a-zA-Z-_]
8287
Value ::= Char* | '"' ( Char | Space )* '"'
8388
Char ::= ( UnicodeExceptDoubleQuotes | '\"' )
84-
Space ::= ( U+0020 )\*
89+
Space ::= ( U+0020 )*
8590
Operand ::= Value
8691
```
8792

0 commit comments

Comments
 (0)