コード例 #1
0
        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;
        }
コード例 #2
0
        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;
        }
コード例 #3
0
ファイル: CommandExecutor.cs プロジェクト: cheneddy/FlubuCore
        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);
        }
コード例 #4
0
        protected virtual FlubuConsole InitializeFlubuConsole(IFlubuSession flubuSession, IBuildScript script)
        {
            var source       = new Dictionary <string, IReadOnlyCollection <Hint> >();
            var propertyKeys = _scriptProperties.GetPropertiesHints(script);

            propertyKeys.Add(new Hint {
                Name = "--parallel", Help = "If applied target's are executed in parallel.", HintColor = ConsoleColor.Magenta
            });
            propertyKeys.Add(new Hint {
                Name = "--dryrun", Help = "Performs a dry run of the specified target.", HintColor = ConsoleColor.Magenta
            });
            propertyKeys.Add(new Hint {
                Name = "--noColor", Help = "Disables colored logging.", HintColor = ConsoleColor.Magenta
            });
            propertyKeys.Add(new Hint {
                Name = "--nodeps", Help = "If applied no target dependencies are executed.", HintColor = ConsoleColor.Magenta
            });
            source.Add("-", propertyKeys);
            var enumHints = _scriptProperties.GetEnumHints(script, flubuSession);

            if (enumHints != null)
            {
                source.AddRange(enumHints);
            }

            List <Hint> defaultHints = new List <Hint>();

            if (script is DefaultBuildScript defaultBuildScript)
            {
                defaultBuildScript.ConfigureDefaultProps(flubuSession);
                defaultBuildScript.ConfigureBuildPropertiesInternal(flubuSession);
                defaultBuildScript.ConfigureTargetsInternal(flubuSession);
            }

            foreach (var targetName in flubuSession.TargetTree.GetTargetNames())
            {
                var target = flubuSession.TargetTree.GetTarget(targetName);
                defaultHints.Add(new Hint
                {
                    Name = target.TargetName,
                    Help = target.Description
                });
            }

            var flubuConsole = new FlubuConsole(flubuSession.TargetTree, defaultHints, source);

            return(flubuConsole);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }