diff --git a/src/Cli/Microsoft.TemplateEngine.Cli/Commands/ICommandDocument.cs b/src/Cli/Microsoft.TemplateEngine.Cli/Commands/ICommandDocument.cs new file mode 100644 index 000000000000..2af15b6d0c20 --- /dev/null +++ b/src/Cli/Microsoft.TemplateEngine.Cli/Commands/ICommandDocument.cs @@ -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; + +/// +/// If a implements this interface, it can open +/// its documentation page online. +/// +public interface ICommandDocument +{ + /// + /// The URL to the documentation page for this command. + /// + string DocsLink { get; } +} diff --git a/src/Cli/Microsoft.TemplateEngine.Cli/Commands/NewCommand.cs b/src/Cli/Microsoft.TemplateEngine.Cli/Commands/NewCommand.cs index 62444b8c13d2..d94840fe09d5 100644 --- a/src/Cli/Microsoft.TemplateEngine.Cli/Commands/NewCommand.cs +++ b/src/Cli/Microsoft.TemplateEngine.Cli/Commands/NewCommand.cs @@ -8,7 +8,7 @@ namespace Microsoft.TemplateEngine.Cli.Commands { - internal partial class NewCommand : BaseCommand, ICustomHelp + internal partial class NewCommand : BaseCommand, ICustomHelp, ICommandDocument { internal NewCommand( string commandName, @@ -44,6 +44,8 @@ internal NewCommand( Options.Add(SharedOptions.ProjectPathOption); } + public string DocsLink { get; } = "https://aka.ms/dotnet-new"; + internal static CliOption DebugCustomSettingsLocationOption { get; } = new("--debug:custom-hive") { Description = SymbolStrings.Option_Debug_CustomSettings, diff --git a/src/Cli/dotnet/DocumentedCommand.cs b/src/Cli/dotnet/DocumentedCommand.cs index 06e49c47126c..53b346eaf5ab 100644 --- a/src/Cli/dotnet/DocumentedCommand.cs +++ b/src/Cli/dotnet/DocumentedCommand.cs @@ -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) { diff --git a/src/Cli/dotnet/commands/dotnet-help/HelpCommand.cs b/src/Cli/dotnet/commands/dotnet-help/HelpCommand.cs index bb847901cc6b..8671bbd6eee2 100644 --- a/src/Cli/dotnet/commands/dotnet-help/HelpCommand.cs +++ b/src/Cli/dotnet/commands/dotnet-help/HelpCommand.cs @@ -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 { @@ -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;