示例#1
0
        /// <summary>
        /// Some corny bash-like aliases for various things. We should get rid of this or do
        /// something better.
        /// </summary>
        static string Alias(string trimmed, RCRunner runner, RCLArgv cmd)
        {
            string line = trimmed;

            if (trimmed == "exit")
            {
                line = "exit 0";
            }
            else if (trimmed == "ls")
            {
                line = "exec \"ls\"";
            }
            else if (trimmed.StartsWith("ls"))
            {
                string path = GetPathArgument("ls", trimmed);
                line = string.Format("exec \"ls {0}\"", path);
            }
            else if (trimmed.StartsWith("cd"))
            {
                string path = GetPathArgument("cd", trimmed);
                // This prevents conflicting with the syntax for the internal cd command.
                if (path.Length > 0 && path[0] == '"')
                {
                    return(trimmed);
                }
                line = string.Format("cd \"{0}\"", path);
            }
            else if (trimmed == "lsl")
            {
                line = "cube list #files";
            }
            else if (trimmed == "pwd")
            {
                line = "pwd {}";
            }
            else if (trimmed == "quiet" ||
                     trimmed == "single" ||
                     trimmed == "multi" ||
                     trimmed == "full" ||
                     trimmed == "clean")
            {
                RCOutput level = (RCOutput)Enum.Parse(typeof(RCOutput), trimmed, true);
                RCSystem.Log.SetVerbosity(level);
            }
            else if (trimmed == "help")
            {
                Console.WriteLine("I am trying to be helpful, these are the command line arguments.");
                Console.WriteLine(cmd.Options.Format(RCFormat.Pretty));
            }
            else if (trimmed == "begin")
            {
                // Is this useful or even correct?
                StringBuilder text    = new StringBuilder();
                string        docline = Console.ReadLine();
                while (docline != "end")
                {
                    text.AppendLine(docline);
                    docline = Console.ReadLine();
                }
                line = text.ToString();
            }
            else if (trimmed.StartsWith("epl"))
            {
                string path = GetPathArgument("epl", trimmed);
                line = string.Format("eval parse load \"{0}\"", path);
            }
            else if (trimmed.StartsWith("fepl"))
            {
                string path = GetPathArgument("fepl", trimmed);
                line = string.Format("fiber {{<-eval parse load \"{0}\"}}", path);
            }
            else if (trimmed.StartsWith("reset"))
            {
                // This is the one operation that cannot be done with an operator.
                // line = "reset 0l";
                runner.Reset();
            }
            else if (trimmed.StartsWith("."))
            {
                if (trimmed == "..")
                {
                    line = "cd \"..\"";
                }
                else
                {
                    line = string.Format("cd \"{0}\"", trimmed.Substring(1));
                }
            }
            return(line);
        }