Skip to content

Commit 281506f

Browse files
committed
Update System.CommandLine
1 parent 22fea82 commit 281506f

File tree

2 files changed

+20
-31
lines changed

2 files changed

+20
-31
lines changed

DepotDownloader/DepotDownloader.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<ItemGroup>
1414
<PackageReference Include="protobuf-net" Version="3.1.17" />
1515
<PackageReference Include="SteamKit2" Version="2.4.1" />
16-
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
16+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta2.21617.1" />
17+
<PackageReference Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta2.21617.1" />
1718
</ItemGroup>
1819
</Project>

DepotDownloader/Program.cs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
using System.CommandLine;
55
using System.CommandLine.Builder;
66
using System.CommandLine.Help;
7-
using System.CommandLine.Invocation;
8-
using System.CommandLine.IO;
7+
using System.CommandLine.NamingConventionBinder;
98
using System.CommandLine.Parsing;
109
using System.IO;
1110
using System.Linq;
@@ -60,34 +59,30 @@ public static Task<int> Main(string[] args)
6059

6160
return new CommandLineBuilder(rootCommand)
6261
.UseDefaults()
63-
.UseHelpBuilder(ctx => new CustomHelpBuilder(ctx.Console))
62+
.UseHelp(help => help.HelpBuilder.CustomizeLayout(GetHelpLayout))
6463
.Build().InvokeAsync(args);
6564
}
6665

67-
private sealed class CustomHelpBuilder : HelpBuilder
66+
private static IEnumerable<HelpSectionDelegate> GetHelpLayout(HelpContext _)
6867
{
69-
public CustomHelpBuilder(IConsole console) : base(console)
68+
yield return ctx => { ctx.Output.WriteLine("DepotDownloader"); };
69+
yield return ctx =>
7070
{
71-
}
72-
73-
protected override void AddUsage(ICommand command)
74-
{
75-
if (command is not RootCommand)
76-
return;
77-
78-
Console.Out.WriteLine(@$"Examples:
71+
ctx.Output.WriteLine(@$"Examples:
7972
- downloading one or all depots for an app:
80-
{command.Name} --app <id> [--depot <id> [--manifest <id>]] [--username <username> [--password <password>]]
73+
{ctx.Command.Name} --app <id> [--depot <id> [--manifest <id>]] [--username <username> [--password <password>]]
8174
8275
- downloading a workshop item using pubfile id:
83-
{command.Name} --app <id> --pubfile <id> [--username <username> [--password <password>]]
76+
{ctx.Command.Name} --app <id> --pubfile <id> [--username <username> [--password <password>]]
8477
8578
- downloading a workshop item using ugc id:
86-
{command.Name} --app <id> --ugc <id> [--username <username> [--password <password>]]"
79+
{ctx.Command.Name} --app <id> --ugc <id> [--username <username> [--password <password>]]"
8780
);
88-
89-
Console.Out.WriteLine();
90-
}
81+
};
82+
yield return HelpBuilder.Default.CommandArgumentsSection();
83+
yield return HelpBuilder.Default.OptionsSection();
84+
yield return HelpBuilder.Default.SubcommandsSection();
85+
yield return HelpBuilder.Default.AdditionalArgumentsSection();
9186
}
9287

9388
public class InputModel
@@ -100,14 +95,14 @@ public InputModel(bool debug, uint app, uint[] depot, ulong[] manifest, ulong? u
10095
Manifests = manifest;
10196
UgcId = ugc;
10297
PublishedFileIds = pubfile;
103-
Branch = EnsureNonEmpty(branch);
104-
BranchPassword = EnsureNonEmpty(branchPassword);
98+
Branch = branch;
99+
BranchPassword = branchPassword;
105100
OperatingSystems = os;
106101
Architectures = arch;
107102
Languages = language;
108103
LowViolence = lowViolence;
109-
Username = EnsureNonEmpty(username);
110-
Password = EnsureNonEmpty(password);
104+
Username = username;
105+
Password = password;
111106
RememberPassword = rememberPassword;
112107
Directory = directory;
113108
FileList = fileList;
@@ -118,13 +113,6 @@ public InputModel(bool debug, uint app, uint[] depot, ulong[] manifest, ulong? u
118113
MaxDownloads = maxDownloads;
119114
LoginId = loginId;
120115
}
121-
122-
// Workaround for https://github.com/dotnet/command-line-api/issues/1244
123-
private static string? EnsureNonEmpty(string? s)
124-
{
125-
return s == string.Empty ? null : s;
126-
}
127-
128116
public bool Debug { get; }
129117

130118
public uint AppId { get; }

0 commit comments

Comments
 (0)