public XPatchOptions Parse(params string[] args)
        {
            var options = new XPatchOptions();
            var commandLineParser = new CommandLineParser();

            var helpWriter = new StringWriter();
            if (commandLineParser.ParseArguments(args, options, helpWriter)
                && options.Values.Count >= 2)
            {
                options.XmlFile = options.Values[0];
                options.XPathExpression = options.Values[1];

                if (options.Values.Count == 3)
                    options.NewValue = options.Values[2];
            }
            else
            {
                options.Invalid = true;
            }

            return options;
        }
Example #2
0
        public bool Run(XPatchOptions options)
        {
            BasicConfigurator.Configure(new XPatchConsoleAppender(_console));
            LogManager.GetRepository().Threshold = MapLevel(options.LogLevel);

            if (!options.NoLogo)
            {
                _console.Write(BuildLogo());
            }

            if (options.ShowHelp)
            {
                _console.Write(options.GetHelp());
                return true;
            }

            if (options.Invalid)
            {
                _console.Error("Ungültige Parameter! 'xpatch -?' zeigt die Hilfe an.");
                return false;
            }

            string newValue = options.NewValue
                                ?? _console.Prompt(
                                    string.Format("Neuer Wert für '{0}': ",
                                                options.XPathExpression));

            try
            {
                _patcher.Patch(options.XmlFile, options.XPathExpression, newValue);
                return true;
            }
            catch (Exception e)
            {
                _log.Error("Bei der Ausführung ist ein Fehler aufgetreten!", e);
                return false;
            }
        }