public static string GetRequiredness(ArgumentRequired r)
 {
     return(r switch
     {
         ArgumentRequired.Required => "Required. ",
         ArgumentRequired.Optional => "Optional. ",
         ArgumentRequired.HasDependencies => "Sometimes required. ",
         _ => "",
     });
Exemplo n.º 2
0
 internal Value(string descriptiveName, string helpText, ArgumentRequired argumentRequired, Action <TClass, TProp> propertySetter,
                TProp defaultValue, Dependencies <TClass>?dependencies, Func <string, Converted <TProp, string> > converter)
 {
     DescriptiveName  = descriptiveName;
     HelpText         = helpText;
     ArgumentRequired = argumentRequired;
     PropertySetter   = propertySetter;
     DefaultValue     = defaultValue;
     Dependencies     = dependencies;
     Converter        = converter;
 }
Exemplo n.º 3
0
 public MultiValue(string descriptiveName, string helpText, ArgumentRequired argumentRequired, Action <TClass, TPropCollection> propertySetter, TPropCollection defaultValues,
                   Dependencies <TClass>?dependencies, Func <string, Converted <TProp, string> > converter, Func <IEnumerable <TProp>, TPropCollection> createCollection)
 {
     DescriptiveName  = descriptiveName;
     HelpText         = helpText;
     ArgumentRequired = argumentRequired;
     PropertySetter   = propertySetter;
     DefaultValues    = defaultValues;
     Dependencies     = dependencies;
     Converter        = converter;
     CreateCollection = createCollection;
 }
Exemplo n.º 4
0
 internal Switch(string?shortName, string?longName, string descriptiveName, string helpText, ArgumentRequired argumentRequired, Action <TClass, TProp> propertySetter,
                 TProp defaultValue, Dependencies <TClass>?dependencies, Func <bool, Converted <TProp, string> > converter)
 {
     ShortName        = shortName;
     LongName         = longName;
     DescriptiveName  = descriptiveName;
     HelpText         = helpText;
     ArgumentRequired = argumentRequired;
     PropertySetter   = propertySetter;
     DefaultValue     = defaultValue;
     Dependencies     = dependencies;
     Converter        = converter;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a new Value.
        /// This is mainly useful to provide custom extension methods which take specific types of <typeparamref name="TProp"/>.
        /// </summary>
        /// <typeparam name="TProp">The type of the target property.</typeparam>
        /// <param name="expression">The property to set.</param>
        /// <param name="config">The configuration.</param>
        /// <returns>The created Value.</returns>
        public Value <TClass, TProp> AddValueCore <TProp>(Expression <Func <TClass, TProp> > expression, NamelessArgConfig <TClass, TProp> config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config), nameof(config) + " cannot be null");
            }
            Action <TClass, TProp> setter = CliParserBuilder.GetSetMethodDelegateFromExpression(expression, out PropertyInfo pi);

            if (config.Converter == null)
            {
                throw new CliParserBuilderException(string.Concat("You need to provide a converter for the property ", pi.Name, " of the class ", typeof(TClass).Name));
            }
            config.configuredDependencies?.Validate();
            ArgumentRequired      ar    = config.configuredDependencies != null ? ArgumentRequired.HasDependencies : config.Required ? ArgumentRequired.Required : ArgumentRequired.Optional;
            Value <TClass, TProp> thing = new(config.DescriptiveName ?? pi.Name, config.HelpText ?? "No help available.", ar, setter, config.DefaultValue, config.configuredDependencies, config.Converter);

            allValues.Add(thing);
            return(thing);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adds a new Switch.
        /// This is mainly useful to provide custom extension methods which take specific types of <typeparamref name="TProp"/>.
        /// </summary>
        /// <typeparam name="TProp">The type of the target property.</typeparam>
        /// <param name="expression">The property to set.</param>
        /// <param name="config">The configuration.</param>
        /// <returns>The created Switch.</returns>
        public Switch <TClass, TProp> AddSwitchCore <TProp>(Expression <Func <TClass, TProp> > expression, NamedArgConfig <TClass, TProp, bool> config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config), nameof(config) + " cannot be null");
            }
            Action <TClass, TProp> setter = CliParserBuilder.GetSetMethodDelegateFromExpression(expression, out PropertyInfo pi);

            if (config.Converter == null)
            {
                throw new CliParserBuilderException(string.Concat("You need to provide a converter for the property ", pi.Name, " of the class ", typeof(TClass).Name));
            }
            config.configuredDependencies?.Validate();
            string?shortName = config.ShortName;
            string?longName  = config.LongName;

            ApplyDefaultPrefixAndCheck(ref shortName, ref longName, "switch");
            ArgumentRequired       ar  = config.configuredDependencies != null ? ArgumentRequired.HasDependencies : config.Required ? ArgumentRequired.Required : ArgumentRequired.Optional;
            Switch <TClass, TProp> arg = new(shortName, longName, config.DescriptiveName ?? pi.Name, config.HelpText ?? "No help available.", ar, setter, config.DefaultValue, config.configuredDependencies, config.Converter);

            AddToDictionary(arg.ShortName, arg.LongName, arg, allSwitchesByName);
            allSwitches.Add(arg);
            return(arg);
        }