Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/9.0.2xx] fix(cli): dotnet help new link opening #45404

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; }
}
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
Loading