Skip to content

Commit

Permalink
Add setclrpath command to dotnet-dump on linux. Mentioned in dotnet#624
Browse files Browse the repository at this point in the history
  • Loading branch information
mikem8361 committed Dec 12, 2019
1 parent 3963bcf commit 484555a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
24 changes: 0 additions & 24 deletions src/Microsoft.Diagnostics.Repl/Command/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Runtime.InteropServices;

namespace Microsoft.Diagnostics.Repl
{
Expand Down Expand Up @@ -44,29 +43,6 @@ public class CommandBaseAttribute : BaseAttribute
/// Optional OS platform for the command
/// </summary>
public CommandPlatform Platform = CommandPlatform.All;

/// <summary>
/// Returns true if the command should be added.
/// </summary>
public bool IsValidPlatform()
{
if (Platform != CommandPlatform.All)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return (Platform & CommandPlatform.Windows) != 0;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return (Platform & CommandPlatform.Linux) != 0;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return (Platform & CommandPlatform.OSX) != 0;
}
}
return true;
}
}

/// <summary>
Expand Down
28 changes: 26 additions & 2 deletions src/Microsoft.Diagnostics.Repl/Command/CommandProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace Microsoft.Diagnostics.Repl
Expand Down Expand Up @@ -116,7 +117,7 @@ private void BuildCommands(CommandLineBuilder rootBuilder, Type type)
{
if (baseAttribute is CommandAttribute commandAttribute)
{
if (commandAttribute.IsValidPlatform())
if (IsValidPlatform(commandAttribute))
{
command = new Command(commandAttribute.Name, commandAttribute.Help);
var properties = new List<(PropertyInfo, Option)>();
Expand Down Expand Up @@ -172,7 +173,7 @@ private void BuildCommands(CommandLineBuilder rootBuilder, Type type)

if (baseAttribute is CommandAliasAttribute commandAliasAttribute)
{
if (commandAliasAttribute.IsValidPlatform())
if (IsValidPlatform(commandAliasAttribute))
{
if (command == null)
{
Expand All @@ -196,6 +197,29 @@ private T GetService<T>()
return service;
}

/// <summary>
/// Returns true if the command should be added.
/// </summary>
private static bool IsValidPlatform(CommandBaseAttribute attribute)
{
if (attribute.Platform != CommandPlatform.All)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return (attribute.Platform & CommandPlatform.Windows) != 0;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return (attribute.Platform & CommandPlatform.Linux) != 0;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return (attribute.Platform & CommandPlatform.OSX) != 0;
}
}
return true;
}

private static string BuildAlias(string parameterName)
{
if (string.IsNullOrWhiteSpace(parameterName)) {
Expand Down

0 comments on commit 484555a

Please sign in to comment.