Skip to content

Commit 5331567

Browse files
authored
Add "dotnet dnx" command as alias for "dotnet tool execute" (#49425)
2 parents cfc10c5 + 210c02b commit 5331567

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

src/Cli/Microsoft.TemplateEngine.Cli/Help/HelpBuilder.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ public virtual void Write(HelpContext context)
4343
throw new ArgumentNullException(nameof(context));
4444
}
4545

46-
if (context.Command.Hidden)
47-
{
48-
return;
49-
}
50-
5146
foreach (var writeSection in GetLayout(context))
5247
{
5348
if (writeSection(context))
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.CommandLine;
5+
using Microsoft.DotNet.Cli.Commands.Tool;
6+
using Microsoft.DotNet.Cli.Commands.Tool.Execute;
7+
8+
namespace Microsoft.DotNet.Cli.Commands.Dnx;
9+
10+
internal static class DnxCommandParser
11+
{
12+
public static readonly Command Command = ConstructCommand();
13+
public static Command GetCommand()
14+
{
15+
return Command;
16+
}
17+
18+
private static Command ConstructCommand()
19+
{
20+
Command command = new("dnx", CliCommandStrings.ToolExecuteCommandDescription);
21+
command.Hidden = true;
22+
23+
foreach (var argument in ToolExecuteCommandParser.Command.Arguments)
24+
{
25+
command.Arguments.Add(argument);
26+
}
27+
28+
foreach (var option in ToolExecuteCommandParser.Command.Options)
29+
{
30+
command.Options.Add(option);
31+
}
32+
33+
command.SetAction((parseResult) => new ToolExecuteCommand(parseResult).Execute());
34+
35+
return command;
36+
}
37+
}

src/Cli/dotnet/Parser.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.DotNet.Cli.Commands.Build;
1111
using Microsoft.DotNet.Cli.Commands.BuildServer;
1212
using Microsoft.DotNet.Cli.Commands.Clean;
13+
using Microsoft.DotNet.Cli.Commands.Dnx;
1314
using Microsoft.DotNet.Cli.Commands.Format;
1415
using Microsoft.DotNet.Cli.Commands.Fsi;
1516
using Microsoft.DotNet.Cli.Commands.Help;
@@ -66,6 +67,7 @@ public static class Parser
6667
BuildCommandParser.GetCommand(),
6768
BuildServerCommandParser.GetCommand(),
6869
CleanCommandParser.GetCommand(),
70+
DnxCommandParser.GetCommand(),
6971
FormatCommandParser.GetCommand(),
7072
CompleteCommandParser.GetCommand(),
7173
FsiCommandParser.GetCommand(),
@@ -313,12 +315,15 @@ public override void Write(HelpContext context)
313315
{
314316
var command = context.Command;
315317
var helpArgs = new string[] { "--help" };
318+
319+
// custom help overrides
316320
if (command.Equals(RootCommand))
317321
{
318322
Console.Out.WriteLine(CliUsage.HelpText);
319323
return;
320324
}
321325

326+
// argument/option cleanups specific to help
322327
foreach (var option in command.Options)
323328
{
324329
option.EnsureHelpName();

0 commit comments

Comments
 (0)