Example #1
0
        public async Task <int> ExecuteAsync()
        {
            var version = Assembly.GetEntryAssembly().GetCustomAttribute <AssemblyFileVersionAttribute>().Version;

            if (_args.DisableColoredLogging)
            {
                FlubuConsoleLogger.DisableColloredLogging = true;
            }

            _log.LogInformation($"Flubu v.{version}");

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

            try
            {
                var script = await _scriptLoader.FindAndCreateBuildScriptInstanceAsync(_args);

                _taskSession.FlubuHelpText = FlubuHelpText;
                _taskSession.ScriptArgs    = _args.ScriptArguments;
                var result = script.Run(_taskSession);
                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);
            }
        }
Example #2
0
        public async Task <IBuildScript> GetBuildScriptAsync(CommandArguments commandArguments, bool forceReload = false)
        {
            if (_script != null && !forceReload)
            {
                return(_script);
            }

            _script = await _scriptLoader.FindAndCreateBuildScriptInstanceAsync(commandArguments);

            return(_script);
        }
Example #3
0
        public async Task <int> ExecuteAsync()
        {
            var version = Assembly.GetEntryAssembly().GetCustomAttribute <AssemblyFileVersionAttribute>().Version;

            if (_args.DisableColoredLogging)
            {
                FlubuConsoleLogger.DisableColloredLogging = true;
            }

            _log.LogInformation($"Flubu v.{version}");

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

            if (_args.MainCommands.Count == 1 && _args.MainCommands.First().Equals("setup", StringComparison.OrdinalIgnoreCase))
            {
                TargetTree.SetupFlubu();
                return(0);
            }

            try
            {
                int result = 0;
                do
                {
                    IBuildScript script = null;

                    try
                    {
                        if (!_flubuSession.InteractiveMode)
                        {
                            script = await _scriptLoader.FindAndCreateBuildScriptInstanceAsync(_args);
                        }
                        else
                        {
                            script = await _scriptLoader.FindAndCreateBuildScriptInstanceAsync(_flubuSession
                                                                                               .InteractiveArgs);
                        }
                    }
                    catch (BuildScriptLocatorException)
                    {
                        if (!_args.InteractiveMode && !_flubuSession.InteractiveMode)
                        {
                            throw;
                        }

                        await SimpleFlubuInteractiveMode(script);
                    }

                    _flubuSession.TargetTree.BuildScript = script;
                    _flubuSession.FlubuHelpText          = FlubuHelpText;
                    _flubuSession.Properties.Set(BuildProps.IsWebApi, _args.IsWebApi);
                    _flubuSession.ScriptArgs = _args.ScriptArguments;
                    _flubuSession.TargetTree.ResetTargetTree();
                    //// ReSharper disable once PossibleNullReferenceException
                    if (script != null)
                    {
                        result = script.Run(_flubuSession);
                    }
                }while (_flubuSession.InteractiveMode && ReloadCommands.Contains(_flubuSession.InteractiveArgs.MainCommands[0], StringComparer.OrdinalIgnoreCase));

                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);
            }
        }
 public async Task <IBuildScript> GetBuildScriptAsync(CommandArguments commandArguments, bool forceReload = false)
 {
     return(await _scriptLoader.FindAndCreateBuildScriptInstanceAsync(commandArguments));
 }