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())); }
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); }
public static AppBehavior Select(string[] cmdLineArgs) { if (cmdLineArgs.Length == 0) { return(new ShowUsageBehavior()); } else { if (!cmdLineArgs[0].StartsWith("-")) { var path = cmdLineArgs[0]; return(new ExecuteScriptBehavior(path, cmdLineArgs.Skip(1).ToArray())); } else if (cmdLineArgs[0].ToLower() == "-measure") { if (cmdLineArgs.Length > 1) { var path = cmdLineArgs[1]; return(new MeasureBehavior(path, cmdLineArgs.Skip(2).ToArray())); } } else if (cmdLineArgs[0].ToLower() == "-compile") { if (cmdLineArgs.Length > 1) { var path = cmdLineArgs[1]; return(new ShowCompiledBehavior(path)); } } else if (cmdLineArgs[0].ToLower() == "-check") { if (cmdLineArgs.Length > 1) { bool cgi_mode = false; int paramIndex = 1; if (cmdLineArgs[paramIndex].ToLower() == "-cgi") { ++paramIndex; cgi_mode = true; } var path = cmdLineArgs[paramIndex]; ++paramIndex; string env = null; if (cmdLineArgs.Length > paramIndex && cmdLineArgs[paramIndex].StartsWith("-env=")) { env = cmdLineArgs[paramIndex].Substring(5); } return(new CheckSyntaxBehavior(path, env, cgi_mode)); } } else if (cmdLineArgs[0].ToLower() == "-make") { if (cmdLineArgs.Length == 3) { var codepath = cmdLineArgs[1]; var output = cmdLineArgs[2]; return(new MakeAppBehavior(codepath, output)); } } else if (cmdLineArgs[0].ToLower() == "-cgi") { return(new CgiBehavior()); } else if (cmdLineArgs[0].ToLower() == "-version") { return(new ShowVersionBehavior()); } else if (cmdLineArgs[0].StartsWith("-encoding=")) { var prefixLen = ("-encoding=").Length; if (cmdLineArgs[0].Length > prefixLen) { var encValue = cmdLineArgs[0].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(cmdLineArgs.Skip(1).ToArray())); } } else if (cmdLineArgs[0].StartsWith("-codestat=")) { var prefixLen = ("-codestat=").Length; if (cmdLineArgs[0].Length > prefixLen) { var outputStatFile = cmdLineArgs[0].Substring(prefixLen); ScriptFileHelper.EnableCodeStatistics(outputStatFile); return(Select(cmdLineArgs.Skip(1).ToArray())); } } } return(new ShowUsageBehavior()); }