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); }
private static AppBehavior SelectParametrized(CmdLineHelper helper) { var initializers = new Dictionary <string, Func <CmdLineHelper, AppBehavior> >(); initializers.Add("-measure", MeasureBehavior.Create); initializers.Add("-compile", ShowCompiledBehavior.Create); initializers.Add("-check", CheckSyntaxBehavior.Create); initializers.Add("-make", MakeAppBehavior.Create); initializers.Add("-cgi", h => new CgiBehavior()); initializers.Add("-version", h => new ShowVersionBehavior()); initializers.Add("-v", h => new ShowVersionBehavior()); initializers.Add("-encoding", ProcessEncodingKey); initializers.Add("-codestat", EnableCodeStatistics); initializers.Add("-debug", DebugBehavior.Create); initializers.Add("-serialize", SerializeModuleBehavior.Create); var param = helper.Parse(helper.Current()); if (initializers.TryGetValue(param.Name.ToLowerInvariant(), out var action)) { return(action(helper)); } return(null); }
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 }); }
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())); }