/// <summary> /// Applies the specified context of the command line option to the specified command line options. /// </summary> /// <param name="options">The command line options to apply the command line option.</param> /// <param name="context">The context of the command line option to be applied.</param> public void Apply(CarnaRunnerCommandLineOptions options, CarnaRunnerCommandLineOptionContext context) { if (!CanApply(context)) { return; } ApplyOption(options, context); }
/// <summary> /// Applies the specified context of the command line option to the specified command line options. /// </summary> /// <param name="options">The command line options to apply the command line option.</param> /// <param name="context">The context of the command line option to be applied.</param> /// <exception cref="InvalidCommandLineOptionException"> /// Settings file defined by <paramref name="context"/> does not exist. /// </exception> protected override void ApplyOption(CarnaRunnerCommandLineOptions options, CarnaRunnerCommandLineOptionContext context) { if (!File.Exists(context.Value)) { throw new InvalidCommandLineOptionException($@"Settings file does not exist. File: {context.Value}"); } options.SettingsFilePath = context.Value; }
/// <summary> /// Applies the specified context of the command line option to the specified command line options. /// </summary> /// <param name="options">The command line options to apply the command line option.</param> /// <param name="context">The context of the command line option to be applied.</param> /// <exception cref="InvalidCommandLineOptionException"> /// Assembly file defined by <paramref name="context"/> does not exist. /// </exception> protected override void ApplyOption(CarnaRunnerCommandLineOptions options, CarnaRunnerCommandLineOptionContext context) { if (!File.Exists(context.Argument)) { throw new InvalidCommandLineOptionException($@"Assembly file does not exist. File: {context.Argument}"); } options.Assemblies.Add(context.Argument); }
void Ex04() { When("a context is created with the specified argument that starts with '/' and is separated by ':'", () => Context = CarnaRunnerCommandLineOptionContext.Of("/f:Test")); Then("the argument of the context should be the specified argument", () => Context.Argument == "/f:Test"); Then("the key of the context should be the first part separated the specified argument by ':'", () => Context.Key == "/f"); Then("the value of the context should be the second part separated the specified argument by ':'", () => Context.Value == "Test"); Then("the context should have a key", () => Context.HasKey); }
void Ex03() { When("a context is created with the specified argument that starts with '/' and is not separated by ':'", () => Context = CarnaRunnerCommandLineOptionContext.Of("/help")); Then("the argument of the context should be the specified argument", () => Context.Argument == "/help"); Then("the key of the context should be the specified argument", () => Context.Key == "/help"); Then("the value of the context should be null", () => Context.Value == null); Then("the context should have a key", () => Context.HasKey); }
void Ex02() { When("a context is created with the specified argument that does not start with '/'", () => Context = CarnaRunnerCommandLineOptionContext.Of("assembly")); Then("the argument of the context should be the specified argument", () => Context.Argument == "assembly"); Then("the key of the context should be null", () => Context.Key == null); Then("the value of the context should be null", () => Context.Value == null); Then("the context should not have a key", () => !Context.HasKey); }
void Ex01() { When("a context is created with the specified argument that is an empty", () => Context = CarnaRunnerCommandLineOptionContext.Of(string.Empty)); Then("the argument of the context should be empty", () => Context.Argument == string.Empty); Then("the key of the context should be null", () => Context.Key == null); Then("the value of the context should be null", () => Context.Value == null); Then("the context should not have a key", () => !Context.HasKey); }
/// <summary> /// Applies the specified context of the command line option to the specified command line options. /// </summary> /// <param name="options">The command line options to apply the command line option.</param> /// <param name="context">The context of the command line option to be applied.</param> protected override void ApplyOption(CarnaRunnerCommandLineOptions options, CarnaRunnerCommandLineOptionContext context) { options.CanPause = true; }
/// <summary> /// Applies the specified context of the command line option to the specified command line options. /// </summary> /// <param name="options">The command line options to apply the command line option.</param> /// <param name="context">The context of the command line option to be applied.</param> protected override void ApplyOption(CarnaRunnerCommandLineOptions options, CarnaRunnerCommandLineOptionContext context) { options.Filter = context.Value; }
/// <summary> /// Gets a value that indicates whether the specified context of the command line option can be applied. /// </summary> /// <param name="context">The context of the command line option to be applied.</param> /// <returns> /// <c>true</c> if the specified context of the command line option can be applied; /// otherwise, <c>false</c>. /// </returns> public virtual bool CanApply(CarnaRunnerCommandLineOptionContext context) => context.HasKey && Keys.Contains(context.Key !.ToLower());
/// <summary> /// Gets a value that indicates whether the specified context of the command line option can be applied /// as an assembly option. /// </summary> /// <param name="context">The context of the command line option to be applied.</param> /// <returns> /// <c>true</c> if the specified context of the command line option can be applied; /// otherwise, <c>false</c>. /// </returns> public override bool CanApply(CarnaRunnerCommandLineOptionContext context) => !context.HasKey && !string.IsNullOrEmpty(context.Argument);
/// <summary> /// Creates a new instance of the <see cref="CarnaRunnerCommandLineOptionContext"/> /// with the specified argument of the command line option. /// </summary> /// <param name="arg">The argument of the command line option.</param> /// <returns>The new instance of the <see cref="CarnaRunnerCommandLineOptionContext"/>.</returns> protected virtual CarnaRunnerCommandLineOptionContext CreateCarnaRunnerCommandLineOptionContext(string arg) => CarnaRunnerCommandLineOptionContext.Of(arg);