Skip to content

Commit 1c12907

Browse files
authored
stop using System.CommandLine types that aren't public anymore (#49181)
1 parent 3c3f04f commit 1c12907

40 files changed

+1258
-209
lines changed

eng/Versions.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
<SystemDataSqlClientPackageVersion>4.8.6</SystemDataSqlClientPackageVersion>
6464
<StyleCopAnalyzersPackageVersion>1.2.0-beta.435</StyleCopAnalyzersPackageVersion>
6565
<WebDeploymentPackageVersion>4.0.5</WebDeploymentPackageVersion>
66-
<SystemCommandLineVersion>2.0.0-beta5.25265.101</SystemCommandLineVersion>
67-
<SystemCommandLineNamingConventionBinderVersion>2.0.0-beta5.25227.101</SystemCommandLineNamingConventionBinderVersion>
66+
<SystemCommandLineVersion>2.0.0-beta5.25279.2</SystemCommandLineVersion>
67+
<SystemCommandLineNamingConventionBinderVersion>2.0.0-beta5.25279.2</SystemCommandLineNamingConventionBinderVersion>
6868
<MicrosoftCodeAnalysisAnalyzerTestingVersion>1.1.2-beta1.22216.1</MicrosoftCodeAnalysisAnalyzerTestingVersion>
6969
<MicrosoftVisualBasicVersion>10.3.0</MicrosoftVisualBasicVersion>
7070
<MicrosoftVisualStudioSetupConfigurationInteropVersion>3.2.2146</MicrosoftVisualStudioSetupConfigurationInteropVersion>

src/Cli/Microsoft.TemplateEngine.Cli/ChoiceTemplateParameter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.CommandLine;
5-
using System.CommandLine.Help;
65
using System.CommandLine.Parsing;
76
using Microsoft.TemplateEngine.Abstractions;
87
using Microsoft.TemplateEngine.Cli.Commands;
8+
using Microsoft.TemplateEngine.Cli.Help;
99
using Microsoft.TemplateEngine.Utils;
1010

1111
namespace Microsoft.TemplateEngine.Cli

src/Cli/Microsoft.TemplateEngine.Cli/CliTemplateParameter.cs

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

44
using System.CommandLine;
5-
using System.CommandLine.Help;
65
using System.CommandLine.Parsing;
76
using System.Diagnostics;
87
using System.Globalization;
98
using Microsoft.TemplateEngine.Abstractions;
109
using Microsoft.TemplateEngine.Cli.Commands;
10+
using Microsoft.TemplateEngine.Cli.Help;
1111

1212
namespace Microsoft.TemplateEngine.Cli
1313
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.CommandLine;
5-
using System.CommandLine.Help;
5+
using Microsoft.TemplateEngine.Cli.Help;
66

77
namespace Microsoft.TemplateEngine.Cli.Commands
88
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.CommandLine.Help;
54
using Microsoft.TemplateEngine.Abstractions;
5+
using Microsoft.TemplateEngine.Cli.Help;
66

77
namespace Microsoft.TemplateEngine.Cli.Commands
88
{

src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.Help.cs

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

44
using System.CommandLine;
5-
using System.CommandLine.Help;
65
using System.Diagnostics.CodeAnalysis;
7-
using System.Resources;
86
using Microsoft.DotNet.Cli.Utils;
97
using Microsoft.TemplateEngine.Abstractions;
8+
using Microsoft.TemplateEngine.Cli.Help;
109
using Microsoft.TemplateEngine.Edge.Settings;
1110
using Microsoft.TemplateEngine.Utils;
1211
using Command = System.CommandLine.Command;
@@ -16,8 +15,6 @@ namespace Microsoft.TemplateEngine.Cli.Commands
1615
internal partial class InstantiateCommand
1716
{
1817
private const string Indent = " ";
19-
private static Lazy<ResourceManager> _resourceManager = new(
20-
() => new ResourceManager("System.CommandLine.Properties.Resources", typeof(System.CommandLine.Symbol).Assembly));
2118

2219
public static void WriteHelp(HelpContext context, InstantiateCommandArgs instantiateCommandArgs, IEngineEnvironmentSettings environmentSettings)
2320
{
@@ -328,7 +325,7 @@ internal static void ShowCommandOptions(
328325
cliOption.EnsureHelpName();
329326
}
330327

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

383380
usageParts.Reverse();
384-
context.Output.WriteLine(HelpUsageTitle());
381+
context.Output.WriteLine(LocalizationResources.HelpUsageTitle());
385382
foreach (string shortName in shortNames)
386383
{
387384
IEnumerable<string> parts = usageParts.Concat(
388385
new[]
389386
{
390387
shortName,
391-
HelpUsageOptions(),
388+
LocalizationResources.HelpUsageOptions(),
392389
HelpStrings.Text_UsageTemplateOptionsPart
393390
});
394391
context.Output.WriteLine(Indent + string.Join(" ", parts));
@@ -463,7 +460,7 @@ private static void WriteCustomInstantiateHelp(HelpContext context, Command comm
463460

464461
private static void CustomUsageSection(HelpContext context, Command command)
465462
{
466-
context.Output.WriteLine(HelpUsageTitle());
463+
context.Output.WriteLine(LocalizationResources.HelpUsageTitle());
467464
context.Output.WriteLine(Indent + string.Join(" ", GetCustomUsageParts(context, command, showSubcommands: false)));
468465

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

500497
if (showSubcommands)
501498
{
502-
yield return HelpUsageCommand();
499+
yield return LocalizationResources.HelpUsageCommand();
503500
}
504501

505502
if (showOptions)
506503
{
507-
yield return HelpUsageOptions();
504+
yield return LocalizationResources.HelpUsageOptions();
508505
}
509506
}
510-
511-
private static string HelpUsageOptions() => _resourceManager.Value.GetString("HelpUsageOptions")!;
512-
513-
private static string HelpUsageCommand() => _resourceManager.Value.GetString("HelpUsageCommand")!;
514-
515-
private static string HelpUsageTitle() => _resourceManager.Value.GetString("HelpUsageTitle")!;
516-
517-
private static string HelpOptionsTitle() => _resourceManager.Value.GetString("HelpOptionsTitle")!;
518507
}
519508
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
using System.CommandLine.Invocation;
6+
7+
namespace Microsoft.TemplateEngine.Cli.Help;
8+
9+
/// <summary>
10+
/// Provides command line help.
11+
/// </summary>
12+
public sealed class DotnetHelpAction : SynchronousCommandLineAction
13+
{
14+
private HelpBuilder? _builder;
15+
16+
/// <summary>
17+
/// Specifies an <see cref="Builder"/> to be used to format help output when help is requested.
18+
/// </summary>
19+
public HelpBuilder Builder
20+
{
21+
get => _builder ??= new HelpBuilder(Console.IsOutputRedirected ? int.MaxValue : Console.WindowWidth);
22+
set => _builder = value ?? throw new ArgumentNullException(nameof(value));
23+
}
24+
25+
/// <inheritdoc />
26+
public override int Invoke(ParseResult parseResult)
27+
{
28+
var output = parseResult.Configuration.Output;
29+
30+
var helpContext = new HelpContext(
31+
Builder,
32+
parseResult.CommandResult.Command,
33+
output,
34+
parseResult);
35+
36+
Builder.Write(helpContext);
37+
38+
return 0;
39+
}
40+
}

0 commit comments

Comments
 (0)