Skip to content

stop using System.CommandLine types that aren't public anymore #49181

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
<SystemDataSqlClientPackageVersion>4.8.6</SystemDataSqlClientPackageVersion>
<StyleCopAnalyzersPackageVersion>1.2.0-beta.435</StyleCopAnalyzersPackageVersion>
<WebDeploymentPackageVersion>4.0.5</WebDeploymentPackageVersion>
<SystemCommandLineVersion>2.0.0-beta5.25265.101</SystemCommandLineVersion>
<SystemCommandLineNamingConventionBinderVersion>2.0.0-beta5.25227.101</SystemCommandLineNamingConventionBinderVersion>
<SystemCommandLineVersion>2.0.0-beta5.25279.2</SystemCommandLineVersion>
<SystemCommandLineNamingConventionBinderVersion>2.0.0-beta5.25279.2</SystemCommandLineNamingConventionBinderVersion>
<MicrosoftCodeAnalysisAnalyzerTestingVersion>1.1.2-beta1.22216.1</MicrosoftCodeAnalysisAnalyzerTestingVersion>
<MicrosoftVisualBasicVersion>10.3.0</MicrosoftVisualBasicVersion>
<MicrosoftVisualStudioSetupConfigurationInteropVersion>3.2.2146</MicrosoftVisualStudioSetupConfigurationInteropVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using System.CommandLine.Help;
using System.CommandLine.Parsing;
using Microsoft.TemplateEngine.Abstractions;
using Microsoft.TemplateEngine.Cli.Commands;
using Microsoft.TemplateEngine.Cli.Help;
using Microsoft.TemplateEngine.Utils;

namespace Microsoft.TemplateEngine.Cli
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using System.CommandLine.Help;
using System.CommandLine.Parsing;
using System.Diagnostics;
using System.Globalization;
using Microsoft.TemplateEngine.Abstractions;
using Microsoft.TemplateEngine.Cli.Commands;
using Microsoft.TemplateEngine.Cli.Help;

namespace Microsoft.TemplateEngine.Cli
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

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

namespace Microsoft.TemplateEngine.Cli.Commands
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// 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.Help;
using Microsoft.TemplateEngine.Abstractions;
using Microsoft.TemplateEngine.Cli.Help;

namespace Microsoft.TemplateEngine.Cli.Commands
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using System.CommandLine.Help;
using System.Diagnostics.CodeAnalysis;
using System.Resources;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.TemplateEngine.Abstractions;
using Microsoft.TemplateEngine.Cli.Help;
using Microsoft.TemplateEngine.Edge.Settings;
using Microsoft.TemplateEngine.Utils;
using Command = System.CommandLine.Command;
Expand All @@ -16,8 +15,6 @@ namespace Microsoft.TemplateEngine.Cli.Commands
internal partial class InstantiateCommand
{
private const string Indent = " ";
private static Lazy<ResourceManager> _resourceManager = new(
() => new ResourceManager("System.CommandLine.Properties.Resources", typeof(System.CommandLine.Symbol).Assembly));

public static void WriteHelp(HelpContext context, InstantiateCommandArgs instantiateCommandArgs, IEngineEnvironmentSettings environmentSettings)
{
Expand Down Expand Up @@ -328,7 +325,7 @@ internal static void ShowCommandOptions(
cliOption.EnsureHelpName();
}

context.Output.WriteLine(HelpOptionsTitle());
context.Output.WriteLine(LocalizationResources.HelpOptionsTitle());
IEnumerable<TwoColumnHelpRow> optionsToWrite = optionsToShow.Select(o => context.HelpBuilder.GetTwoColumnRow(o, context));
context.HelpBuilder.WriteColumns(optionsToWrite.ToArray(), context);
context.Output.WriteLine();
Expand Down Expand Up @@ -381,14 +378,14 @@ internal static void ShowUsage(Command? command, IReadOnlyList<string> shortName
}

usageParts.Reverse();
context.Output.WriteLine(HelpUsageTitle());
context.Output.WriteLine(LocalizationResources.HelpUsageTitle());
foreach (string shortName in shortNames)
{
IEnumerable<string> parts = usageParts.Concat(
new[]
{
shortName,
HelpUsageOptions(),
LocalizationResources.HelpUsageOptions(),
HelpStrings.Text_UsageTemplateOptionsPart
});
context.Output.WriteLine(Indent + string.Join(" ", parts));
Expand Down Expand Up @@ -463,7 +460,7 @@ private static void WriteCustomInstantiateHelp(HelpContext context, Command comm

private static void CustomUsageSection(HelpContext context, Command command)
{
context.Output.WriteLine(HelpUsageTitle());
context.Output.WriteLine(LocalizationResources.HelpUsageTitle());
context.Output.WriteLine(Indent + string.Join(" ", GetCustomUsageParts(context, command, showSubcommands: false)));

if (command is NewCommand)
Expand Down Expand Up @@ -499,21 +496,13 @@ private static IEnumerable<string> GetCustomUsageParts(

if (showSubcommands)
{
yield return HelpUsageCommand();
yield return LocalizationResources.HelpUsageCommand();
}

if (showOptions)
{
yield return HelpUsageOptions();
yield return LocalizationResources.HelpUsageOptions();
}
}

private static string HelpUsageOptions() => _resourceManager.Value.GetString("HelpUsageOptions")!;

private static string HelpUsageCommand() => _resourceManager.Value.GetString("HelpUsageCommand")!;

private static string HelpUsageTitle() => _resourceManager.Value.GetString("HelpUsageTitle")!;

private static string HelpOptionsTitle() => _resourceManager.Value.GetString("HelpOptionsTitle")!;
}
}
41 changes: 41 additions & 0 deletions src/Cli/Microsoft.TemplateEngine.Cli/Help/DotnetHelpAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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;
using System.CommandLine.Invocation;

namespace Microsoft.TemplateEngine.Cli.Help
{
/// <summary>
/// Provides command line help.
/// </summary>
public sealed class DotnetHelpAction : SynchronousCommandLineAction
{
private HelpBuilder? _builder;

/// <summary>
/// Specifies an <see cref="Builder"/> to be used to format help output when help is requested.
/// </summary>
public HelpBuilder Builder
{
get => _builder ??= new HelpBuilder(Console.IsOutputRedirected ? int.MaxValue : Console.WindowWidth);
set => _builder = value ?? throw new ArgumentNullException(nameof(value));
}

/// <inheritdoc />
public override int Invoke(ParseResult parseResult)
{
var output = parseResult.Configuration.Output;

var helpContext = new HelpContext(
Builder,
parseResult.CommandResult.Command,
output,
parseResult);

Builder.Write(helpContext);

return 0;
}
}
}
Loading