/// <summary> /// Called when a switch that doesn't take parameters is detected on the command line. /// </summary> /// <param name="commandLineSwitches"></param> /// <param name="parameterlessSwitch"></param> /// <param name="switchParameters"></param> /// <param name="duplicateSwitchErrorMessage"></param> /// <param name="unquotedCommandLineArg"></param> private static void GatherParameterlessCommandLineSwitch ( CommandLineSwitches commandLineSwitches, CommandLineSwitches.ParameterlessSwitch parameterlessSwitch, string switchParameters, string duplicateSwitchErrorMessage, string unquotedCommandLineArg ) { // switch should not have any parameters if (switchParameters.Length == 0) { // check if switch is duplicated, and if that's allowed if (!commandLineSwitches.IsParameterlessSwitchSet(parameterlessSwitch) || (duplicateSwitchErrorMessage == null)) { commandLineSwitches.SetParameterlessSwitch(parameterlessSwitch, unquotedCommandLineArg); } else { commandLineSwitches.SetSwitchError(duplicateSwitchErrorMessage, unquotedCommandLineArg); } } else { commandLineSwitches.SetUnexpectedParametersError(unquotedCommandLineArg); } }
public void SetParameterlessSwitchTests() { CommandLineSwitches switches = new CommandLineSwitches(); switches.SetParameterlessSwitch(CommandLineSwitches.ParameterlessSwitch.NoLogo, "/nologo"); Assert.Equal("/nologo", switches.GetParameterlessSwitchCommandLineArg(CommandLineSwitches.ParameterlessSwitch.NoLogo)); Assert.True(switches.IsParameterlessSwitchSet(CommandLineSwitches.ParameterlessSwitch.NoLogo)); Assert.True(switches[CommandLineSwitches.ParameterlessSwitch.NoLogo]); // set it again switches.SetParameterlessSwitch(CommandLineSwitches.ParameterlessSwitch.NoLogo, "-NOLOGO"); Assert.Equal("-NOLOGO", switches.GetParameterlessSwitchCommandLineArg(CommandLineSwitches.ParameterlessSwitch.NoLogo)); Assert.True(switches.IsParameterlessSwitchSet(CommandLineSwitches.ParameterlessSwitch.NoLogo)); Assert.True(switches[CommandLineSwitches.ParameterlessSwitch.NoLogo]); // we didn't set this switch Assert.Null(switches.GetParameterlessSwitchCommandLineArg(CommandLineSwitches.ParameterlessSwitch.Version)); Assert.False(switches.IsParameterlessSwitchSet(CommandLineSwitches.ParameterlessSwitch.Version)); Assert.False(switches[CommandLineSwitches.ParameterlessSwitch.Version]); }
public void AppendParameterlessSwitchesTests() { CommandLineSwitches switchesLeft = new CommandLineSwitches(); switchesLeft.SetParameterlessSwitch(CommandLineSwitches.ParameterlessSwitch.Help, "/?"); Assert.True(switchesLeft.IsParameterlessSwitchSet(CommandLineSwitches.ParameterlessSwitch.Help)); Assert.False(switchesLeft.IsParameterlessSwitchSet(CommandLineSwitches.ParameterlessSwitch.NoConsoleLogger)); CommandLineSwitches switchesRight1 = new CommandLineSwitches(); switchesRight1.SetParameterlessSwitch(CommandLineSwitches.ParameterlessSwitch.NoConsoleLogger, "/noconlog"); Assert.False(switchesRight1.IsParameterlessSwitchSet(CommandLineSwitches.ParameterlessSwitch.Help)); Assert.True(switchesRight1.IsParameterlessSwitchSet(CommandLineSwitches.ParameterlessSwitch.NoConsoleLogger)); switchesLeft.Append(switchesRight1); Assert.Equal("/noconlog", switchesLeft.GetParameterlessSwitchCommandLineArg(CommandLineSwitches.ParameterlessSwitch.NoConsoleLogger)); Assert.True(switchesLeft.IsParameterlessSwitchSet(CommandLineSwitches.ParameterlessSwitch.NoConsoleLogger)); Assert.True(switchesLeft[CommandLineSwitches.ParameterlessSwitch.NoConsoleLogger]); // this switch is not affected Assert.Equal("/?", switchesLeft.GetParameterlessSwitchCommandLineArg(CommandLineSwitches.ParameterlessSwitch.Help)); Assert.True(switchesLeft.IsParameterlessSwitchSet(CommandLineSwitches.ParameterlessSwitch.Help)); Assert.True(switchesLeft[CommandLineSwitches.ParameterlessSwitch.Help]); CommandLineSwitches switchesRight2 = new CommandLineSwitches(); switchesRight2.SetParameterlessSwitch(CommandLineSwitches.ParameterlessSwitch.NoConsoleLogger, "/NOCONSOLELOGGER"); Assert.False(switchesRight2.IsParameterlessSwitchSet(CommandLineSwitches.ParameterlessSwitch.Help)); Assert.True(switchesRight2.IsParameterlessSwitchSet(CommandLineSwitches.ParameterlessSwitch.NoConsoleLogger)); switchesLeft.Append(switchesRight2); Assert.Equal("/NOCONSOLELOGGER", switchesLeft.GetParameterlessSwitchCommandLineArg(CommandLineSwitches.ParameterlessSwitch.NoConsoleLogger)); Assert.True(switchesLeft.IsParameterlessSwitchSet(CommandLineSwitches.ParameterlessSwitch.NoConsoleLogger)); Assert.True(switchesLeft[CommandLineSwitches.ParameterlessSwitch.NoConsoleLogger]); Assert.Equal("/?", switchesLeft.GetParameterlessSwitchCommandLineArg(CommandLineSwitches.ParameterlessSwitch.Help)); Assert.True(switchesLeft.IsParameterlessSwitchSet(CommandLineSwitches.ParameterlessSwitch.Help)); Assert.True(switchesLeft[CommandLineSwitches.ParameterlessSwitch.Help]); Assert.False(switchesLeft.HaveErrors()); }
public void TestHaveAnySwitchesBeenSet() { // Check if method works with parameterized switch CommandLineSwitches switches = new CommandLineSwitches(); Assert.False(switches.HaveAnySwitchesBeenSet()); switches.SetParameterizedSwitch(CommandLineSwitches.ParameterizedSwitch.Verbosity, "/v:q", "q", false, true); Assert.True(switches.HaveAnySwitchesBeenSet()); // Check if method works with parameterless switches switches = new CommandLineSwitches(); Assert.False(switches.HaveAnySwitchesBeenSet()); switches.SetParameterlessSwitch(CommandLineSwitches.ParameterlessSwitch.Help, "/?"); Assert.True(switches.HaveAnySwitchesBeenSet()); }