コード例 #1
0
 public HelpCommand()
 {
     OptionalArguments.Add(new OptionalCommandArgument()
     {
         Name = "all", IsFlag = true
     });
     OptionalArguments.Add(new OptionalCommandArgument()
     {
         Name = "cmd"
     });
 }
コード例 #2
0
        /// <summary>
        /// Add an argument with the specified properties to the argument parser.
        /// </summary>
        /// <param name="name">Name of the argument. If this name starts with the "-" prefix then it will be an optional argument, else it will be a positional argument.</param>
        /// <param name="longName">Longer (not necessarily) name of an optional argument, an alias. It can be used for positional arguments, it would only change the key value in the namespace.</param>
        /// <param name="action">Action of an optional argument.</param>
        /// <param name="defaultValue">Default value of an optional argument if it is not supplied. Default value is `null` by default.</param>
        /// <param name="choices">A list of strings indicating the only selectable options for an argument. An error will be thrown if the provided values is not in the list of choices.</param>
        /// <param name="required">Determines is an optional argument is required to be supplied. Can be used for positional arguments too but it won't effect anything.</param>
        /// <param name="help">Help string to be printed in the help message for the argument. It is empty by default.</param>
        /// <param name="constant">Constant value for the argument. This parameter only works for arguments with `StoreConst` and `AppendConst` actions.</param>
        public void AddArgument(string name,
                                string longName       = null,
                                ArgumentAction action = ArgumentAction.Store,
                                object defaultValue   = null,
                                List <string> choices = null,
                                bool required         = false,
                                string help           = "",
                                object constant       = null)
        {
            if (name.Contains(" "))
            {
                throw new InvalidArgumentNameException("An argument name can't contain spaces.");
            }

            Argument arg = new Argument(name,
                                        longName: longName,
                                        action: action,
                                        defaultValue: defaultValue,
                                        choices: choices,
                                        required: required,
                                        help: help,
                                        constant: constant);

            arguments.Add(arg);

            if (arg.Name.IsOptionalArgument())
            {
                Categories[optionalArgsTitle].Add(arg);
                OptionalArguments.Add(arg);
            }
            else
            {
                Categories[positionalArgsTitle].Add(arg);
                PositionalArguments.Add(arg);
            }
        }