Skip to content

Commit

Permalink
Print version only for the version command (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
premun authored May 20, 2022
1 parent 6e87004 commit 9cacd2f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Mono.Options;

Expand All @@ -12,12 +13,19 @@ public XHarnessVersionCommand() : base("version") { }

public override int Invoke(IEnumerable<string> arguments)
{
var version = GetAssemblyVersion();

if (!arguments.Contains("-v"))
{
Console.WriteLine(version.ProductVersion);
return 0;
}

// Print the name of the tool and the version number unix style
// Example:
// Apple clang version 11.0.3 (clang-1103.0.32.29)
// Target: x86_64-apple-darwin19.4.0
// InstalledDir: /Applications/Xcode114.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
var version = GetAssemblyVersion();
Console.WriteLine($"XHarness version {version.ProductVersion} ({version.OriginalFilename})");
Console.WriteLine($"InstalledDir: {version.FileName}");
return 0;
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.DotNet.XHarness.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public static CommandSet GetXHarnessCommandSet()
/// </summary>
private static bool IsOutputSensitive(string[] args)
{
if (args.Length > 0 && args[0] == "version")
{
return true;
}

if (args.Length < 2 || args.Contains("--help") || args.Contains("-h"))
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public XHarnessConsoleLoggerFormatter(IOptionsMonitor<SimpleConsoleFormatterOpti
_newLineWithMessagePadding = Environment.NewLine + _messagePadding;
}

public override void Write<TState>(in LogEntry<TState> logEntry, IExternalScopeProvider scopeProvider, TextWriter textWriter)
public override void Write<TState>(in LogEntry<TState> logEntry, IExternalScopeProvider? scopeProvider, TextWriter textWriter)
{
if (logEntry.Formatter == null)
{
Expand Down

0 comments on commit 9cacd2f

Please sign in to comment.