private static void ShowHelp(OptionSet options, AmbrosiaCSRuntimeModes mode) { var name = typeof(Program).Assembly.GetName().Name; #if NETCORE Console.WriteLine($"Usage: dotnet {name}.dll {mode} [OPTIONS]\nOptions:"); #else Console.WriteLine($"Usage: {name}.exe {mode} [OPTIONS]\nOptions:"); #endif options.WriteOptionDescriptions(Console.Out); }
private static OptionSet ParseOptions(string[] args, out bool shouldShowHelp) { var showHelp = false; var assemblyNames = new List <string>(); var projectFiles = new List <string>(); var codeGenOptions = new OptionSet { { "a|assembly=", "An input assembly file location. [REQUIRED]", a => assemblyNames.Add(Path.GetFullPath(a)) }, { "o|outputAssemblyName=", "An output assembly name. [REQUIRED]", outputAssemblyName => _outputAssemblyName = outputAssemblyName }, { "f|targetFramework=", "The output assembly target framework. [> 1 REQUIRED]", f => _targetFrameworks.Add(f) }, { "p|project=", "An input project file location for reference resolution. ", p => projectFiles.Add(Path.GetFullPath(p)) }, { "h|help", "show this message and exit", h => showHelp = h != null }, }; var runtimeModeToOptionSet = new Dictionary <AmbrosiaCSRuntimeModes, OptionSet> { { AmbrosiaCSRuntimeModes.CodeGen, codeGenOptions }, }; _runtimeMode = default(AmbrosiaCSRuntimeModes); if (args.Length < 1 || !Enum.TryParse(args[0], true, out _runtimeMode)) { Console.WriteLine("Missing or illegal runtime mode."); ShowHelp(runtimeModeToOptionSet); Environment.Exit(1); } var options = runtimeModeToOptionSet[_runtimeMode]; try { options.Parse(args); } catch (OptionException e) { Console.WriteLine("Invalid arguments: " + e.Message); ShowHelp(options, _runtimeMode); Environment.Exit(1); } shouldShowHelp = showHelp; _assemblyNames = assemblyNames; _projectFiles = projectFiles; return(codeGenOptions); }