@@ -50,7 +50,7 @@ The standard CLI has two distinct option layers:
5050
5151### Global Options
5252
53- Global options affect the overall execution environment before the command is known .
53+ Global options affect the overall execution environment for the whole command run .
5454
5555Examples:
5656
@@ -61,7 +61,9 @@ Examples:
6161- quiet / verbose behavior
6262- global help / version handling
6363
64- Global options are parsed by ` GlobalOptions.parse(String[] args) ` .
64+ Global options are parsed by ` GlobalOptions.parse(String[] args) ` . Execution modifiers may appear either before or
65+ after the command token. Top-level mode selectors are pre-command only, except for command-help handling described
66+ below.
6567
6668### Command-Local Options
6769
@@ -77,28 +79,28 @@ Command-local options are parsed by `CommandDefinition.parseArgs(String[] args)`
7779
7880### Layer Boundary
7981
80- - global options configure how the CLI run is executed
82+ - global execution modifiers configure how the CLI run is executed
83+ - top-level mode selectors choose an alternate program mode before command execution
8184- command-local options configure what the chosen command does
82- - global parsing happens first
85+ - global parsing happens first and extracts known global options from the full argument list
8386- command-local parsing happens only after the command token is known
8487- a token must not be interpreted as both a global option and a command-local option in the same pass
8588
8689## Contract 1: Global Option Parsing
8790
88- ` GlobalOptions.parse(String[] args) ` is responsible only for parsing options that affect the whole run before
89- the command is known.
91+ ` GlobalOptions.parse(String[] args) ` is responsible only for parsing known options that affect the whole run.
9092
9193### Parsing Model
9294
93- Global option parsing is a left-to-right first-pass scan.
95+ Global option parsing is a left-to-right first-pass scan across the full argument list .
9496
9597The parser consumes tokens until one of these happens:
9698
97- 1 . it reaches the first command token
98- 2 . it reaches the end of input
99- 3 . it encounters a malformed global option and fails with a usage error
99+ 1 . it reaches the end of input
100+ 2 . it encounters a malformed known global option and fails with a usage error
100101
101- This pass is intentionally narrow. It must not inspect or reinterpret command-local options.
102+ This pass is intentionally narrow. It extracts only known global options and must not reinterpret unknown
103+ post-command options that belong to command-local parsing.
102104
103105### Supported Syntax
104106
@@ -126,11 +128,15 @@ For Contract 1, this applies to valued global options only.
126128
127129### Boundary Rules
128130
129- - Global options are only recognized before the command token.
131+ - Execution modifier global options are recognized before and after the command token.
132+ - Top-level mode selectors ` --version ` and ` --interactive ` are recognized only before the command token.
130133- The first token before command resolution that does not begin with ` - ` is the command token.
131134- The command token is normalized to lowercase for registry lookup.
132- - After the command token is found, all remaining tokens are passed through unchanged as command arguments.
133- - Tokens after the command token are never reinterpreted as global options, even if they look like global flags.
135+ - After the command token is found, execution modifier global options are extracted and all other tokens are passed
136+ through unchanged as command arguments.
137+ - Unknown options after the command token are never reinterpreted as global options.
138+ - Post-command ` --help ` and ` -h ` are reserved for command help and are passed through as command arguments.
139+ - Post-command ` --version ` and ` --interactive ` are command-local tokens and are passed through as command arguments.
134140
135141Examples:
136142
@@ -143,13 +149,29 @@ Examples:
143149 - command: ` get-balance `
144150 - command args: ` --address T... `
145151- ` wallet-cli get-balance --network nile `
152+ - global options: ` --network nile `
146153 - command: ` get-balance `
147- - command args: ` --network nile `
148- - ` --network ` is not treated as a global option because it appears after the command token
154+ - command args: none
149155- ` wallet-cli get-balance --network=nile `
156+ - global options: ` --network=nile `
150157 - command: ` get-balance `
151- - command args: ` --network=nile `
152- - ` --network=nile ` is not treated as a global option because it appears after the command token
158+ - command args: none
159+ - ` wallet-cli get-balance --address T... --network nile `
160+ - global options: ` --network nile `
161+ - command: ` get-balance `
162+ - command args: ` --address T... `
163+ - ` wallet-cli get-balance --help `
164+ - command: ` get-balance `
165+ - command args: ` --help `
166+ - ` --help ` is not treated as global help because it appears after the command token
167+ - ` wallet-cli get-balance --version `
168+ - command: ` get-balance `
169+ - command args: ` --version `
170+ - ` --version ` is not treated as global version because it appears after the command token
171+ - ` wallet-cli get-balance --interactive `
172+ - command: ` get-balance `
173+ - command args: ` --interactive `
174+ - ` --interactive ` is not treated as global interactive mode because it appears after the command token
153175
154176### No-Command Cases
155177
@@ -196,7 +218,7 @@ The following are usage errors at the global parsing layer:
196218- unknown global option before the command token
197219- missing value for a valued global option
198220- invalid value for a constrained global option
199- - malformed global syntax before the command token
221+ - malformed syntax for a known global option
200222
201223Specific expectations:
202224
@@ -216,6 +238,10 @@ Specific expectations:
216238 - usage error: missing or empty value for ` --output `
217239- ` --quiet=true `
218240 - usage error: option ` --quiet ` does not take a value
241+ - ` get-balance --network beta `
242+ - usage error: invalid value for ` --network `
243+ - ` get-balance --unknown value `
244+ - not a global parsing error; ` --unknown value ` remains command-local input
219245
220246Error classification for valued global options:
221247
0 commit comments