Beispiel #1
0
        private static void Main(string[] args)
        {
            try
            {
                InitializeServices(args);

                if (args == null || args.Length == 0 || _consoleArgsReader.ContainsHelpOption(args) || _consoleArgsReader.ContainsAnyCommand(args) == false)
                {
                    ShowHelp();
                    return;
                }

                if (_consoleArgsReader.ContainsGetCwdCommand(args))
                {
                    string cwd = _fileSystem.GetCurrentDirectory();
                    Console.WriteLine($"Current working directory is: {cwd}");
                    return;
                }

                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);

                    Generate(projectFolder, configPath);
                }
            }
            catch (Exception e) when(e is CliException || e is CoreException)
            {
                _logger.Log($"APPLICATION ERROR: {e.Message}{Environment.NewLine}{e.StackTrace}", LogLevel.Error);
            }
            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}{Environment.NewLine}{e.StackTrace}", LogLevel.Error);
            }
            catch (ReflectionTypeLoadException e)
            {
                foreach (Exception loaderException in e.LoaderExceptions)
                {
                    _logger.Log($"TYPE LOAD ERROR: {loaderException.Message}{Environment.NewLine}{e.StackTrace}", LogLevel.Error);
                }
            }
            catch (Exception e)
            {
                _logger.Log($"GENERIC ERROR: {e.Message}{Environment.NewLine}{e.StackTrace}", LogLevel.Error);
            }
        }
Beispiel #2
0
        public void ContainsAnyCommand_Test(string[] args, bool expectedResult)
        {
            bool actualResult = _consoleArgsReader.ContainsAnyCommand(args);

            Assert.Equal(expectedResult, actualResult);
        }