示例#1
0
 private void PrintUsingInformation()
 {
     Exit.PrintUsingInformation();
     Echo.PrintUsingInformation();
     Pwd.PrintUsingInformation();
     Cat.PrintUsingInformation();
     Wc.PrintUsingInformation();
     LocalVariable.PrintUsingInformation();
     Console.WriteLine("Use \"|\" for command pipelining");
     SystemShell.PrintUsingInformation();
     Console.WriteLine();
 }
示例#2
0
        private static ICommand NewCommand(string input, Dictionary <string, string> variables, bool isFirst)
        {
            string[] words = input.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if ((isFirst == false) && (words.Length != 1))
            {
                throw new ArgumentException("Incorrect arguments in \"" + input.Trim() + "\"");
            }

            List <string> arguments = new List <string>();
            string        command   = words[0].ToLower();

            for (int i = 1; i < words.Length; i++)
            {
                arguments.Add(words[i]);
            }

            if (arguments.Count > 0)
            {
                arguments = ToArguments(arguments, variables);
            }

            switch (command)
            {
            case "exit":
            {
                Exit exit = new Exit(arguments);

                return(exit);
            }

            case "echo":
            {
                Echo echo = new Echo(arguments);

                return(echo);
            }

            case "pwd":
            {
                Pwd pwd = new Pwd(arguments);

                return(pwd);
            }

            case "cat":
            {
                Cat cat = new Cat(arguments);

                return(cat);
            }

            case "wc":
            {
                Wc wc = new Wc(arguments);

                return(wc);
            }

            default:
            {
                SystemShell processStart = new SystemShell(words.ToList());

                return(processStart);
            }
            }
        }