Пример #1
0
        public static AppBehavior Select(string[] cmdLineArgs)
        {
            var    helper = new CmdLineHelper(cmdLineArgs);
            string arg    = helper.Next();

            if (arg == null)
            {
                return(new ShowUsageBehavior());
            }

            if (!arg.StartsWith("-"))
            {
                var path = arg;
                return(new ExecuteScriptBehavior(path, helper.Tail()));
            }

            var selected = SelectParametrized(helper);

            if (selected == null)
            {
                selected = new ShowUsageBehavior();
            }

            return(selected);
        }
Пример #2
0
        private static AppBehavior ProcessEncodingKey(CmdLineHelper helper)
        {
            var param     = helper.Current();
            var prefixLen = ("-encoding=").Length;

            if (param.Length > prefixLen)
            {
                var      encValue = param.Substring(prefixLen);
                Encoding encoding;
                try
                {
                    encoding = Encoding.GetEncoding(encValue);
                }
                catch
                {
                    Output.WriteLine("Wrong console encoding");
                    encoding = null;
                }

                if (encoding != null)
                {
                    Program.ConsoleOutputEncoding = encoding;
                }

                return(Select(helper.Tail()));
            }

            return(null);
        }
Пример #3
0
        private static AppBehavior ProcessEncodingKey(CmdLineHelper helper)
        {
            var param = helper.Parse(helper.Current());

            if (!string.IsNullOrEmpty(param.Value))
            {
                var      encValue = param.Value;
                Encoding encoding;
                try
                {
                    encoding = Encoding.GetEncoding(encValue);
                }
                catch
                {
                    Output.WriteLine("Wrong console encoding");
                    encoding = null;
                }

                if (encoding != null)
                {
                    Program.ConsoleOutputEncoding = encoding;
                }

                return(Select(helper.Tail()));
            }

            return(null);
        }
Пример #4
0
        public static AppBehavior Create(CmdLineHelper helper)
        {
            int               port         = 2801;
            string            path         = null;
            DebugProtocolType protocolType = DebugProtocolType.Tcp;

            while (true)
            {
                var arg = helper.Next();
                if (arg == null)
                {
                    break;
                }

                var parsedArg = helper.Parse(arg);
                if (parsedArg.Name == "-port")
                {
                    var portString = parsedArg.Value;
                    if (string.IsNullOrEmpty(portString))
                    {
                        return(null);
                    }

                    if (!Int32.TryParse(portString, out port))
                    {
                        Output.WriteLine("Incorrect port: " + portString);
                        return(null);
                    }
                }
                else if (parsedArg.Name == "-protocol")
                {
                    var proto = parsedArg.Value;
                    if (string.IsNullOrEmpty(proto) || !Enum.TryParse(proto, true, out protocolType))
                    {
                        Output.WriteLine("Unknown protocol. Using default");
                        protocolType = DebugProtocolType.Tcp;
                    }
                }
                else
                {
                    path = arg;
                    break;
                }
            }

            return(path == null ? null : new DebugBehavior(port, path, helper.Tail())
            {
                ProtocolType = protocolType
            });
        }
Пример #5
0
        private static AppBehavior EnableCodeStatistics(CmdLineHelper helper)
        {
            var param = helper.Parse(helper.Current());

            if (string.IsNullOrEmpty(param.Value))
            {
                return(null);
            }

            var outputStatFile = param.Value;

            ScriptFileHelper.EnableCodeStatistics(outputStatFile);
            return(Select(helper.Tail()));
        }
Пример #6
0
        private static AppBehavior SelectParametrized(CmdLineHelper helper)
        {
            var param = helper.Current().ToLowerInvariant();

            if (param == "-measure")
            {
                var path = helper.Next();
                if (path != null)
                {
                    return(new MeasureBehavior(path, helper.Tail()));
                }
            }
            else if (param == "-compile")
            {
                var path = helper.Next();
                if (path != null)
                {
                    return(new ShowCompiledBehavior(path));
                }
            }
            else if (param == "-check")
            {
                return(ProcessCheckKey(helper));
            }
            else if (param == "-make")
            {
                var codepath = helper.Next();
                var output   = helper.Next();
                var makeBin  = helper.Next();
                if (output != null && codepath != null)
                {
                    var appMaker = new MakeAppBehavior(codepath, output);
                    if (makeBin != null && makeBin == "-bin")
                    {
                        appMaker.CreateDumpOnly = true;
                    }

                    return(appMaker);
                }
            }
            else if (param == "-cgi")
            {
                return(new CgiBehavior());
            }
            else if (param == "-version" || param == "-v")
            {
                return(new ShowVersionBehavior());
            }
            else if (param.StartsWith("-encoding="))
            {
                return(ProcessEncodingKey(helper));
            }
            else if (param.StartsWith("-codestat="))
            {
                var prefixLen = ("-codestat=").Length;
                if (param.Length > prefixLen)
                {
                    var outputStatFile = param.Substring(prefixLen);
                    ScriptFileHelper.EnableCodeStatistics(outputStatFile);
                    return(Select(helper.Tail()));
                }
            }
            else if (param == "-debug")
            {
                var arg  = helper.Next();
                int port = 2801;
                if (arg != null && arg.StartsWith("-port="))
                {
                    var prefixLen = ("-port=").Length;
                    if (arg.Length > prefixLen)
                    {
                        var value = arg.Substring(prefixLen);
                        if (!Int32.TryParse(value, out port))
                        {
                            Output.WriteLine("Incorrect port: " + value);
                            return(null);
                        }
                    }
                }
                else if (arg != null)
                {
                    var path = arg;
                    return(new DebugBehavior(port, path, helper.Tail()));
                }
            }
            else if (param == "-serialize")
            {
                var path = helper.Next();
                if (path != null)
                {
                    return(new SerializeModuleBehavior(path));
                }

                return(new ShowUsageBehavior());
            }

            return(null);
        }
Пример #7
0
        public static AppBehavior Create(CmdLineHelper helper)
        {
            var path = helper.Next();

            return(path != null ? new MeasureBehavior(path, helper.Tail()) : null);
        }