Exemplo n.º 1
0
        public static ProcessResult Run(string command, string arguments, string workingDirectory, bool printOutput, bool printErrors)
        {
            try
            {
                Output.Logger.Debug("starting child process", new { command, arguments, workingDirectory });
                PerformanceTesting.Checkpoint($"Begin Process {command} {arguments.Split(' ').First()}");

                var process = System.Diagnostics.Process.Start(new ProcessStartInfo()
                {
                    FileName               = command,
                    WorkingDirectory       = workingDirectory ?? Environment.CurrentDirectory,
                    Arguments              = arguments,
                    RedirectStandardOutput = !printOutput,
                    RedirectStandardError  = !printErrors,
                });
                process.WaitForExit();

                var output = printOutput ? null : process.StandardOutput.ReadToEnd();
                var error  = printErrors ? null : process.StandardError.ReadToEnd();

                Output.Logger.Trace("end child process", new { command, arguments, workingDirectory, process_stdout = output, process_stderr = error });

                PerformanceTesting.Checkpoint($"End Process {command}");
                return(new ProcessResult(process.ExitCode, output, error));
            }
            catch (Win32Exception ex)
            {
                Output.Logger.Fatal("missing dependency", new { dependency = command });
                throw new FatalException($"{command} is not available.", ex);
            }
        }
Exemplo n.º 2
0
        private void PrintHelp(NotParsed <object> result)
        {
            PerformanceTesting.Checkpoint("Begin Help");
            var verb = GetVerb(result.TypeInfo.Current);

            HelpPrinter.PrintHelp(verb, result);
        }
Exemplo n.º 3
0
        private void ExecuteVerb(IOptions options)
        {
            PerformanceTesting.Checkpoint("End Parse");
            options.PassthroughArguments = string.Join(" ", _argsRest);

            var verb = GetVerb(options.GetType());

            VerbExecuter.ExecuteVerb(verb, options);
        }
Exemplo n.º 4
0
        public static void InitUserConfig(ILogger logger)
        {
            PerformanceTesting.Checkpoint("Begin Configuration");

            logger.Debug("building user configuration");
            UserConfig = BuildUserConfig();

            PerformanceTesting.Checkpoint("End Configuration");
        }
Exemplo n.º 5
0
        private static void CheckDocker(ILogger logger, IVerb verb, UserConfig config)
        {
            PerformanceTesting.Checkpoint("Begin Docker Check");
            logger.Trace("checking docker");

            if (verb.RequiresDocker && config.Checks.Docker && !Docker.IsRunning())
            {
                logger.Fatal("docker check failed");
                throw new FatalException("Docker daemon is unreachable or not running.");
            }

            PerformanceTesting.Checkpoint("End Docker Check");
        }
Exemplo n.º 6
0
        public static void ExecuteVerb(IVerb verb, IOptions options)
        {
            var logger = Init(verb, options);

            logger.Debug("executing verb");

            PerformanceTesting.Checkpoint("Begin Verb");
            verb.Execute(options, Output.Logger);

            logger.Info("execution completed", new { time = PerformanceTesting.GetElapsedMilliseconds() });

            Output.Dispose();
        }
Exemplo n.º 7
0
        public IEnumerable <Error> ParseAndExecuteVerb()
        {
            PerformanceTesting.Checkpoint("Begin Parse");
            switch (GetParser().ParseArguments(_args, GetVerbTypes()))
            {
            case Parsed <object> result:
                ExecuteVerb((IOptions)result.Value);
                break;

            case NotParsed <object> result:
                PrintHelp(result);
                return(result.Errors);
            }
            return(new Error[0]);
        }
Exemplo n.º 8
0
 public static int Main(string[] args)
 {
     try
     {
         PreRun();
         return(Run(args));
     }
     catch (Exception ex)
     {
         return(HandleException(ex));
     }
     finally
     {
         Output.Fancy.ResetStyling();
         PerformanceTesting.Checkpoint("End");
     }
 }
Exemplo n.º 9
0
        private static int HandleException(Exception ex)
        {
            if (ex is FatalException fatalEx)
            {
                PerformanceTesting.Checkpoint("Fatal Exception");
                ErrorPrinter.Fatal(fatalEx.Message);

                if (fatalEx.InnerException != null)
                {
                    ErrorPrinter.HandledException(null, fatalEx.InnerException);
                }

                return(fatalEx.ExitCode);
            }

            PerformanceTesting.Checkpoint("Unhandled Exception");

            Output.Logger.Fatal(null, ex);
            ErrorPrinter.UnhandledException(ex);

            return(1);
        }