in src/BinaryParsers/CommandLineHelper.cs [102:208]
public static SwitchState GetSwitchState(string commandLine, string[] switchNames, string[] overrideNames, SwitchState defaultState, OrderOfPrecedence precedence)
{
// TODO-paddymcd-MSFT - This is an OK first pass.
// Unfortunately composite switches get tricky and not all switches support the '-' semantics
// e.g. /O1- gets translated to /O1 /O-, the second of which is not supported.
// Additionally, currently /d2guardspecload is translated into /guardspecload, which may be a bug for ENC
SwitchState namedswitchesState = SwitchState.SwitchNotFound;
if (switchNames != null && switchNames.Length > 0)
{
// array of strings for the switch name without the preceding switchPrefix to make comparison easier
string[] switchArray = new string[switchNames.Length];
string[] overridesArray = null;
SwitchState namedoverridesState = SwitchState.SwitchNotFound;
for (int index = 0; index < switchNames.Length; index++)
{
// if present remove the slash or minus
switchArray[index] = switchNames[index].TrimStart(switchPrefix);
}
if (overrideNames != null && overrideNames.Length > 0)
{
overridesArray = new string[overrideNames.Length];
for (int index = 0; index < overrideNames.Length; index++)
{
// if present remove the slash or minus
overridesArray[index] = overrideNames[index].TrimStart(switchPrefix);
}
}
foreach (string arg in ArgumentSplitter.CommandLineToArgvW(commandLine))
{
if (IsCommandLineOption(arg))
{
string realArg = arg.TrimStart(switchPrefix);
// Check if this matches one of the names switches
for (int index = 0; index < switchArray.Length; index++)
{
if (realArg.StartsWith(switchArray[index]))
{
// partial stem match - now check if this is a full match or a match with a "-" on the end
if (realArg.Equals(switchArray[index]))
{
namedswitchesState = SwitchState.SwitchEnabled;
// not necessary at this time, but here for completeness...
namedoverridesState = SwitchState.SwitchDisabled;
}
else if (realArg[switchArray[index].Length] == '-')
{
namedswitchesState = SwitchState.SwitchDisabled;
}
// Else we have a stem match - do nothing
}
}
// check if this matches one of the named overrides
if (overridesArray != null)
{
for (int index = 0; index < overridesArray.Length; index++)
{
if (realArg.StartsWith(overridesArray[index]))
{
// partial stem match - now check if this is a full match or a match with a "-" on the end
if (realArg.Equals(overridesArray[index]))
{
namedoverridesState = SwitchState.SwitchEnabled;
namedswitchesState = SwitchState.SwitchDisabled;
}
else if (realArg[overridesArray[index].Length] == '-')
{
namedoverridesState = SwitchState.SwitchDisabled;
// Unsetting an override has no impact upon the named switches
}
// Else we have a stem match - do nothing
}
}
}
if (namedswitchesState != SwitchState.SwitchNotFound &&
namedoverridesState != SwitchState.SwitchNotFound &&
precedence == OrderOfPrecedence.FirstWins)
{
// we found a switch that impacts the desired state and FirstWins is set
break;
}
}
}
if (namedswitchesState == SwitchState.SwitchNotFound)
{
if (namedoverridesState == SwitchState.SwitchEnabled)
{
namedswitchesState = SwitchState.SwitchDisabled;
}
else
{
namedswitchesState = defaultState;
}
}
}
return namedswitchesState;
}