Ejemplo n.º 1
0
        public Dictionary <string, object> Parse(string cmd)
        {
            string arguments = String.Join(" ", Commandline.ToArgs(cmd));

            return(new Dictionary <string, object>()
            {
                { "verb", "shell" },
                { "arguments", arguments }
            });
        }
Ejemplo n.º 2
0
 public static List <string> ParseOptions(string cmd, OptionSet options)
 {
     try
     {
         return(options.Parse(Commandline.ToArgs(cmd)));
     }
     catch (OptionException e)
     {
         throw new ArgumentException(e.Message);
     }
 }
Ejemplo n.º 3
0
        public Dictionary <string, object> Parse(string cmd)
        {
            List <string> args      = Commandline.ToArgs(cmd);
            string        script    = args[0];
            string        arguments = String.Join(" ", args.Skip(1));

            if (script.StartsWith("\"") && script.EndsWith("\""))
            {
                // If embraced with double-quotes, treat the path as a qualified path and no more guessing
                script = script.Trim('"');
                try
                {
                    script = Path.GetFullPath(script);
                }
                catch (Exception e)
                {
                    if (e is ArgumentException || e is NotSupportedException || e is PathTooLongException)
                    {
                        throw new ArgumentException("script");
                    }
                    else
                    {
                        throw; // Not expected to be `catch`ed
                    }
                }
            }
            else
            {
                // Otherwise the input is treated as a plain file name
                foreach (char c in Path.GetInvalidFileNameChars())
                {
                    if (script.Contains(c))
                    {
                        throw new ArgumentException("script");
                    }
                }

                if (!Path.HasExtension(script))
                {
                    script = Path.ChangeExtension(script, "txt");
                }

                string selfPath     = Path.GetDirectoryName(Application.ExecutablePath);
                string possiblePath = Path.Combine(selfPath, "Scripts", script);
                if (File.Exists(possiblePath))
                {
                    script = possiblePath; // $self\Scripts\$script
                }
                else
                {
                    script = Path.Combine(selfPath, "Scripts", "API", script); // $self\Scripts\API\$script
                }
            }

            return(new Dictionary <string, object>()
            {
                { "verb", "load" },
                { "script", script },
                { "arguments", arguments }
            });
        }