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
19 changes: 15 additions & 4 deletions src/nbgv/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ private static RootCommand BuildCommandLine()
{
Description = "The name of just one version property to print to stdout. When specified, the output is always in raw text. Useful in scripts.",
};
var publicRelease = new Option<bool?>("--public-release")
{
Description = "Specifies whether this is a public release. When specified, overrides the PublicRelease environment variable. Use --public-release=true or --public-release=false to explicitly set the value.",
Arity = ArgumentArity.ZeroOrOne,
};
var commit = new Argument<string>("commit-ish")
{
Description = $"The commit/ref to get the version information for.",
Expand All @@ -158,6 +163,7 @@ private static RootCommand BuildCommandLine()
metadata,
format,
variable,
publicRelease,
commit,
};

Expand All @@ -167,8 +173,9 @@ private static RootCommand BuildCommandLine()
var metadataValue = parseResult.GetValue(metadata);
var formatValue = parseResult.GetValue(format);
var variableValue = parseResult.GetValue(variable);
var publicReleaseValue = parseResult.GetValue(publicRelease);
var commitValue = parseResult.GetValue(commit);
return await OnGetVersionCommand(projectValue, metadataValue, formatValue, variableValue, commitValue);
return await OnGetVersionCommand(projectValue, metadataValue, formatValue, variableValue, publicReleaseValue, commitValue);
});
}

Expand Down Expand Up @@ -576,7 +583,7 @@ private static async Task<int> OnInstallCommand(string path, string version, str
return (int)ExitCodes.OK;
}

private static Task<int> OnGetVersionCommand(string project, string[] metadata, string format, string variable, string commitish)
private static Task<int> OnGetVersionCommand(string project, string[] metadata, string format, string variable, bool? publicReleaseArg, string commitish)
{
if (string.IsNullOrEmpty(format))
{
Expand Down Expand Up @@ -609,8 +616,12 @@ private static Task<int> OnGetVersionCommand(string project, string[] metadata,
oracle.BuildMetadata.AddRange(metadata);
}

// Take the PublicRelease environment variable into account, since the build would as well.
if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("PublicRelease")) && bool.TryParse(Environment.GetEnvironmentVariable("PublicRelease"), out bool publicRelease))
// Set PublicRelease - prioritize command line argument over environment variable
if (publicReleaseArg.HasValue)
{
oracle.PublicRelease = publicReleaseArg.Value;
}
else if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("PublicRelease")) && bool.TryParse(Environment.GetEnvironmentVariable("PublicRelease"), out bool publicRelease))
{
oracle.PublicRelease = publicRelease;
}
Expand Down
Loading