示例#1
0
        static IColorConsole WriteHelp(this IColorConsole con, CmdLineParameter p)
        {
            bool optional = p.HasDefaultValue;
            Type type     = p.Type;
            bool isFlag   = type.IsEquivalentTo(typeof(Boolean));
            var  color    = optional || isFlag ? OptionalParameterColor : ParameterColor;

            con.w(Indent).w(color, p.Name.PadRight(7)).w(" - {0}", type.ToDisplayName());
            if (p.HelpText != null)
            {
                con.w("{0}", p.HelpText);
            }

            if (type.IsEquivalentTo(typeof(Boolean)))
            {
                if (optional)
                {
                    con.w("(default=").w(DefaultValueColor, "{0}", p.DefaultValueToDisplayString()).w(")");
                }
            }
            else
            {
                Type nullable = type.IsGenericType && type.FullName.StartsWith("System.Nullable`1[") ? type.GetGenericArguments()[0] : null;
                if (optional)
                {
                    if (nullable == null && !type.IsEquivalentTo(typeof(string)) || p.DefaultValue != null)
                    {
                        con.w(" (default=").w(DefaultValueColor, "{0}", p.DefaultValueToDisplayString()).w(")");
                    }
                    //con.w("]");
                }
            }
            con.wl();
            return(con);
        }
示例#2
0
        static IColorConsole WriteShortHelp(this IColorConsole con, CmdLineParameter p)
        {
            bool optional = p.HasDefaultValue;
            Type type     = p.Type;
            var  color    = optional ? OptionalParameterColor : ParameterColor;

            con.w(" ");
            if (type.IsEquivalentTo(typeof(Boolean)))
            {
                con.w("[{0}", p.Config.ArgStartsWith).w(OptionalParameterColor, p.Name).w("]");
                if (optional)
                {
                    con.w("(default=").w(DefaultValueColor, "{0}", p.DefaultValueToDisplayString()).w(")");
                }
            }
            else
            {
                Type nullable = type.IsGenericType && type.FullName.StartsWith("System.Nullable`1[") ? type.GetGenericArguments()[0] : null;
                if (optional)
                {
                    con.w("[");
                }
                con.w("{0}", p.Config.ArgStartsWith).w(color, p.Name).w("=").w("{0}", nullable != null ? nullable.ToDisplayString() : p.TypeToDisplayString());
                if (optional)
                {
                    if (nullable == null && !type.IsEquivalentTo(typeof(string)) || p.DefaultValue != null)
                    {
                        con.w("(default=").w(DefaultValueColor, "{0}", p.DefaultValueToDisplayString()).w(")");
                    }
                    con.w("]");
                }
            }
            return(con);
        }