Exemple #1
0
        public void TestListSystemCommands()
        {
            Execute("bind mouse0 +bool");

            Assert.AreEqual(1, CRegistery.ListCommands("+bool", CCommandListOptions.System).Count);
            Assert.AreEqual(1, CRegistery.ListCommands("-bool", CCommandListOptions.System).Count);
        }
Exemple #2
0
        public void TestListCommands()
        {
            CRegistery.Clear();

            CCommand a11 = new cmd_a11();
            CCommand a12 = new cmd_a12();
            CCommand b11 = new cmd_b11();
            CCommand b12 = new cmd_b12();

            CRegistery.Register(a11);
            CRegistery.Register(a12);
            CRegistery.Register(b11);
            CRegistery.Register(b12);

            IList <CCommand> commands = CRegistery.ListCommands();

            AssertTypes(commands, typeof(cmd_a11), typeof(cmd_a12), typeof(cmd_b11), typeof(cmd_b12));

            commands = CRegistery.ListCommands("a");
            AssertTypes(commands, typeof(cmd_a11), typeof(cmd_a12));

            commands = CRegistery.ListCommands("a1");
            AssertTypes(commands, typeof(cmd_a11), typeof(cmd_a12));

            commands = CRegistery.ListCommands("a11");
            AssertTypes(commands, typeof(cmd_a11));

            commands = CRegistery.ListCommands("a13");
            AssertTypes(commands);
        }
Exemple #3
0
        public void TestListOperationCommands()
        {
            Execute("bind mouse0 +bool");

            Assert.AreEqual(0, CRegistery.ListCommands("+bool").Count);
            Assert.AreEqual(0, CRegistery.ListCommands("-bool").Count);
        }
Exemple #4
0
        private string[] ListCommandNames(string prefix, CommandListOptions options)
        {
            IList <CCommand> commands = CRegistery.ListCommands(delegate(CCommand cmd)
            {
                return(!(cmd is CVarCommand) && CRegistery.ShouldListCommand(cmd, prefix, options));
            });

            return(Collection.Map(commands, delegate(CCommand cmd)
            {
                return C(cmd.Name, cmd.ColorCode);
            }));
        }
Exemple #5
0
        void Execute(string prefix = null)
        {
            IList <CCommand> cmds = CRegistery.ListCommands(prefix);

            foreach (CCommand cmd in cmds)
            {
                CVarCommand cvarCmd = cmd as CVarCommand;
                if (cvarCmd != null)
                {
                    cvarCmd.ParentCommand = this;
                    cvarCmd.SetDefault();
                    cvarCmd.ParentCommand = null;
                }
            }
        }
Exemple #6
0
        public void TestRegisterMethodsCommands()
        {
            CRegistery.Clear();

            Lunar.RegisterCommand("del1", Del1);
            Lunar.RegisterCommand("del2", Del2);
            Lunar.RegisterCommand("del3", Del3);

            IList <CCommand> cmds = CRegistery.ListCommands("del");

            Assert.AreEqual(3, cmds.Count);
            Assert.AreEqual("del1", cmds[0].Name);
            Assert.AreEqual("del2", cmds[1].Name);
            Assert.AreEqual("del3", cmds[2].Name);
        }
Exemple #7
0
        protected override IList <string> AutoCompleteArgs(string commandLine, string token)
        {
            IList <CCommand> commands = CRegistery.ListCommands(delegate(CCommand command)
            {
                return(!(command is CVarCommand) &&
                       !(command is CDelegateCommand) &&
                       !(command is CAliasCommand) &&
                       CRegistery.ShouldListCommand(command, token, CCommand.DefaultListOptions));
            });

            if (commands.Count == 0)
            {
                return(null);
            }

            return(Collection.Map(commands, delegate(CCommand cmd)
            {
                return StringUtils.C(cmd.Name, cmd.ColorCode);
            }));
        }
Exemple #8
0
        public void TestRegisterMethodsCommandsFromTheSameObject()
        {
            CRegistery.Clear();

            Dummy dummy = new Dummy();

            CommandAction <string[]> del1 = dummy.Execute;
            CommandAction <string[]> del2 = dummy.Execute2;

            Lunar.RegisterCommand("del1", del1);
            Lunar.RegisterCommand("del2", del2);

            IList <CCommand> cmds = CRegistery.ListCommands("del");

            Assert.AreEqual(2, cmds.Count);
            Assert.AreEqual(del1, (cmds[0] as CDelegateCommand).ActionDelegate);
            Assert.AreEqual(del2, (cmds[1] as CDelegateCommand).ActionDelegate);

            CRegistery.UnregisterAll(dummy);
            cmds = CRegistery.ListCommands("del");
            Assert.AreEqual(0, cmds.Count);
        }
Exemple #9
0
        private static string[] getSuggestions(string line, string token)
        {
            IList <CCommand> commands = CRegistery.ListCommands(token);

            if (commands.Count == 0) // no commands found
            {
                return(EMPTY_SUGGESTIONS);
            }

            if (commands.Count == 1) // single command
            {
                CCommand cmd = commands[0];

                // check if line already contains suggested value (e.g. "cmdlist ")
                if (line.Length == cmd.Name.Length + 1 && line.EndsWith(" ") && line.StartsWith(cmd.Name))
                {
                    throw new NotImplementedException(); // FIXME
                }

                return(singleSuggestion(toDisplayName(cmd)));
            }

            return(getSuggestions(commands)); // multiple commands
        }
Exemple #10
0
 private static string[] getDefaultSuggestions()
 {
     return(getSuggestions(CRegistery.ListCommands()));
 }