示例#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);
        }