Command-line argument parsing and lookup¶
Downstream applications never parse Environment.GetCommandLineArgs themselves; Initialize() normalizes the raw array once during the console application execution lifecycle, and this operation's lookup methods let ValidateCommandLine() and RunAppLogic() query that normalized array by position or by named switch, and split a switch into its name and value at a colon.
| Field | Value |
|---|---|
| Operation ID | OP-CA-002 |
| Trigger | Downstream code (typically ValidateCommandLine() or RunAppLogic()) calls ParamExists, GetParamName, or GetParamValue, after Initialize() has normalized m_CmdLine |
| Inputs | The normalized command-line argument array (m_CmdLine); a requested switch name (String) or positional index (Integer) |
| Outputs | Boolean existence result (ParamExists); the resolved switch name or value (String, empty string when not found) |
| Primary components | clsConsoleBase.GetParamName, clsConsoleBase.GetParamValue, clsConsoleBase.ParamExists |
| Entry point | Presentation\SAIF.Presentation.ConsoleApplication\clsConsoleBase.vb |
Steps¶
- Prerequisite normalization (performed once, during
Initialize()). Each raw argument has a single leading/or-stripped, if present, and is upper-cased before storage inm_CmdLine(BR-002). This step is part of console application execution lifecycle and is not repeated here; every lookup below operates on the already-normalized array. - Check existence by index (
ParamExists(Integer)). ReturnsTrueonly if the index falls within0tom_CmdLine.Length - 1. - Check existence by name (
ParamExists(String)). Scansm_CmdLineand returnsTrueas soon as any stored argument starts with the upper-cased requested name (BR-005). - If no stored argument matches: returns
False. - Resolve a switch's name by index (
GetParamName(Integer)). - If
ParamExists(inNumber)isFalse: returns"". - Otherwise, if the stored argument contains a colon not immediately followed by a backslash: returns the substring before the colon (BR-004).
- Otherwise: returns the whole stored argument as the name.
- Resolve a switch's name by name (
GetParamName(String)). - If
ParamExists(inName)isFalse: returns"". - Otherwise, scans
m_CmdLinefor the first argument starting with the upper-cased name and applies the same colon/backslash split as step 4 (BR-004, BR-005). - Resolve a switch's value by name (
GetParamValue(String)). - If
ParamExists(inName)isFalse: returns"". - Otherwise, finds the first matching argument and, if it contains a colon not immediately followed by a backslash, returns the substring after the colon (BR-004, BR-005).
- If no colon-delimited value is present (or the colon is immediately followed by a backslash): returns
""— a value-only switch (e.g.,/DEBUG) has no separately retrievable value. - Resolve a switch's value by index (
GetParamValue(Integer)). Same colon/backslash split as step 6, applied to the argument at the given index (BR-004).
Process flow¶
The following diagram visualizes the name/value resolution path shared by GetParamName and GetParamValue.
flowchart TD
Start([Lookup requested: name or index]) --> Exists{ParamExists?}
Exists -->|No| Empty([Return empty string])
Exists -->|Yes| Find[Locate matching stored argument]
Find --> Colon{Colon present and<br>not followed by backslash?}
Colon -->|Yes, GetParamName| Before([Return substring before colon])
Colon -->|Yes, GetParamValue| After([Return substring after colon])
Colon -->|No| Whole([GetParamName: return whole argument<br>GetParamValue: return empty string])
Failure and edge-case behavior¶
- Name and value resolution both rely on prefix matching (
StartsWith), so a short requested name can match a longer stored argument that happens to share the same prefix, potentially resolving the wrong switch (BR-005). - A value that itself begins with a Windows drive-letter path (
C:\...) is preserved intact rather than split at its own colon, because the character immediately after the colon is checked for a backslash (BR-004). - A switch with no colon at all (e.g., a bare
/DEBUGflag) always yields an empty value fromGetParamValue; callers must useParamExiststo detect the flag itself. ParamExists(Integer)is a bounds check only — it does not inspect the argument's content — whileParamExists(String)inspects content but not position.
Related documentation¶
Sources¶
Presentation\SAIF.Presentation.ConsoleApplication\clsConsoleBase.vb