Exemple #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);
        }
Exemple #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);
        }
Exemple #3
0
        public static string TypeToDisplayString(this CmdLineParameter p)
        {
            Type type = p.Type;

            if (type.IsArray)
            {
                var ename = type.GetElementType().ToDisplayString(p.Config.ArgListSeparator);
                return(string.Concat("{", ename, ",...}"));
            }
            return(ToDisplayString(type));
        }
Exemple #4
0
        // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

        Tuple <CmdLineParameter, bool, string> ProcessParameter(CmdLineParameter parameter, IDictionary <string, string> args)
        {
            var name = parameter.Name;
            var pair = args.Where(p1 => p1.Key.Equals(name, Defintion.Config.NameComparison)).FirstOrDefault();

            if (pair.Key != null)
            {
                args.Remove(pair.Key);
            }
            return(Tuple.Create(parameter, pair.Key != null, pair.Value));
        }
Exemple #5
0
 public static string DefaultValueToDisplayString(this CmdLineParameter p)
 {
     if (p.HasDefaultValue)
     {
         if (p.Type.IsEquivalentTo(typeof(Boolean)))
         {
             return(p.DefaultValue.ToString().ToLower());
         }
         return(p.DefaultValue?.ToString());
     }
     return(null);
 }