public void DumpVersion(VersionCliArgs args) { var csProjXml = _fileDetector.FindAndLoadCsProj(args.CsProjFilePath); _fileParser.Load(csProjXml); if (args.OutputFormat == OutputFormat.Json) { var theOutput = new { Product = new { Name = ProductInfo.Name, Version = ProductInfo.Version }, CurrentVersion = _fileParser.Version, ProjectFile = _fileDetector.ResolvedCsProjFile, }; WriteJsonToStdout(theOutput); } else { Console.WriteLine("Project version is: {0}\t{1}", Environment.NewLine, _fileParser.Version); } }
internal static VersionCliArgs GetVersionBumpFromRemainingArgs(List <string> remainingArguments, OutputFormat outputFormat, bool doVcs, bool dryRunEnabled) { if (remainingArguments == null || !remainingArguments.Any()) { var msgEx = "No version bump specified, please specify one of:\n\tmajor | minor | patch | <specific version>"; // ReSharper disable once NotResolvedInText throw new ArgumentException(msgEx, "versionBump"); } var args = new VersionCliArgs { OutputFormat = outputFormat, DoVcs = doVcs, DryRun = dryRunEnabled }; var bump = VersionBump.Patch; foreach (var arg in remainingArguments) { if (Enum.TryParse(arg, true, out bump)) { break; } var ver = SemVer.FromString(arg); args.SpecificVersionToApply = ver.ToVersionString(); bump = VersionBump.Specific; } args.VersionBump = bump; return(args); }
public VersionInfo Execute(VersionCliArgs args) { if (!args.DryRun && args.DoVcs && !_vcsTool.IsVcsToolPresent()) { throw new OperationCanceledException( $"Unable to find the vcs tool {_vcsTool.ToolName()} in your path"); } if (!args.DryRun && args.DoVcs && !_vcsTool.IsRepositoryClean()) { throw new OperationCanceledException( "You currently have uncomitted changes in your repository, please commit these and try again"); } var csProjXml = _fileDetector.FindAndLoadCsProj(args.CsProjFilePath); _fileParser.Load(csProjXml); var semVer = SemVer.FromString(_fileParser.Version); semVer.Bump(args.VersionBump, args.SpecificVersionToApply); var newVersion = semVer.ToVersionString(); if (!args.DryRun) // if we are not in dry run mode, then we should go ahead { var patchedCsProjXml = _fileVersionPatcher.Patch( csProjXml, _fileParser.Version, newVersion ); _fileVersionPatcher.Flush( patchedCsProjXml, _fileDetector.ResolvedCsProjFile ); if (args.DoVcs) { // Run git commands _vcsTool.Commit(_fileDetector.ResolvedCsProjFile, $"v{newVersion}"); _vcsTool.Tag($"v{newVersion}"); } } var theOutput = new VersionInfo { Product = new ProductOutputInfo { Name = ProductInfo.Name, Version = ProductInfo.Version }, OldVersion = _fileParser.Version, NewVersion = newVersion, ProjectFile = _fileDetector.ResolvedCsProjFile, VersionStrategy = args.VersionBump.ToString().ToLowerInvariant() }; if (args.OutputFormat == OutputFormat.Json) { WriteJsonToStdout(theOutput); } else { Console.WriteLine($"Bumped {_fileDetector.ResolvedCsProjFile} to version {newVersion}"); } return(theOutput); }