Command-line argument parsing¶
PatternCommandLineParser.Parse(string[] args) (used directly, or via its fixed-pattern subclass SaifStandardCommandLineParser) converts raw command-line tokens into a standardized Dictionary<string,string> that argument resolution then binds onto the argument container.
| Field | Value |
|---|---|
| Operation ID | OP-WIN-004 |
| Trigger | Called from ArgumentContainerBase<T>'s constructor via the container's CommandLineParser. |
| Inputs | Raw command-line string[] args; the parser's configured ParsePattern regex. |
| Outputs | Dictionary<string,string> of standardized-key → value pairs. |
| Primary components | PatternCommandLineParser.Parse, PatternCommandLineParser.StandardizeArgKey, SaifStandardCommandLineParser |
| Entry point | Console\SAIF.Console\Console\PatternCommandLineParser.cs |
Steps¶
- For each arg token in
args, split the token onParsePatterninto up to 3 regex parts. - If the split yields 2 parts (flag-only, e.g.
-verbose): if the key isn't already present in the result dictionary, add it with value"true"(BR-WIN-011: boolean/flag-style arguments default to string"true"). - If the split yields 3 parts (
key:value/key=value/-key valueforms, depending on pattern): if the key isn't already present, addkey → value. - Standardize each key via
StandardizeArgKeybefore insertion: PatternCommandLineParser's default upper-cases the key.SaifStandardCommandLineParserinherits this default unchanged, but fixesParsePatternto^-{1,2}|^/|:|=.- Duplicate keys (the same standardized key appearing twice in
args) are silently ignored — the first occurrence wins (BR-WIN-012); no exception is thrown and no error is recorded for the duplicate. - Return the completed dictionary to the calling argument container.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([Parse called with args]) --> Loop[For each token]
Loop --> Split[Split on ParsePattern]
Split --> Parts{Number of parts}
Parts -->|2 parts, flag only| KeyExists1{Key already present?}
Parts -->|3 parts, key/value| KeyExists2{Key already present?}
KeyExists1 -->|No| AddTrue(["Add key -> #quot;true#quot;"])
KeyExists1 -->|Yes| Skip1([Ignore duplicate])
KeyExists2 -->|No| AddValue([Add key -> value])
KeyExists2 -->|Yes| Skip2([Ignore duplicate])
AddTrue --> Standardize[StandardizeArgKey]
AddValue --> Standardize
Standardize --> Loop
Loop --> Done([Return dictionary])
Failure and edge-case behavior¶
- Tokens that split into a number of parts other than 2 or 3 are not documented as producing a dictionary entry; behavior for such tokens depends on the configured
ParsePattern.** - Because standardization defaults to upper-casing, argument keys are effectively case-insensitive at the point of lookup in argument resolution.
Related documentation¶
Note: Statements marked with
**could not be confirmed; treat as unknown until verified.
Sources¶
Console\SAIF.Console\Console\PatternCommandLineParser.csConsole\SAIF.Console\Console\SaifStandardCommandLineParser.csConsole\SAIF.Console\Console\ICommandLineParser.cs