Skip to content

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

  1. For each arg token in args, split the token on ParsePattern into up to 3 regex parts.
  2. 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").
  3. If the split yields 3 parts (key:value/key=value/-key value forms, depending on pattern): if the key isn't already present, add key → value.
  4. Standardize each key via StandardizeArgKey before insertion:
  5. PatternCommandLineParser's default upper-cases the key.
  6. SaifStandardCommandLineParser inherits this default unchanged, but fixes ParsePattern to ^-{1,2}|^/|:|=.
  7. 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.
  8. 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.

Note: Statements marked with ** could not be confirmed; treat as unknown until verified.

Sources

  • Console\SAIF.Console\Console\PatternCommandLineParser.cs
  • Console\SAIF.Console\Console\SaifStandardCommandLineParser.cs
  • Console\SAIF.Console\Console\ICommandLineParser.cs