예제 #1
0
        public override CommandFilterModel Filter(string[] args)
        {
            // Argument does not contain any information that can be used
            // to construct VersionUpdateCommand.
            if (args == null || args.Length == 0)
            {
                return(null);
            }

            var filteredArgs       = args;
            var versionUpdateModel = new VersionUpdateModel();

            // Extract the version update value, e.g. 0.1
            // TODO: Use observer (event) based trigger to notify information capture.
            filteredArgs = FilterArgs(filteredArgs, arg =>
            {
                if (arg.StartsWith("+") || arg.StartsWith("-"))
                {
                    versionUpdateModel.Increment     = arg.StartsWith("+");
                    versionUpdateModel.VersionUpdate = _assemblyVersionParser.Parse(arg.Substring(1));
                    return(true);
                }

                return(false);
            });

            // Extract the target value, e.g. fileVersion
            filteredArgs = FilterArgs(filteredArgs, arg =>
            {
                if (arg.StartsWith("-f"))
                {
                    versionUpdateModel.IsFileVersion = true;
                    return(true);
                }

                return(false);
            });

            // Extract the path value, e.g. Properties\AssemblyInfo.cs
            filteredArgs = FilterArgs(filteredArgs, arg =>
            {
                if (arg.StartsWith("-path="))
                {
                    versionUpdateModel.AssemblyInfoPath = arg.Substring("-path=".Length);
                    return(false);
                }

                return(false);
            });

            return(new CommandFilterModel
            {
                Command = new VersionUpdateCommand(versionUpdateModel, _assemblyVersionReaderFactory, _assemblyVersionWriterFactory),
                Args = filteredArgs
            });
        }
예제 #2
0
        private AssemblyVersion ParseVersion(string content, string pattern)
        {
            var match = Regex.Match(content, pattern, RegexOptions.Multiline);

            if (match == null || !match.Success)
            {
                throw new ApplicationException($"Unable to match the assembly version details with the pattern {pattern}");
            }

            return(_assemblyVersionParser.Parse(match.Groups["AssemblyVersion"].Value));
        }