Пример #1
0
 /// <summary>
 /// Adds the option to the command using only the aliases that are available, and only if the primary (first)
 /// alias is available. If a required option is not available, the command is disabled.
 /// </summary>
 /// <param name="command">The command to add the option to.</param>
 /// <param name="option">The option to add.</param>
 /// <typeparam name="T">The type of the option's argument.</typeparam>
 private void AddOptionIfAvailable <T>(Command command, OptionInfo <T> option)
 {
     if (IsAliasAvailable(option.Aliases.First()))
     {
         command.AddOption(option.Create(option.Aliases.Where(IsAliasAvailable)));
     }
     else if (option.Required)
     {
         command.AddValidator(commandResult =>
                              $"The required option {option.Aliases.First()} conflicts with an entry point parameter name.");
     }
 }
Пример #2
0
 /// <summary>
 /// Returns the default value and displays a warning if the primary (first) alias is shadowed by an entry point
 /// option, and returns the original value otherwise.
 /// </summary>
 /// <typeparam name="T">The type of the option values.</typeparam>
 /// <param name="option">The option.</param>
 /// <param name="value">The value of the option given on the command line.</param>
 /// <returns>The default value or the original value.</returns>
 private T DefaultIfShadowed <T>(OptionInfo <T> option, T value)
 {
     if (IsAliasAvailable(option.Aliases.First()))
     {
         return(value);
     }
     else
     {
         DisplayWithColor(ConsoleColor.Yellow, Console.Error,
                          $"Warning: Option {option.Aliases.First()} is overridden by an entry point parameter name. " +
                          $"Using default value {option.DefaultValue}.");
         return(option.DefaultValue);
     }
 }
Пример #3
0
 /// <summary>
 /// Creates a new driver for the entry point.
 /// </summary>
 /// <param name="entryPoint">The entry point.</param>
 public Driver(IEntryPoint <TIn, TOut> entryPoint)
 {
     this.entryPoint = entryPoint;
     SimulatorOption = new OptionInfo <string>(
         new[]
     {
         "--" + CommandLineArguments.SimulatorOption.Item1,
         "-" + CommandLineArguments.SimulatorOption.Item2
     },
         entryPoint.DefaultSimulator,
         "The name of the simulator to use.",
         suggestions: new[]
     {
         AssemblyConstants.QuantumSimulator,
         AssemblyConstants.ToffoliSimulator,
         AssemblyConstants.ResourcesEstimator,
         entryPoint.DefaultSimulator
     });
 }