From c560e9af3cdaffb03623bfbf22e84abe7bae1fee Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Thu, 24 Mar 2016 15:36:58 -0500 Subject: [PATCH] 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 --- scripts/dotnet-cli-build/CompileTargets.cs | 23 +++++++++++++++++-- src/dotnet/Program.cs | 16 ++++++++++--- src/dotnet/README.md | 6 ++++- .../commands/dotnet-help/HelpCommand.cs | 3 ++- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/scripts/dotnet-cli-build/CompileTargets.cs b/scripts/dotnet-cli-build/CompileTargets.cs index bd3e32265..ef3b6e976 100644 --- a/scripts/dotnet-cli-build/CompileTargets.cs +++ b/scripts/dotnet-cli-build/CompileTargets.cs @@ -78,8 +78,7 @@ namespace Microsoft.DotNet.Cli.Build var configuration = c.BuildContext.Get("Configuration"); // Run the build - string version = DotNetCli.Stage0.Exec("", "--version").CaptureStdOut().Execute().StdOut; - string rid = Array.Find(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(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(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) { diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 1bb50e714..2b83d6e83 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -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) diff --git a/src/dotnet/README.md b/src/dotnet/README.md index a13b1352f..cb612264f 100644 --- a/src/dotnet/README.md +++ b/src/dotnet/README.md @@ -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. diff --git a/src/dotnet/commands/dotnet-help/HelpCommand.cs b/src/dotnet/commands/dotnet-help/HelpCommand.cs index 8d6ea5e29..3f46d87eb 100644 --- a/src/dotnet/commands/dotnet-help/HelpCommand.cs +++ b/src/dotnet/commands/dotnet-help/HelpCommand.cs @@ -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