Пример #1
0
 public static CLIResult Error(string msg, CLICommandInfo cmd = null, int errCode = -1)
 {
     if (cmd != null)
     {
         msg += $"\nusage: {cmd.GetCommandFormat()}";
     }
     return(new CLIResult(ResultType.Error, msg, errCode));
 }
Пример #2
0
        public static CLICommandInfo Parse(MethodInfo minfo)
        {
            var cmdinfo = new CLICommandInfo();

            cmdinfo.CommandName = minfo.Name;
            cmdinfo.m_method    = minfo;

            var parameters = minfo.GetParameters();

            foreach (var p in parameters)
            {
                var cmdparam = new CommandParam();
                cmdparam.Key       = p.Name;
                cmdparam.Name      = p.Name;
                cmdparam.ParamType = p.ParameterType;
                var optionalAttr = Attribute.GetCustomAttribute(p, typeof(CLIOptional)) as CLIOptional;
                cmdparam.IsOptional = optionalAttr != null;
                if (optionalAttr != null && optionalAttr.Key != null)
                {
                    cmdparam.Key = optionalAttr.Key;
                }
                if (p.HasDefaultValue)
                {
                    cmdparam.DefaultValue = p.DefaultValue;
                }
                else
                {
                    if (cmdparam.IsOptional)
                    {
                        throw new Exception("Optional parameter must have default value.");
                    }
                }
                cmdinfo.Params.Add(cmdparam);
            }
            return(cmdinfo);
        }
Пример #3
0
        private void Print(string error, CLICommandInfo cmd)
        {
            var cliresult = CLIResult.Error(error);

            cliresult.Print();
        }
Пример #4
0
        public void Register(MethodInfo methodinfo)
        {
            var method = CLICommandInfo.Parse(methodinfo);

            m_cmds.Add(method);
        }