Skip to content

Commit 1b0a6ee

Browse files
authored
fix(cli): dotnet help new link opening (#45282)
1 parent b09e142 commit 1b0a6ee

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
6+
namespace Microsoft.TemplateEngine.Cli.Commands;
7+
8+
/// <summary>
9+
/// If a <see cref="CliCommand"/> implements this interface, it can open
10+
/// its documentation page online.
11+
/// </summary>
12+
public interface ICommandDocument
13+
{
14+
/// <summary>
15+
/// The URL to the documentation page for this command.
16+
/// </summary>
17+
string DocsLink { get; }
18+
}

src/Cli/Microsoft.TemplateEngine.Cli/Commands/NewCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Microsoft.TemplateEngine.Cli.Commands
1010
{
11-
internal partial class NewCommand : BaseCommand<NewCommandArgs>, ICustomHelp
11+
internal partial class NewCommand : BaseCommand<NewCommandArgs>, ICustomHelp, ICommandDocument
1212
{
1313
internal NewCommand(
1414
string commandName,
@@ -44,6 +44,8 @@ internal NewCommand(
4444
Options.Add(SharedOptions.ProjectPathOption);
4545
}
4646

47+
public string DocsLink { get; } = "https://aka.ms/dotnet-new";
48+
4749
internal static CliOption<string?> DebugCustomSettingsLocationOption { get; } = new("--debug:custom-hive")
4850
{
4951
Description = SymbolStrings.Option_Debug_CustomSettings,

src/Cli/dotnet/DocumentedCommand.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.CommandLine;
5+
using Microsoft.TemplateEngine.Cli.Commands;
56

67
namespace Microsoft.DotNet.Cli
78
{
8-
public class DocumentedCommand : CliCommand
9+
public class DocumentedCommand : CliCommand, ICommandDocument
910
{
10-
public string DocsLink { get; set; }
11+
public string DocsLink { get; }
1112

1213
public DocumentedCommand(string name, string docsLink, string description = null) : base(name, description)
1314
{

src/Cli/dotnet/commands/dotnet-help/HelpCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics;
66
using Microsoft.DotNet.Cli;
77
using Microsoft.DotNet.Cli.Utils;
8+
using Microsoft.TemplateEngine.Cli.Commands;
89

910
namespace Microsoft.DotNet.Tools.Help
1011
{
@@ -101,7 +102,7 @@ public int Execute()
101102
private bool TryGetDocsLink(string[] command, out string docsLink)
102103
{
103104
var parsedCommand = Parser.Instance.Parse(["dotnet", .. command]);
104-
if (parsedCommand?.CommandResult?.Command is DocumentedCommand dc)
105+
if (parsedCommand?.CommandResult?.Command is ICommandDocument dc)
105106
{
106107
docsLink = dc.DocsLink;
107108
return true;

0 commit comments

Comments
 (0)