示例#1
0
        public void Eval(params string[] input)
        {
            if (input.IsNullOrEmpty())
            {
                return;
            }

            string     commandName = input.First();
            CommandDef cmd         = this[commandName];

            if (cmd == null)
            {
                this.ShowUsageCommandNotFound(commandName);
                return;
            }

            try
            {
                cmd.Eval((input.Select(arg => arg)).Skip(1).ToArray());
            }
            catch (Exception ex)
            {
                this.HandleError(ex);
                CommandUI.PrintSectionBreak();
                cmd.ShowUsage();
            }
        }
示例#2
0
        //bool Validate()
        //{
        //    bool isValid = true;
        //    foreach (CommandDef cmd in m_commands.Values)
        //    {
        //        if (cmd.Eval == null)
        //        {
        //            Console.WriteLine("{0} has no Eval method", cmd.Name);
        //            isValid = false;
        //        }
        //    }

        //    return isValid;
        //}

        CommandDef Bind(string name)
        {
            CommandDef cmd = this[name];

            if (cmd == null)
            {
                throw new ArgumentException(string.Format("Command {0} not found. Type help for usage.", name));
            }

            return(cmd);
        }
示例#3
0
        CommandDef Ensure(string name)
        {
            CommandDef cmd = this[name];

            if (cmd == null)
            {
                cmd = new CommandDef {
                    Name = name
                };
                m_commands[name] = cmd;
            }

            return(cmd);
        }
示例#4
0
        public void Help(string[] args)
        {
            string cmdName = null;

            if (!args.IsNullOrEmpty())
            {
                cmdName = args[0];
            }

            if (string.IsNullOrEmpty(cmdName))
            {
                Console.WriteLine(HelpUsage);
                return;
            }

            if (cmdName.Equals("all", StringComparison.OrdinalIgnoreCase))
            {
                ShowAllUsage();
                return;
            }

            CommandDef cmd = this[cmdName];

            if (cmd != null)
            {
                cmd.ShowUsage();
                return;
            }
            //
            // Do a prefix match. Note: if needed, we can speed this up since the name array is sorted.
            //
            foreach (string name in this.PrefixMatchCommandNames(cmdName))
            {
                this.Bind(name).ShowUsage();
            }
        }