コード例 #1
0
        public static string GetOptionHelpGroup(OptionTable opts,
                                                OptionSpecifier id)
        {
            var groupId = opts.GetOptionGroupId(id);

            // If not in a group, return the default help group.
            if (groupId == 0)
            {
                return("OPTIONS");
            }

            // Abuse the help text of the option groups to store the "help group"
            // name.
            //
            // FIXME: Split out option groups.
            var groupHelp = opts.GetOptionHelpText(groupId);

            if (!string.IsNullOrEmpty(groupHelp))
            {
                return(groupHelp);
            }

            // Otherwise keep looking.
            return(GetOptionHelpGroup(opts,
                                      groupId));
        }
コード例 #2
0
ファイル: Option.cs プロジェクト: trmcnealy/System.Option
        public Option(OptionInfo info,
                      OptionTable owner)
        {
            Info  = info;
            Owner = owner;

            // Multi-level aliases are not supported. This just simplifies option
            // tracking, it is not an inherent limitation.
            Contract.Assert((Info == null || !GetAlias().IsValid() || !GetAlias().GetAlias().IsValid()),
                            "Multi-level aliases are not supported.");

            if (Info != null &&
                GetAliasArgs() != null)
            {
                Contract.Assert(GetAlias().IsValid(),
                                "Only alias options can have alias args.");
                Contract.Assert(GetKind() == OptionKind.FlagClass,
                                "Only Flag aliases can have alias args.");
                Contract.Assert(GetAlias().GetKind() != OptionKind.FlagClass,
                                "Cannot provide alias args to a flag option.");
            }
        }
コード例 #3
0
        public static string GetOptionHelpName(OptionTable opts,
                                               OptionSpecifier id)
        {
            var    o    = opts.GetOption(id);
            var    name = o.GetPrefixedName();
            string metaVarName;

            // Add metavar, if used.

            var kind = o.GetKind();

            if (kind == OptionKind.GroupClass ||
                kind == OptionKind.InputClass ||
                kind == OptionKind.UnknownClass)
            {
                throw new Exception("Invalid option with help text.");
            }

            if (kind == OptionKind.MultiArgClass)
            {
                metaVarName = opts.GetOptionMetaVar(id);
                if (!string.IsNullOrEmpty(metaVarName))
                {
                    // For MultiArgs, metavar is full list of all argument names.
                    name += ' ';
                    name += metaVarName;
                }
                else
                {
                    // For MultiArgs<N>, if metavar not supplied, print <value> N times.
                    for (int i = 0, e = o.GetNumArgs(); i < e; ++i)
                    {
                        name += " <value>";
                    }
                }
            }
            else if (kind == OptionKind.FlagClass)
            {
            }
            else if (kind == OptionKind.ValuesClass)
            {
            }
            else if (kind == OptionKind.SeparateClass ||
                     kind == OptionKind.JoinedOrSeparateClass ||
                     kind == OptionKind.RemainingArgsClass ||
                     kind == OptionKind.RemainingArgsJoinedClass)
            {
                name       += ' ';
                metaVarName = opts.GetOptionMetaVar(id);
                if (!string.IsNullOrEmpty(metaVarName))
                {
                    name += metaVarName;
                }
                else
                {
                    name += "<value>";
                }
            }
            else if (kind == OptionKind.JoinedClass ||
                     kind == OptionKind.CommaJoinedClass ||
                     kind == OptionKind.JoinedAndSeparateClass)
            {
                metaVarName = opts.GetOptionMetaVar(id);
                if (!string.IsNullOrEmpty(metaVarName))
                {
                    name += metaVarName;
                }
                else
                {
                    name += "<value>";
                }
            }

            return(name);
        }
コード例 #4
0
        public static ushort GetOptionAlias(this OptionTable optionTable, ushort optId)
        {
            var alias = optionTable._optionInfos.FirstOrDefault(item => item.Id == optId);

            return(alias?.AliasId ?? optId);
        }