public ReplCommandBuilder WithFlag(string name, Action <ReplCommandFlagParameterBuilder>?config = null) { var parameterBuilder = new ReplCommandFlagParameterBuilder().WithName(name); config?.Invoke(parameterBuilder); this.parameters.Add(parameterBuilder); return(this); }
private static void BuildFlagParameter( ReplBuilder builder, ReplCommandBuilder commandBuilder, ParameterInfo parameter, ReplFlagAttribute replFlag, ReplCommandFlagParameterBuilder paramBuilder) { if (parameter.ParameterType != typeof(bool)) { ConsoleEx.WriteLine(ConsoleColor.Red, $"Flag `{commandBuilder.Names.First()} {AsOptionName(parameter.Name)}` cannot have a type other than `bool`, but found with type `{parameter.ParameterType.Name}`"); } paramBuilder .WithCaption(replFlag.Caption) .WithDescription(replFlag.Caption); foreach (var replExample in parameter.GetCustomAttributes <ReplExampleAttribute>()) { paramBuilder.WithExample(replExample.Command, exampleBuilder => { exampleBuilder .WithCaption(exampleBuilder.caption) .WithDescription(exampleBuilder.description); }); if (replExample.Scope >= ReplExampleScope.Parent) { commandBuilder.WithExample(replExample.Command, exampleBuilder => { exampleBuilder .WithCaption(exampleBuilder.caption) .WithDescription(exampleBuilder.description); }); } if (replExample.Scope >= ReplExampleScope.All) { builder.WithExample(replExample.Command, exampleBuilder => { exampleBuilder .WithCaption(exampleBuilder.caption) .WithDescription(exampleBuilder.description); }); } } }