Ejemplo n.º 1
0
        public void Execute(string targetNumber, ISettings settings)
        {
            targetNumber = VariablesEngine.Expand(targetNumber, settings);
            Write("build number is ");
            WriteLine(targetNumber, T.HeadingTextColor);

            AzurePipelines.UpdateBuildNumber(targetNumber);
            ProcessUtils.ExecAndGetOutput("appveyor", $"UpdateBuild -Version {targetNumber}");
        }
Ejemplo n.º 2
0
        public void Execute(ISettings settings)
        {
            log.Info("{0} variables are supported:", VariablesEngine.SupportedVariableNames.Count);

            foreach (string variableName in VariablesEngine.SupportedVariableNames)
            {
                log.Info("  {0}: {1}", variableName, VariablesEngine.Expand($"%{variableName}%"));
            }
        }
Ejemplo n.º 3
0
        public void Execute(string commaSeparatedVariables, ISettings settings)
        {
            foreach (string rawName in commaSeparatedVariables.Split(',', StringSplitOptions.RemoveEmptyEntries))
            {
                string name  = rawName.Trim();
                string var   = $"{ExpressionParser.Delimiter}{name}{ExpressionParser.Delimiter}";
                string value = VariablesEngine.Expand(var, settings);

                AzurePipelines.SetVariable(name, value);
            }
        }
Ejemplo n.º 4
0
        private void Substitute(string filePath, ISettings settings)
        {
            log.Debug("processing {0}", filePath);

            log.Debug("reading {0}...", filePath);
            string content = File.ReadAllText(filePath);

            log.Debug("substituting...");
            content = VariablesEngine.Expand(content, settings);

            log.Debug("writing...");
            File.WriteAllText(filePath, content);
        }
        private void UpdateProperty(XmlDocument document, string name, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            value = VariablesEngine.Expand(value, _settings);

            log.Trace("{0} => {1}", name, value);

            log.Debug("searching for {0}...", name);
            string xPath = $"Project/PropertyGroup/{name}";

            XmlNodeList nodes = document.SelectNodes(xPath);

            log.Debug("found {0} elements", nodes.Count);

            if (nodes.Count > 0)
            {
                XmlNode node     = nodes[0];
                string  oldValue = node.InnerText;

                if (oldValue == value)
                {
                    log.Debug("value hasn't changed from {0}", value);
                }
                else
                {
                    node.InnerText = value;
                    log.Debug("{0} => {1}", oldValue, value);
                }
            }
            else
            {
                XmlNodeList pgs = document.SelectNodes("Project/PropertyGroup");
                if (pgs.Count == 0)
                {
                    log.Debug("no PropertyGroup elements defined.");
                    return;
                }

                log.Debug("creating new node...");
                XmlNode container  = pgs[0];
                XmlNode newElement = document.CreateNode(XmlNodeType.Element, name, null);
                newElement.InnerText = value;
                container.AppendChild(newElement);
                log.Debug("node created and value set to {0}", value);
            }
        }
Ejemplo n.º 6
0
        public void Update(string path, ISettings settings)
        {
            log.Trace("loading {path}", path);
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(File.ReadAllText(path));

            log.Trace("searching for Package/Identity...");

            //ignore namespaces in xml
            XmlNode identityNode = xmlDoc.SelectSingleNode("*[local-name()='Package']/*[local-name()='Identity']");

            if (identityNode == null)
            {
                log.Debug("nothing found");
            }

            XmlAttribute versionAttribute = identityNode.Attributes["Version"];

            log.Trace("found version {version}", versionAttribute.Value);

            string targetVersion = settings.Get("AppxVersion");

            if (targetVersion != null)
            {
                targetVersion = VariablesEngine.Expand(targetVersion, settings);
            }
            if (targetVersion == null)
            {
                log.Trace("property 'AppxVersion' not found");
                return;
            }

            log.Trace("changing to {targetVersion}", targetVersion);
            versionAttribute.Value = targetVersion;

            xmlDoc.Save(path);
        }
Ejemplo n.º 7
0
        static int Main(string[] args)
        {
            var app = new NetBox.Terminal.App.Application(".NET Housework");
            LinePrimitive <bool> verbose = app.SharedOption <bool>("-v|--verbose", "print verbose output", false);

            app.OnBeforeExecuteCommand(cmd =>
            {
                L.Config
                .WriteTo.PoshConsole("{message}{error}", logProperties: false)
                .When.SeverityIsAtLeast(verbose ? LogSeverity.Verbose : LogSeverity.Information);
            });

            app.Command("echo", cmd =>
            {
                cmd.Description = Help.Command_Echo;
                LinePrimitive <string> expression = cmd.Argument <string>("expression", "expression to execute").Required();
                LinePrimitive <string> settings   = Settings(cmd);

                cmd.OnExecute(() =>
                {
                    Write(VariablesEngine.Expand(expression, Settings(settings)));
                });
            });

            app.Command("setbuildnumber", cmd =>
            {
                cmd.Description = Help.Command_setbuildnumber;
                LinePrimitive <string> number   = cmd.Argument <string>("number", "number to set").Required();
                LinePrimitive <string> settings = Settings(cmd);

                cmd.OnExecute(() =>
                {
                    new SetBuildNumberCommand().Execute(number, Settings(settings));
                });
            });

            app.Command("author", cmd =>
            {
                cmd.Description = Help.Command_author;
                LinePrimitive <string> input    = cmd.Argument <string>("input", Help.Argument_input).Required();
                LinePrimitive <string> settings = Settings(cmd);
                LinePrimitive <bool> recurse    = cmd.Option <bool>("-r|--recurse", Help.Option_recurse, true);

                cmd.OnExecute(() =>
                {
                    new AuthoringCommand().Execute(
                        FileSource.Search(input, recurse),
                        Settings(settings));
                });
            });


            app.Command("substitute", cmd =>
            {
                cmd.Description = Help.Command_author;
                LinePrimitive <string> input    = cmd.Argument <string>("input", Help.Argument_input).Required();
                LinePrimitive <string> settings = Settings(cmd);
                LinePrimitive <bool> recurse    = cmd.Option <bool>("-r|--recurse", Help.Option_recurse, true);

                cmd.OnExecute(() =>
                {
                    new SubstituteCommand().Execute(
                        FileSource.Search(input, recurse),
                        Settings(settings));
                });
            });

            app.Command("vars", cmd =>
            {
                cmd.Description = Help.Command_vars;

                LinePrimitive <string> settings = Settings(cmd);

                cmd.OnExecute(() => new VarsCommand().Execute(Settings(settings)));
            });

            app.Command("pushvars", cmd =>
            {
                cmd.Description = Help.Command_pushvars;

                LinePrimitive <string> names    = cmd.Argument <string>("names", "list of variable names, comma separated").Required();
                LinePrimitive <string> settings = Settings(cmd);

                cmd.OnExecute(() => new PushVarsCommand().Execute(names, Settings(settings)));
            });

            return(app.Execute());
        }
Ejemplo n.º 8
0
 public void Parse_no_variables()
 {
     Assert.Equal("none", VariablesEngine.Expand("none", null));
 }
Ejemplo n.º 9
0
 public void Parse_simple_variable()
 {
     Assert.Equal("y2020", VariablesEngine.Expand("y%date:yyyy%", null));
 }