Exemplo n.º 1
0
        /// <summary>
        /// create main parser
        /// </summary>
        /// <param name="description">program description</param>
        /// <param name="builder">action to configure and run the parser</param>
        /// <param name="colors">custom color object or null to disable</param>
        /// <param name="unescapeArguments">true to unescape arguments ( eg. newlines in argument strings )</param>
        public static CmdlineParser Create(string description, Action <CmdlineParser> builder, CmdlineColors colors, bool unescapeArguments)
        {
            var parser = new CmdlineParser(null, description, unescapeArguments);

            parser._Colors = colors;

            builder(parser);

            return(parser);
        }
Exemplo n.º 2
0
 /// <summary>
 /// associate this item to given parser and argument
 /// </summary>
 internal void Match(CmdlineParser parser, CmdlineArgument arg)
 {
     if (IsCommand)
     {
         parser.Command = this;
     }
     arg.MatchedItem    = this;
     this.MatchParser   = parser;
     this.Matches       = true;
     this.MatchArgument = arg;
 }
Exemplo n.º 3
0
 /// <summary>
 /// construct a parse item
 /// </summary>
 /// <param name="parser">parser owner</param>
 /// <param name="type">type of parse item</param>
 /// <param name="shortName">short name (command,flag,parameter)</param>
 /// <param name="longName">long name (flag)</param>
 /// <param name="valueName">value name (flag with val)</param>
 /// <param name="description">description (any item)</param>
 /// <param name="mandatory">if true and not matches a message will reported</param>
 /// <param name="globalFlagAction">if non null sets this flag as a global that can matched independently that command and other mandatory items</param>
 /// <param name="globalFlagActionNested">if false global flag action will executed immeditaly; if true execution will deferred to nested parser</param>
 internal CmdlineParseItem(CmdlineParser parser, CmdlineParseItemType type,
                           string shortName, string longName, string valueName, string description, bool mandatory, Action <CmdlineParseItem> globalFlagAction, bool globalFlagActionNested = true)
 {
     Parser                 = parser;
     Type                   = type;
     ShortName              = shortName;
     LongName               = longName;
     ValueName              = valueName;
     Description            = description;
     Mandatory              = mandatory;
     GlobalFlagAction       = globalFlagAction;
     GlobalFlagActionNested = globalFlagActionNested;
 }
Exemplo n.º 4
0
        /// <summary>
        /// add a command item to this parser
        /// </summary>
        /// <param name="name">name of the command</param>
        /// <param name="description">description of the command ( for the usage )</param>
        /// <param name="builder">an optional builder to create a subparser from this command</param>
        public CmdlineParseItem AddCommand(string name, string description, Action <CmdlineParser> builder = null)
        {
            var parser = new CmdlineParser(this, null, unescapeArguments);

            var cmd = new CmdlineParseItem(parser, CmdlineParseItemType.command,
                                           name, null, null, description, mandatory: false, globalFlagAction: null);

            parser.Command = cmd;

            items.Add(cmd);

            if (builder != null)
            {
                builder(parser);
            }

            return(cmd);
        }
Exemplo n.º 5
0
 CmdlineParser(CmdlineParser parent, string description, bool unescapeArguments)
 {
     Parent                 = parent;
     _Description           = description;
     this.unescapeArguments = unescapeArguments;
 }
Exemplo n.º 6
0
 /// <summary>
 /// construct a cmdline usage associated to given parser
 /// </summary>
 public CmdlineUsage(CmdlineParser parser)
 {
     Parser = parser;
 }