Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/nbgv/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,23 @@ private static RootCommand BuildCommandLine()
DefaultValueFactory = _ => DefaultRef,
Arity = ArgumentArity.ZeroOrOne,
};
var whatIf = new Option<bool>("--what-if")
{
Description = "Calculates and outputs the tag name without creating the tag.",
};
tag = new Command("tag", "Creates a git tag to mark a version.")
{
project,
versionOrRef,
whatIf,
};

tag.SetAction(async (ParseResult parseResult, CancellationToken cancellationToken) =>
{
var projectValue = parseResult.GetValue(project);
var versionOrRefValue = parseResult.GetValue(versionOrRef);
return await OnTagCommand(projectValue, versionOrRefValue);
var whatIfValue = parseResult.GetValue(whatIf);
return await OnTagCommand(projectValue, versionOrRefValue, whatIfValue);
});
}

Expand Down Expand Up @@ -723,7 +729,7 @@ private static Task<int> OnSetVersionCommand(string project, string version)
return Task.FromResult((int)ExitCodes.OK);
}

private static Task<int> OnTagCommand(string project, string versionOrRef)
private static Task<int> OnTagCommand(string project, string versionOrRef, bool whatIf)
{
if (string.IsNullOrEmpty(versionOrRef))
{
Expand Down Expand Up @@ -803,6 +809,13 @@ private static Task<int> OnTagCommand(string project, string versionOrRef)
// replace the "{version}" placeholder with the actual version
string tagName = tagNameFormat.Replace("{version}", oracle.SemVer2);

if (whatIf)
{
// In what-if mode, just output the tag name and exit
Console.WriteLine(tagName);
return Task.FromResult((int)ExitCodes.OK);
}

try
{
context.ApplyTag(tagName);
Expand Down
Loading