Ejemplo n.º 1
0
        public virtual string GetSwitchHelp(ParamsObject InputParams)
        {
            int _atLeastOne = 0;
            IEnumerable <SwitchAttribute> switchAttrs = getOrderedSwitches(InputParams);
            ///If allowed to call with no default ordinal
            bool   defaultOrdinalAllowed  = switchAttrs.Where(sa => sa.Required && sa.DefaultOrdinal == null).Count() == 0;
            string _defaultOrdinalMessage = "";

            if (!defaultOrdinalAllowed)
            {
                _defaultOrdinalMessage = "Anonymous parameters not allowed.";
            }
            else
            {
                _defaultOrdinalMessage = "Anonymous parameters must be passed in their default ordinal, as listed below.";
            }
            string _help = _defaultOrdinalMessage + Environment.NewLine;

            foreach (SwitchAttribute switchAttr in switchAttrs)
            {
                SwitchHelpTextAttribute helpText = InputParams.GetPropertyByAttribute(switchAttr).GetCustomAttribute <SwitchHelpTextAttribute>();
                if (helpText == null)
                {
                    continue;
                }
                _atLeastOne++;
                string   _name             = helpText.Name;
                string   _description      = helpText.Description;
                string   _isoptional       = switchAttr.Required ? "Required" : "Optional";
                string   _acceptedValues   = "";
                string   _noDefaultOrdinal = defaultOrdinalAllowed && switchAttr.DefaultOrdinal.HasValue ? "" : "No default ordinal. ";
                string[] _acceptedValArr   = _parser.GetAcceptedValues(InputParams.GetPropertyByAttribute(switchAttr).PropertyType);
                if (_acceptedValArr.Length == 0)
                {
                    _acceptedValArr = switchAttr.SwitchValues;
                }
                if (_acceptedValArr.Length > 0)
                {
                    _acceptedValues = _acceptedValArr.Length == 0 ? "" : string.Format("Accepted Values: {0}`{1}`.",
                                                                                       string.Concat(
                                                                                           _acceptedValArr
                                                                                           .Take(_acceptedValArr.Length - 1)
                                                                                           .Select(s => "`" + s.ToUpper() + "`| ")
                                                                                           ),
                                                                                       _acceptedValArr.ElementAt(_acceptedValArr.Length - 1).ToUpper());
                }
                if (string.IsNullOrEmpty(_name))
                {
                    _name = switchAttr.SwitchName;
                }
                _name  = _name.ToUpper();
                _help += Environment.NewLine + string.Format("/{0," + (_options.HelpTextIndentLength * -1).ToString() + "} {1}. {2}{3}. {4}", _name + ": ", _isoptional, _noDefaultOrdinal, _description, _acceptedValues);
            }
            _help += Environment.NewLine;
            return(_help);
        }
Ejemplo n.º 2
0
        public virtual string GetUsage(ParamsObject InputParams)
        {
            string _usage = System.IO.Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly().Location) + " ";
            IEnumerable <SwitchAttribute> switchAttrs = getOrderedSwitches(InputParams);

            foreach (SwitchAttribute switchAttr in switchAttrs)
            {
                string _name = switchAttr.SwitchName;
                _usage += string.Format("/{0}:\"{1}\" ", _name.ToUpper(), InputParams.GetPropertyByAttribute(switchAttr).Name);
            }
            return(_usage);
        }