Changing --version in the CLI
`dotnet --version` returns just the version number. This helps tools get this information without having to parse the full info. Introduce a new argument `--info` that returns the current "long form". With this, we also change the long form to say "RID" instead of "Runtime ID" simply because that would avoid any future localization issues and thus make the parsing easier. Fix #1607 #1882
This commit is contained in:
parent
f0fd9ae901
commit
c560e9af3c
4 changed files with 41 additions and 7 deletions
|
@ -78,8 +78,7 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
var configuration = c.BuildContext.Get<string>("Configuration");
|
||||
|
||||
// Run the build
|
||||
string version = DotNetCli.Stage0.Exec("", "--version").CaptureStdOut().Execute().StdOut;
|
||||
string rid = Array.Find<string>(version.Split(Environment.NewLine.ToCharArray()), (e) => e.Contains("Runtime Id:")).Replace("Runtime Id:", "").Trim();
|
||||
string rid = GetRuntimeId();
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
// Why does Windows directly call cmake but Linux/Mac calls "build.sh" in the corehost dir?
|
||||
|
@ -134,6 +133,26 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
return c.Success();
|
||||
}
|
||||
|
||||
private static string GetRuntimeId()
|
||||
{
|
||||
string info = DotNetCli.Stage0.Exec("", "--info").CaptureStdOut().Execute().StdOut;
|
||||
string rid = Array.Find<string>(info.Split(Environment.NewLine.ToCharArray()), (e) => e.Contains("RID:"))?.Replace("RID:", "").Trim();
|
||||
|
||||
// TODO: when Stage0 is updated with the new --info, remove this legacy check for --version
|
||||
if (string.IsNullOrEmpty(rid))
|
||||
{
|
||||
string version = DotNetCli.Stage0.Exec("", "--version").CaptureStdOut().Execute().StdOut;
|
||||
rid = Array.Find<string>(version.Split(Environment.NewLine.ToCharArray()), (e) => e.Contains("Runtime Id:")).Replace("Runtime Id:", "").Trim();
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(rid))
|
||||
{
|
||||
throw new BuildFailureException("Could not find the Runtime ID from Stage0 --info or --version");
|
||||
}
|
||||
|
||||
return rid;
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult CompileStage1(BuildTargetContext c)
|
||||
{
|
||||
|
|
|
@ -61,7 +61,12 @@ namespace Microsoft.DotNet.Cli
|
|||
}
|
||||
else if (IsArg(args[lastArg], "version"))
|
||||
{
|
||||
PrintVersionInfo();
|
||||
PrintVersion();
|
||||
return 0;
|
||||
}
|
||||
else if (IsArg(args[lastArg], "info"))
|
||||
{
|
||||
PrintInfo();
|
||||
return 0;
|
||||
}
|
||||
else if (IsArg(args[lastArg], "h", "help"))
|
||||
|
@ -129,7 +134,12 @@ namespace Microsoft.DotNet.Cli
|
|||
.ExitCode;
|
||||
}
|
||||
|
||||
private static void PrintVersionInfo()
|
||||
private static void PrintVersion()
|
||||
{
|
||||
Reporter.Output.WriteLine(HelpCommand.ProductVersion);
|
||||
}
|
||||
|
||||
private static void PrintInfo()
|
||||
{
|
||||
HelpCommand.PrintVersionHeader();
|
||||
|
||||
|
@ -144,7 +154,7 @@ namespace Microsoft.DotNet.Cli
|
|||
Reporter.Output.WriteLine($" OS Name: {runtimeEnvironment.OperatingSystem}");
|
||||
Reporter.Output.WriteLine($" OS Version: {runtimeEnvironment.OperatingSystemVersion}");
|
||||
Reporter.Output.WriteLine($" OS Platform: {runtimeEnvironment.OperatingSystemPlatform}");
|
||||
Reporter.Output.WriteLine($" Runtime Id: {runtimeEnvironment.GetRuntimeIdentifier()}");
|
||||
Reporter.Output.WriteLine($" RID: {runtimeEnvironment.GetRuntimeIdentifier()}");
|
||||
}
|
||||
|
||||
private static bool IsArg(string candidate, string longName)
|
||||
|
|
|
@ -8,7 +8,7 @@ dotnet -- general driver for running the command-line commands
|
|||
|
||||
# SYNOPSIS
|
||||
|
||||
dotnet [--version] [--help] [--verbose] < command > [< args >]
|
||||
dotnet [--version] [--info] [--help] [--verbose] < command > [< args >]
|
||||
|
||||
# DESCRIPTION
|
||||
dotnet is a generic driver for the CLI toolchain. Invoked on its own, it will give out brief usage instructions.
|
||||
|
@ -25,6 +25,10 @@ Each specific feature is implemented as a command. In order to use the feature,
|
|||
|
||||
Print out the version of the CLI tooling
|
||||
|
||||
`--info`
|
||||
|
||||
Print out information about the CLI tooling
|
||||
|
||||
`-h, --help`
|
||||
|
||||
Print out a short help and a list of current commands.
|
||||
|
|
|
@ -17,7 +17,8 @@ Arguments:
|
|||
|
||||
Common Options (passed before the command):
|
||||
-v|--verbose Enable verbose output
|
||||
--version Display .NET CLI Version Info
|
||||
--version Display .NET CLI Version Number
|
||||
--info Display .NET CLI Info
|
||||
|
||||
Common Commands:
|
||||
new Initialize a basic .NET project
|
||||
|
|
Loading…
Add table
Reference in a new issue