/// <summary> /// Sets standard output options according to specified command line switches. /// </summary> /// <param name="silent"><see cref="CommandLineSwitch"/> that enables Silent option.\n /// Switch must have no parameters. If switch is found in parsed set of command line /// arguments, then Silent option is set to True. If switch is not found or object is null /// then Silent option will not change.</param> /// <param name="verbose"><see cref="CommandLineSwitch"/> that enables Verbose option.\n /// Switch must have no parameters. If switch is found in parsed set of command line /// arguments, then Verbose option is set to True. If switch is not found or object is null /// then Verbose option will not change.</param> public void SetupVerboseLevel(CommandLineSwitch silent, CommandLineSwitch verbose) { if (this.Arguments == null) { throw new InvalidOperationException("Command line arguments are not parsed yet."); } if (silent != null) { if (silent.ParametersCount != 0) { throw new ArgumentException("Switch for option 'silent' must have no " + "parameters."); } this.Silent = this.Arguments.GetArgument(silent).isSpecified; } if (verbose != null) { if (verbose.ParametersCount != 0) { throw new ArgumentException("Switch for option 'verbose' must have no " + "parameters."); } this.Verbose = !this.Silent && this.Arguments.GetArgument(verbose).isSpecified; } }
/// <summary> /// Sets output target for <see cref="StreamOutput"/> to specified file. /// </summary> /// <param name="output"><see cref="CommandLineSwitch"/> that sets output to specified /// file.\n Switch must have one parameter. If switch is found in parsed set of command line /// arguments, then output stream is set to specified file.</param> public void SetupOutput(CommandLineSwitch output) { if (this.Arguments == null) { throw new InvalidOperationException("Command line arguments are not parsed yet."); } if (output == null) { throw new ArgumentNullException(nameof(output)); } if (output.ParametersCount != 1) { throw new ArgumentException("Switch for option 'output' must have exactly " + "one parameter."); } var outputArgument = this.Arguments.GetArgument(output); if (outputArgument.isSpecified) { this.Output.SetToFile(outputArgument.parameters[0]); } }
/// <summary> /// Check that switch is incompatible with other switch. /// Two switches are considered incompatible if they share names or shortcuts. /// </summary> /// <param name="other">Switch to compare with current switch. Can't be null.</param> /// <returns>true, if switches are incompatible.</returns> public bool IsIncompatibleWith(CommandLineSwitch other) { return((!string.IsNullOrEmpty(this.Name) && this.Name == other.Name) || (this.Shortcut.HasValue && other.Shortcut.HasValue && this.Shortcut.Value == other.Shortcut.Value)); }