/// <summary>
        /// Adds --help option, if there isn't already a help flag set.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="template">The help template. Defaults to <c>--help</c>.</param>
        /// <returns>The builder.</returns>
        public static IConventionBuilder UseDefaultHelpOption(this IConventionBuilder builder, string template = DefaultHelpOptionConvention.DefaultHelpTemplate)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.AddConvention(new DefaultHelpOptionConvention(template)));
        }
        /// <summary>
        /// Applies a collection of default conventions, such as applying options in attributes
        /// on the model type,
        /// </summary>
        /// <returns>The builder.</returns>
        public static IConventionBuilder UseAttributes(this IConventionBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder
                   .AddConvention(new AttributeConvention())
                   .UseCommandAttribute()
                   .UseVersionOptionFromMemberAttribute()
                   .UseVersionOptionAttribute()
                   .UseHelpOptionAttribute()
                   .UseOptionAttributes()
                   .UseArgumentAttributes()
                   .UseSubcommandAttributes());
        }
 /// <summary>
 /// Enables using constructor injection to initialize the model type.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="additionalServices">Additional services that should be passed to the service provider.</param>
 public static IConventionBuilder UseConstructorInjection(this IConventionBuilder builder, IServiceProvider additionalServices)
 => builder.AddConvention(new ConstructorInjectionConvention(additionalServices));
 /// <summary>
 /// Sets a method named "OnExecute" or "OnExecuteAsync" on the model type to handle
 /// <see cref="CommandLineApplication.Invoke" />
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The builder.</returns>
 public static IConventionBuilder UseOnExecuteMethodFromModel(this IConventionBuilder builder)
 => builder.AddConvention(new ExecuteMethodConvention());
 /// <summary>
 /// Enables using constructor injection to initialize the model type.
 /// </summary>
 /// <param name="builder"></param>
 public static IConventionBuilder UseConstructorInjection(this IConventionBuilder builder)
 => builder.AddConvention(new ConstructorInjectionConvention());
 public static IConventionBuilder UsePagerForHelpText(this IConventionBuilder builder, bool usePager = true)
 {
     builder.AddConvention(new UsePagerForHelpTextConvention(usePager));
     return(builder);
 }
 /// <summary>
 /// Invokes a method named "OnValidationError" on the model type when validation fails.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The builder.</returns>
 public static IConventionBuilder UseOnValidationErrorMethodFromModel(this IConventionBuilder builder)
 => builder.AddConvention(new ValidationErrorMethodConvention());
 /// <summary>
 /// Applies settings from <see cref="OptionAttribute" /> on the model type.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The builder.</returns>
 public static IConventionBuilder UseOptionAttributes(this IConventionBuilder builder)
 => builder.AddConvention(new OptionAttributeConvention());
 /// <summary>
 /// Applies settings from <see cref="ArgumentAttribute" /> on the model type.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The builder.</returns>
 public static IConventionBuilder UseArgumentAttributes(this IConventionBuilder builder)
 => builder.AddConvention(new ArgumentAttributeConvention());
 /// <summary>
 /// Sets <see cref="CommandLineApplication.Name" /> to match the name of
 /// <see cref="System.Reflection.Assembly.GetEntryAssembly" />
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The builder.</returns>
 public static IConventionBuilder SetAppNameFromEntryAssembly(this IConventionBuilder builder)
 => builder.AddConvention(new AppNameFromEntryAssemblyConvention());
 /// <summary>
 /// Applies settings from <see cref="VersionOptionAttribute" /> on the model type.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The builder.</returns>
 public static IConventionBuilder UseVersionOptionAttribute(this IConventionBuilder builder)
 => builder.AddConvention(new VersionOptionAttributeConvention());
 /// <summary>
 /// Sets a property named "Parent" on the model type to the value
 /// of the model of the parent command.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The builder.</returns>
 public static IConventionBuilder SetParentPropertyOnModel(this IConventionBuilder builder)
 => builder.AddConvention(new ParentPropertyConvention());
Example #13
0
 /// <summary>
 /// Sets the subcommand name using the model type, if available and not otherwise set using <see cref="CommandAttribute"/>.
 /// </summary>
 /// <param name="builder"></param>
 /// <returns></returns>
 public static IConventionBuilder UseCommandNameFromModelType(this IConventionBuilder builder)
 => builder.AddConvention(new CommandNameFromTypeConvention());
 /// <summary>
 /// Enables setting properties on a command model from <see cref="CommandOption"/>s.
 /// </summary>
 /// <param name="builder">The convention builder.</param>
 /// <param name="propertySuffix">The naming suffix for candidate properties that should have option values mapped to them.</param>
 /// <param name="nestedPropertySuffix">The naming suffix to use for properties of a complex type (non-primitive) that option values should be mapped to.</param>
 public static IConventionBuilder UseOptionProperties(this IConventionBuilder builder, string propertySuffix = "", string nestedPropertySuffix = "Options") =>
 builder.AddConvention(new OptionPropertiesConvention
 {
     NestedPropertySuffix = nestedPropertySuffix,
     PropertySuffix       = propertySuffix
 });
 /// <summary>
 /// Sets a property named "RemainingArgs" or "RemainingArguments" on the model type to the value
 /// of <see cref="CommandLineApplication.RemainingArguments" />.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The builder.</returns>
 public static IConventionBuilder SetRemainingArgsPropertyOnModel(this IConventionBuilder builder)
 => builder.AddConvention(new RemainingArgsPropertyConvention());
 /// <summary>
 /// Adds subcommands for each <see cref="SubcommandAttribute" /> on the model type.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The builder.</returns>
 public static IConventionBuilder UseSubcommandAttributes(this IConventionBuilder builder)
 => builder.AddConvention(new SubcommandAttributeConvention());
 /// <summary>
 /// Sets a property named "Subcommand" on the model type to the value
 /// of the model of the selected subcommand.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The builder.</returns>
 public static IConventionBuilder SetSubcommandPropertyOnModel(this IConventionBuilder builder)
 => builder.AddConvention(new SubcommandPropertyConvention());
 public static IConventionBuilder MakeSuggestionsInErrorMessage(this IConventionBuilder builder,
                                                                bool makeSuggestions = true)
 {
     builder.AddConvention(new MakeSuggestionsInErrorMessageConvention(makeSuggestions));
     return(builder);
 }