Beispiel #1
0
        public static void ParseInput(string message)
        {
            // Doing some init stuff.
            string unfilteredMessage = message;

            message = message.ToLower();
            unfilteredMessageArray = unfilteredMessage.Split(delimiterChars);
            messageArray           = message.Split(delimiterChars);
            rootFolder             = Directory.GetCurrentDirectory();

            if (enableDebug)
            {
                Console.WriteLine("Message recieved was!: {0}", messageArray[0]);
            }
            // Do whatever we need to do to parse something.
            if (messageArray[0].Equals("create"))
            {
                if (!messageArray[1].Equals(""))
                {
                    Console.WriteLine("Creating new entry: {0}!", messageArray[1]);
                }
                // If the second argument even remotely contains a path, we are going to treat it like one.
                if (messageArray[1].Contains("/") || messageArray[1].Equals(".."))
                {
                    Console.WriteLine("Appending entry to {0}, under project {1}", messageArray[1], Tekton.GetCurrentProject());
                    // A little hack to capitilize the names of the directories when we are creating them. Just so they look nice.
                    // string serializedDirectoryName = FirstCharToUpper(messageArray[1].Substring(1));
                    // Console.WriteLine(serializedDirectoryName);
                    // We have to make sure to append the "/", otherwise, it'll just create some other directory.
                    // Directory.CreateDirectory(Directory.GetCurrentDirectory().ToString() + "/" + serializedDirectoryName);
                    Directory.CreateDirectory(Directory.GetCurrentDirectory().ToString() + unfilteredMessageArray[1]);
                    // Debating if letting the user decide whether or not he/she wants to, by default, change directories into what they just made.
                }
                else if (messageArray.Length <= 1)
                {
                    ErrorException(parserErrors.ARG_ERROR);
                }
            }
            // Application Specific Arguemnts ---------------------------
            else if (messageArray[0].Equals("q") || messageArray[0].Equals("quit") || messageArray[0].Equals("exit"))
            {
                Environment.Exit(0);
            }
            else if (messageArray[0].Equals("clear") || messageArray[0].Equals("cls"))
            {
                Console.Clear();
            }
            else if (messageArray[0].Equals("help"))
            {
                try {
                    string helpText = File.ReadAllText(rootFolder + "../../../data/help.txt", Encoding.UTF8);
                    Console.WriteLine(helpText);
                }
                catch (DirectoryNotFoundException e) {
                    Console.WriteLine(e.Message);
                }
            }
            else if (messageArray[0].Equals("ls"))
            {
                string dir = Directory.GetCurrentDirectory();
                try {
                    foreach (string f in Directory.GetFiles(dir))
                    {
                        Console.WriteLine(f);
                    }
                    foreach (string d in Directory.GetDirectories(dir))
                    {
                        Console.WriteLine(d);
                        // DirSearch(d);
                    }
                }
                catch (System.Exception ex) {
                    Console.WriteLine(ex.Message);
                }
            }
            else if (messageArray[0].Equals("debug"))
            {
                Console.WriteLine("Debug Mode: {0}", !enableDebug);
                enableDebug = !enableDebug;
            }
            else if (messageArray[0].Equals("cd"))
            {
                if (!messageArray[1].Equals("") || messageArray[1] != null)
                {
                    try {
                        Directory.SetCurrentDirectory(Directory.GetCurrentDirectory() + unfilteredMessageArray[1]);
                        Tekton.SetProjectPath(GetLastFolderName(Directory.GetCurrentDirectory()) + "/" + Path.GetFileName(Directory.GetCurrentDirectory()));
                    }
                    catch (DirectoryNotFoundException e) {
                        // Why the hell doesn't this directory exist I'm trying to cd into it? :thinking:
                        // Console.WriteLine(e.Message);
                        ErrorException(parserErrors.DIR_ERROR);
                    }
                }
                if (messageArray[1].Equals(".."))
                {
                    Directory.SetCurrentDirectory(Path.Combine(Directory.GetCurrentDirectory(), ".."));
                }
            }
            else
            {
                // If the input matches NONE of these, then it's considered an argument error.
                ErrorException(parserErrors.ARG_ERROR);
            }
        }
Beispiel #2
0
 public static void InputManager(string userInput)
 {
     ParseInput(userInput);
     Tekton.TektonProjectCLI(Tekton.GetCurrentProject(), Tekton.GetUserName());
 }