Skip to content

Commit

Permalink
fix(cli): dotnet help new link opening (#45282)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpinedam authored Dec 10, 2024
1 parent b09e142 commit 1b0a6ee
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/Cli/Microsoft.TemplateEngine.Cli/Commands/ICommandDocument.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;

namespace Microsoft.TemplateEngine.Cli.Commands;

/// <summary>
/// If a <see cref="CliCommand"/> implements this interface, it can open
/// its documentation page online.
/// </summary>
public interface ICommandDocument
{
/// <summary>
/// The URL to the documentation page for this command.
/// </summary>
string DocsLink { get; }
}
4 changes: 3 additions & 1 deletion src/Cli/Microsoft.TemplateEngine.Cli/Commands/NewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Microsoft.TemplateEngine.Cli.Commands
{
internal partial class NewCommand : BaseCommand<NewCommandArgs>, ICustomHelp
internal partial class NewCommand : BaseCommand<NewCommandArgs>, ICustomHelp, ICommandDocument
{
internal NewCommand(
string commandName,
Expand Down Expand Up @@ -44,6 +44,8 @@ internal NewCommand(
Options.Add(SharedOptions.ProjectPathOption);
}

public string DocsLink { get; } = "https://aka.ms/dotnet-new";

internal static CliOption<string?> DebugCustomSettingsLocationOption { get; } = new("--debug:custom-hive")
{
Description = SymbolStrings.Option_Debug_CustomSettings,
Expand Down
5 changes: 3 additions & 2 deletions src/Cli/dotnet/DocumentedCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using Microsoft.TemplateEngine.Cli.Commands;

namespace Microsoft.DotNet.Cli
{
public class DocumentedCommand : CliCommand
public class DocumentedCommand : CliCommand, ICommandDocument
{
public string DocsLink { get; set; }
public string DocsLink { get; }

public DocumentedCommand(string name, string docsLink, string description = null) : base(name, description)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Cli/dotnet/commands/dotnet-help/HelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.TemplateEngine.Cli.Commands;

namespace Microsoft.DotNet.Tools.Help
{
Expand Down Expand Up @@ -101,7 +102,7 @@ public int Execute()
private bool TryGetDocsLink(string[] command, out string docsLink)
{
var parsedCommand = Parser.Instance.Parse(["dotnet", .. command]);
if (parsedCommand?.CommandResult?.Command is DocumentedCommand dc)
if (parsedCommand?.CommandResult?.Command is ICommandDocument dc)
{
docsLink = dc.DocsLink;
return true;
Expand Down

0 comments on commit 1b0a6ee

Please sign in to comment.