Example #1
0
        public RCLArgv(params string[] argv)
        {
            Exit      = false;
            Batch     = false;
            NoKeys    = false;
            NoResult  = false;
            Version   = false;
            FullStack = false;
            Program   = "";
            Action    = "";
            Output    = "full";
            Show      = new string[] { "*" };
            Hide      = new string[] { };
            RCBlock       custom    = RCBlock.Empty;
            List <string> arguments = new List <string> ();

            for (int i = 0; i < argv.Length; ++i)
            {
                string[] kv = argv[i].Split('=');
                if (kv.Length == 1)
                {
                    if (kv[0].StartsWith("--"))
                    {
                        string option = kv[0].Substring(2);
                        if (option.Equals("exit"))
                        {
                            Exit = true;
                        }
                        else if (option.Equals("batch"))
                        {
                            Batch = true;
                        }
                        else if (option.Equals("nokeys"))
                        {
                            NoKeys = true;
                        }
                        else if (option.Equals("noread"))
                        {
                            NoRead = true;
                        }
                        else if (option.Equals("noresult"))
                        {
                            NoResult = true;
                        }
                        else if (option.Equals("fullstack"))
                        {
                            FullStack = true;
                        }
                        else if (option.Equals("version"))
                        {
                            // This option forces the version to display no matter what.
                            // Useful when you need to check the version number from a test.
                            Version = true;
                        }
                        else
                        {
                            custom = new RCBlock(custom, option, ":", RCBoolean.True);
                        }
                    }
                    else if (kv[0].StartsWith("-"))
                    {
                        for (int j = 1; j < kv[0].Length; ++j)
                        {
                            char c;
                            switch (c = kv[0][j])
                            {
                            case 'x':
                                Exit = true;
                                break;

                            case 'b':
                                Batch = true;
                                break;

                            case 'k':
                                NoKeys = true;
                                break;

                            case 'r':
                                NoRead = true;
                                break;

                            case 'v':
                                Version = true;
                                break;

                            default:
                                Usage("Unknown option '" + kv[0][j] + "'");
                                break;
                            }
                        }
                    }
                    else
                    {
                        // do position.
                        arguments.Add(kv[0]);
                    }
                }
                else
                {
                    // do named arguments.
                    if (kv[0].StartsWith("--"))
                    {
                        string option = kv[0].Substring(2);
                        if (option.Equals("program"))
                        {
                            Program = kv[1];
                        }
                        else if (option.Equals("action"))
                        {
                            Action = kv[1];
                        }
                        else if (option.Equals("output"))
                        {
                            Output = kv[1];
                        }
                        else if (option.Equals("show"))
                        {
                            Show = kv[1].Split(',');
                        }
                        else if (option.Equals("hide"))
                        {
                            Hide = kv[1].Split(',');
                        }
                        else
                        {
                            custom = new RCBlock(custom, option, ":", new RCString(kv[1]));
                        }
                    }
                    else
                    {
                        Usage("Named options start with --");
                    }
                }
            }
            Arguments  = new RCString(arguments.ToArray());
            Options    = RCBlock.Empty;
            Options    = new RCBlock(Options, "program", ":", new RCString(Program));
            Options    = new RCBlock(Options, "action", ":", new RCString(Action));
            Options    = new RCBlock(Options, "output", ":", new RCString(Output));
            Options    = new RCBlock(Options, "show", ":", new RCString(Show));
            Options    = new RCBlock(Options, "hide", ":", new RCString(Hide));
            Options    = new RCBlock(Options, "batch", ":", new RCBoolean(Batch));
            Options    = new RCBlock(Options, "nokeys", ":", new RCBoolean(NoKeys));
            Options    = new RCBlock(Options, "noread", ":", new RCBoolean(NoRead));
            Options    = new RCBlock(Options, "noresult", ":", new RCBoolean(NoResult));
            Options    = new RCBlock(Options, "exit", ":", new RCBoolean(Exit));
            Options    = new RCBlock(Options, "version", ":", new RCBoolean(Version));
            Options    = new RCBlock(Options, "fullstack", ":", new RCBoolean(FullStack));
            OutputEnum = (RCOutput)Enum.Parse(typeof(RCOutput), Output, true);
            for (int i = 0; i < custom.Count; ++i)
            {
                RCBlock name = custom.GetName(i);
                Options = new RCBlock(Options, name.Name, ":", name.Value);
            }
        }
Example #2
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);
        }
Example #3
0
 public void SetVerbosity(RCOutput level)
 {
     _level = level;
 }