Skip to content

Commit eac1a57

Browse files
CopilotAArnott
andcommitted
Add --what-if switch to nbgv tag command
Co-authored-by: AArnott <[email protected]>
1 parent b9aaf4f commit eac1a57

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/nbgv/Program.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,23 @@ private static RootCommand BuildCommandLine()
206206
DefaultValueFactory = _ => DefaultRef,
207207
Arity = ArgumentArity.ZeroOrOne,
208208
};
209+
var whatIf = new Option<bool>("--what-if")
210+
{
211+
Description = "Calculates and outputs the tag name without creating the tag.",
212+
};
209213
tag = new Command("tag", "Creates a git tag to mark a version.")
210214
{
211215
project,
212216
versionOrRef,
217+
whatIf,
213218
};
214219

215220
tag.SetAction(async (ParseResult parseResult, CancellationToken cancellationToken) =>
216221
{
217222
var projectValue = parseResult.GetValue(project);
218223
var versionOrRefValue = parseResult.GetValue(versionOrRef);
219-
return await OnTagCommand(projectValue, versionOrRefValue);
224+
var whatIfValue = parseResult.GetValue(whatIf);
225+
return await OnTagCommand(projectValue, versionOrRefValue, whatIfValue);
220226
});
221227
}
222228

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

726-
private static Task<int> OnTagCommand(string project, string versionOrRef)
732+
private static Task<int> OnTagCommand(string project, string versionOrRef, bool whatIf)
727733
{
728734
if (string.IsNullOrEmpty(versionOrRef))
729735
{
@@ -803,6 +809,13 @@ private static Task<int> OnTagCommand(string project, string versionOrRef)
803809
// replace the "{version}" placeholder with the actual version
804810
string tagName = tagNameFormat.Replace("{version}", oracle.SemVer2);
805811

812+
if (whatIf)
813+
{
814+
// In what-if mode, just output the tag name and exit
815+
Console.WriteLine(tagName);
816+
return Task.FromResult((int)ExitCodes.OK);
817+
}
818+
806819
try
807820
{
808821
context.ApplyTag(tagName);

0 commit comments

Comments
 (0)