private static void InitializeServices(string[] args) { _consoleArgsReader = new ConsoleArgsReader(); bool verbose = _consoleArgsReader.ContainsVerboseOption(args); _logger = new ConsoleLogger(verbose); _fileSystem = new FileSystem(); _configProvider = new ConfigProvider(_fileSystem, _logger); _generatorOptionsProvider = new GeneratorOptionsProvider(_fileSystem, _logger); _projectFileManager = new ProjectFileManager(_fileSystem); _projectBuilder = new ProjectBuilder(_logger); }
private static void Main(string[] args) { try { if (args == null || args.Length == 0 || _consoleArgsReader.ContainsHelpOption(args) || _consoleArgsReader.ContainsAnyCommand(args) == false) { ShowHelp(); return; } if (_consoleArgsReader.ContainsGetCwdCommand(args)) { string cwd = _fileSystem.GetCurrentDirectory(); _logger.Log($"Current working directory is: {cwd}"); return; } _logger.LogVerbose = _consoleArgsReader.ContainsVerboseOption(args); string[] configPaths = _consoleArgsReader.GetConfigPaths(args).ToArray(); string[] projectFolders = _consoleArgsReader.ContainsProjectFolderOption(args) ? _consoleArgsReader.GetProjectFolders(args).ToArray() : new [] { "." }; for (var i = 0; i < projectFolders.Length; i++) { string projectFolder = projectFolders[i]; string configPath = configPaths.HasIndex(i) ? configPaths[i] : null; _assemblyResolver = new AssemblyResolver(_fileSystem, _logger, projectFolder); _logger.Log($"Generating files for project \"{projectFolder}\"..."); Generate(projectFolder, configPath); _logger.Log($"Files for project \"{projectFolder}\" generated successfully.", ""); } } catch (Exception e) when(e is CliException || e is CoreException) { _logger.Log($"APPLICATION ERROR: {e.Message}", e.StackTrace); } catch (AssemblyResolutionException e) { string message = e.Message + "Consider adding any external assembly directories in the externalAssemblyPaths parameter. " + "If you're using ASP.NET Core, add your NuGet directory to externalAssemblyPaths parameter (you can use global NuGet packages directory alias: \"<global-packages>\")"; _logger.Log(message, e.StackTrace); } catch (ReflectionTypeLoadException e) { foreach (Exception loaderException in e.LoaderExceptions) { _logger.Log($"TYPE LOAD ERROR: {loaderException.Message}", e.StackTrace); } } catch (Exception e) { _logger.Log($"GENERIC ERROR: {e.Message}", e.StackTrace); } }
public void ContainsVerboseOption_Test(string[] args, bool expectedResult) { bool actualResult = _consoleArgsReader.ContainsVerboseOption(args); Assert.Equal(expectedResult, actualResult); }