Esempio n. 1
0
        private async Task SimpleFlubuInteractiveMode(IBuildScript script)
        {
            do
            {
                try
                {
                    var flubuConsole = new FlubuConsole(null, new List <Hint>());
                    var commandLine  = flubuConsole.ReadLine(Directory.GetCurrentDirectory());

                    var splitedLine = commandLine.Split(' ').ToList();

                    if (InteractiveExitCommands.Contains(splitedLine[0], StringComparer.OrdinalIgnoreCase))
                    {
                        break;
                    }

                    var app = new CommandLineApplication(false);
                    IFlubuCommandParser parser = new FlubuCommandParser(app, null);
                    var args = parser.Parse(commandLine.Split(' ')
                                            .Where(x => !string.IsNullOrWhiteSpace(x))
                                            .Select(x => x.Trim()).ToArray());
                    _flubuSession.InteractiveArgs = args;
                    _flubuSession.ScriptArgs      = args.ScriptArguments;

                    var internalCommandExecuted = flubuConsole.ExecuteInternalCommand(commandLine);
                    if (internalCommandExecuted)
                    {
                        continue;
                    }

                    if (!ReloadCommands.Contains(splitedLine[0], StringComparer.OrdinalIgnoreCase))
                    {
                        var command    = splitedLine.First();
                        var runProgram = _flubuSession.Tasks().RunProgramTask(command).DoNotLogTaskExecutionInfo()
                                         .WorkingFolder(".");
                        splitedLine.RemoveAt(0);
                        try
                        {
                            runProgram.WithArguments(splitedLine.ToArray()).Execute(_flubuSession);
                        }
                        catch (CommandUnknownException)
                        {
                            _flubuSession.LogError($"'{command}' is not recognized as a internal or external command, operable program or batch file.");
                        }
                        catch (TaskExecutionException)
                        {
                        }
                    }
                    else
                    {
                        script = await _scriptLoader.FindAndCreateBuildScriptInstanceAsync(_flubuSession.InteractiveArgs);
                    }
                }
                catch (BuildScriptLocatorException)
                {
                }
            }while (script == null);
        }
        protected virtual async Task <IBuildScript> SimpleFlubuInteractiveMode(IBuildScript script)
        {
            do
            {
                try
                {
                    var flubuConsole = new FlubuConsole(_flubuSession.TargetTree, new List <Hint>());
                    var commandLine  = flubuConsole.ReadLine();

                    if (string.IsNullOrEmpty(commandLine))
                    {
                        continue;
                    }

                    var splitedLine = commandLine.Split(' ').ToList();

                    if (InternalTerminalCommands.InteractiveExitOnlyCommands.Contains(splitedLine[0], StringComparer.OrdinalIgnoreCase))
                    {
                        break;
                    }

                    var cmdApp = new CommandLineApplication()
                    {
                        UnrecognizedArgumentHandling = UnrecognizedArgumentHandling.CollectAndContinue
                    };
                    var parser = new FlubuCommandParser(cmdApp, null, null, null);
                    var args   = parser.Parse(commandLine.Split(' ')

                                              .Where(x => !string.IsNullOrWhiteSpace(x))
                                              .Select(x => x.Trim()).ToArray());
                    _flubuSession.InteractiveArgs = args;
                    _flubuSession.ScriptArgs      = args.ScriptArguments;
                    Args = args;
                    Args.InteractiveMode = true;

                    var internalCommandExecuted = flubuConsole.ExecuteInternalCommand(commandLine);
                    if (internalCommandExecuted)
                    {
                        continue;
                    }

                    if (!InternalTerminalCommands.ReloadCommands.Contains(splitedLine[0], StringComparer.OrdinalIgnoreCase))
                    {
                        var command    = splitedLine.First();
                        var runProgram = _flubuSession.Tasks().RunProgramTask(command).DoNotLogTaskExecutionInfo()
                                         .WorkingFolder(Directory.GetCurrentDirectory());
                        splitedLine.RemoveAt(0);
                        try
                        {
                            runProgram.WithArguments(splitedLine.ToArray()).Execute(_flubuSession);
                        }
                        catch (CommandUnknownException)
                        {
                            _flubuSession.LogError($"'{command}' is not recognized as a internal or external command, operable program or batch file.");
                        }
                        catch (TaskExecutionException)
                        {
                        }
                        catch (ArgumentException)
                        {
                        }
                        catch (Win32Exception)
                        {
                        }
                    }
                    else
                    {
                        script = await _scriptProvider.GetBuildScriptAsync(_flubuSession.InteractiveArgs, true);
                    }
                }
                catch (BuildScriptLocatorException)
                {
                    _flubuSession.LogInfo("Build script not found.");
                }
            }while (script == null);

            return(script);
        }
        protected virtual void FlubuInteractiveMode(IFlubuSession flubuSession, IBuildScript script)
        {
            flubuSession.InteractiveMode = true;
            var flubuConsole = InitializeFlubuConsole(flubuSession, script);

            flubuSession.TargetTree.ScriptArgsHelp = _scriptProperties.GetPropertiesHelp(script);
            flubuSession.TargetTree.RunTarget(flubuSession, FlubuTargets.HelpOnlyTargets);
            flubuSession.LogInfo(" ");

            do
            {
                if (flubuSession.InteractiveMode)
                {
                    var commandLine = flubuConsole.ReadLine();

                    if (string.IsNullOrEmpty(commandLine))
                    {
                        continue;
                    }

                    var cmdApp = new CommandLineApplication()
                    {
                        UnrecognizedArgumentHandling = UnrecognizedArgumentHandling.CollectAndContinue
                    };
                    var parser = new FlubuCommandParser(cmdApp, null, null, null);
                    var args   = parser.Parse(commandLine.Split(' ')

                                              .Where(x => !string.IsNullOrWhiteSpace(x))
                                              .Select(x => x.Trim()).ToArray());
                    var targetsInfo = DefaultBuildScript.ParseCmdLineArgs(args.MainCommands, flubuSession.TargetTree);

                    if (args.MainCommands.Count == 0)
                    {
                        continue;
                    }

                    if (!args.MainCommands[0].Equals("l", StringComparison.OrdinalIgnoreCase) &&
                        !args.MainCommands[0].Equals("load", StringComparison.OrdinalIgnoreCase))
                    {
                        args.Script = flubuSession.InteractiveArgs.Script;
                    }

                    flubuSession.InteractiveArgs = args;
                    flubuSession.ScriptArgs      = args.ScriptArguments;
                    _scriptProperties.InjectProperties(script, flubuSession);

                    if (InternalTerminalCommands.InteractiveExitAndReloadCommands.Contains(args.MainCommands[0],
                                                                                           StringComparer.OrdinalIgnoreCase))
                    {
                        break;
                    }

                    if (targetsInfo.unknownTarget)
                    {
                        var internalCommandExecuted = flubuConsole.ExecuteInternalCommand(commandLine);
                        if (internalCommandExecuted)
                        {
                            continue;
                        }

                        var splitedLine = commandLine.Split(' ').ToList();
                        var command     = splitedLine.First();
                        var runProgram  = flubuSession.Tasks().RunProgramTask(command).DoNotLogTaskExecutionInfo()
                                          .WorkingFolder(Directory.GetCurrentDirectory());
                        splitedLine.RemoveAt(0);
                        try
                        {
                            runProgram.WithArguments(splitedLine.ToArray()).Execute(flubuSession);
                        }
                        catch (CommandUnknownException)
                        {
                            flubuSession.LogError(
                                $"'{command}' is not recognized as a flubu target, internal or external command, operable program or batch file.");
                        }
                        catch (TaskExecutionException e)
                        {
                            flubuSession.LogError($"ERROR: {(flubuSession.Args.Debug ? e.ToString() : e.Message)}", Color.Red);
                        }
                        catch (ArgumentException)
                        {
                        }
                        catch (Win32Exception)
                        {
                        }

                        continue;
                    }
                }

                try
                {
                    script.Run(flubuSession);
                    flubuSession.LogInfo(" ");
                }
                catch (Exception e)
                {
                    flubuSession.LogError($"ERROR: {(flubuSession.Args.Debug ? e.ToString() : e.Message)}", Color.Red);
                }
            }while (flubuSession.InteractiveMode);
        }