Пример #1
0
        public virtual async Task <int> ExecuteAsync()
        {
            if (_args.DisableColoredLogging)
            {
                FlubuConsoleLogger.DisableColloredLogging = true;
            }

            if (_args.Help)
            {
                return(1);
            }

            if (_args.IsFlubuSetup())
            {
                TargetTree.SetupFlubu();
                return(0);
            }

            try
            {
                var script = await _scriptProvider.GetBuildScriptAsync(_args);

                _flubuSession.FlubuHelpText          = FlubuHelpText;
                _flubuSession.ScriptArgs             = _args.ScriptArguments;
                _flubuSession.TargetTree.BuildScript = script;
                _flubuSession.Properties.Set(BuildProps.IsWebApi, _args.IsWebApi);
                var result = script.Run(_flubuSession);
                return(result);
            }
            catch (TaskExecutionException e)
            {
                if (_args.RethrowOnException)
                {
                    throw;
                }

                _log.Log(LogLevel.Error, 1, $"EXECUTION FAILED:\r\n{e.ToString()}", null, (t, ex) => t);
                return(StatusCodes.BuildScriptNotFound);
            }
            catch (FlubuException e)
            {
                if (_args.RethrowOnException)
                {
                    throw;
                }

                var str = _args.Debug ? e.ToString() : e.Message;
                _log.Log(LogLevel.Error, 1, $"EXECUTION FAILED:\r\n{str}", null, (t, ex) => t);
                return(StatusCodes.BuildScriptNotFound);
            }
            catch (Exception e)
            {
                if (_args.RethrowOnException)
                {
                    throw;
                }

                var str = _args.Debug ? e.ToString() : e.Message;
                _log.Log(LogLevel.Error, 1, $"EXECUTION FAILED:\r\n{str}", null, (t, ex) => t);
                return(3);
            }
        }