private static string ReadBuildScriptLocation() { bool scriptFound = false; string buildScriptLocation = null; while (!scriptFound) { var flubuConsole = new FlubuConsole(null, new List<Hint>(), options: o => { o.OnlyDirectoriesSuggestions = true; o.IncludeFileSuggestions = true; o.FileSuggestionsSearchPattern = "*.cs"; o.InitialText = "Enter path to script file (.cs) (enter to skip):"; o.WritePrompt = false; }); buildScriptLocation = flubuConsole.ReadLine().Trim(); if (string.IsNullOrEmpty(buildScriptLocation) || (Path.GetExtension(buildScriptLocation) == ".cs" && File.Exists(buildScriptLocation))) { scriptFound = true; } else { Console.WriteLine("Script file not found."); } } return buildScriptLocation; }
private static string ReadFlubuSettingsLocation() { bool csprojFound = false; string csprojLocation = null; while (!csprojFound) { var flubuConsole = new FlubuConsole(null, new List<Hint>(), options: o => { o.OnlyDirectoriesSuggestions = true; o.IncludeFileSuggestions = true; o.FileSuggestionsSearchPattern = "*.json"; o.WritePrompt = false; o.InitialText = "Enter flubu settings file location (enter to skip):"; }); csprojLocation = flubuConsole.ReadLine().Trim(); if (string.IsNullOrEmpty(csprojLocation) || (Path.GetExtension(csprojLocation) == ".json" && File.Exists(csprojLocation))) { csprojFound = true; } else { Console.WriteLine("flubu settings file not found."); } } return csprojLocation; }
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); }
private List <Tuple <string, string> > GetReplacementTokens(TemplateModel templateData) { var replacementTokens = new List <Tuple <string, string> >(); if (templateData?.Tokens != null && templateData.Tokens.Count > 0) { foreach (var token in templateData.Tokens) { switch (token.InputType) { case InputType.Options: { Console.WriteLine(string.Empty); for (int i = 0; i < token.Values.Count; i++) { Console.WriteLine($"{i} - {token.Values[i]}"); } Console.WriteLine(string.Empty); bool correctOption = false; int chosenOption; do { Console.Write($"Choose replacement value for token '{token.Token}':"); var key = Console.ReadLine().Trim(); if (int.TryParse(key, out chosenOption)) { if (chosenOption >= 0 && chosenOption < token.Values.Count) { correctOption = true; } } }while (correctOption); replacementTokens.Add(new Tuple <string, string>(token.Token, token.Values[chosenOption])); break; } default: { var initialText = !string.IsNullOrEmpty(token.Description) ? token.Description : $"Enter replacement value for token {token.Token}"; bool directoryAndFilesSuggestions = token.InputType == InputType.Files; string allowedFileExtensionGlobPattern = null; if (token.Files?.AllowedFileExtension != null) { allowedFileExtensionGlobPattern = token.Files.AllowedFileExtension.StartsWith("*.") ? token.Files.AllowedFileExtension : $"*.{token.Files.AllowedFileExtension}"; } var hints = new List <Hint>(); if (token.InputType == InputType.Hints) { hints.AddRange(token.Values.Select(value => new Hint() { Name = value, HintColor = ConsoleColor.DarkGray })); } var console = new FlubuConsole(hints, options: o => { o.WritePrompt = false; o.InitialText = initialText; o.InitialHelp = token.Help; o.OnlyDirectoriesSuggestions = directoryAndFilesSuggestions; o.IncludeFileSuggestions = directoryAndFilesSuggestions; o.FileSuggestionsSearchPattern = allowedFileExtensionGlobPattern; o.DefaultSuggestion = token.DefaultValue; }); bool isRightFileExtension = true; string newValue; do { newValue = console.ReadLine().Trim(); if (!string.IsNullOrEmpty(allowedFileExtensionGlobPattern)) { isRightFileExtension = CheckFileExtension(newValue, allowedFileExtensionGlobPattern); } }while (!isRightFileExtension); if (!string.IsNullOrEmpty(newValue)) { replacementTokens.Add(new Tuple <string, string>(token.Token, newValue)); } break; } } } } return(replacementTokens); }