Update System.CommandLine

pull/234/head
js6pak 4 years ago
parent 22fea82562
commit 281506f40b
No known key found for this signature in database
GPG Key ID: EFE980EFD32F8EE9

@ -13,6 +13,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="protobuf-net" Version="3.1.17" /> <PackageReference Include="protobuf-net" Version="3.1.17" />
<PackageReference Include="SteamKit2" Version="2.4.1" /> <PackageReference Include="SteamKit2" Version="2.4.1" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21308.1" /> <PackageReference Include="System.CommandLine" Version="2.0.0-beta2.21617.1" />
<PackageReference Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta2.21617.1" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -4,8 +4,7 @@ using System.Collections.Generic;
using System.CommandLine; using System.CommandLine;
using System.CommandLine.Builder; using System.CommandLine.Builder;
using System.CommandLine.Help; using System.CommandLine.Help;
using System.CommandLine.Invocation; using System.CommandLine.NamingConventionBinder;
using System.CommandLine.IO;
using System.CommandLine.Parsing; using System.CommandLine.Parsing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -60,34 +59,30 @@ namespace DepotDownloader
return new CommandLineBuilder(rootCommand) return new CommandLineBuilder(rootCommand)
.UseDefaults() .UseDefaults()
.UseHelpBuilder(ctx => new CustomHelpBuilder(ctx.Console)) .UseHelp(help => help.HelpBuilder.CustomizeLayout(GetHelpLayout))
.Build().InvokeAsync(args); .Build().InvokeAsync(args);
} }
private sealed class CustomHelpBuilder : HelpBuilder private static IEnumerable<HelpSectionDelegate> GetHelpLayout(HelpContext _)
{ {
public CustomHelpBuilder(IConsole console) : base(console) yield return ctx => { ctx.Output.WriteLine("DepotDownloader"); };
yield return ctx =>
{ {
} ctx.Output.WriteLine(@$"Examples:
protected override void AddUsage(ICommand command)
{
if (command is not RootCommand)
return;
Console.Out.WriteLine(@$"Examples:
- downloading one or all depots for an app: - downloading one or all depots for an app:
{command.Name} --app <id> [--depot <id> [--manifest <id>]] [--username <username> [--password <password>]] {ctx.Command.Name} --app <id> [--depot <id> [--manifest <id>]] [--username <username> [--password <password>]]
- downloading a workshop item using pubfile id: - downloading a workshop item using pubfile id:
{command.Name} --app <id> --pubfile <id> [--username <username> [--password <password>]] {ctx.Command.Name} --app <id> --pubfile <id> [--username <username> [--password <password>]]
- downloading a workshop item using ugc id: - downloading a workshop item using ugc id:
{command.Name} --app <id> --ugc <id> [--username <username> [--password <password>]]" {ctx.Command.Name} --app <id> --ugc <id> [--username <username> [--password <password>]]"
); );
};
Console.Out.WriteLine(); yield return HelpBuilder.Default.CommandArgumentsSection();
} yield return HelpBuilder.Default.OptionsSection();
yield return HelpBuilder.Default.SubcommandsSection();
yield return HelpBuilder.Default.AdditionalArgumentsSection();
} }
public class InputModel public class InputModel
@ -100,14 +95,14 @@ namespace DepotDownloader
Manifests = manifest; Manifests = manifest;
UgcId = ugc; UgcId = ugc;
PublishedFileIds = pubfile; PublishedFileIds = pubfile;
Branch = EnsureNonEmpty(branch); Branch = branch;
BranchPassword = EnsureNonEmpty(branchPassword); BranchPassword = branchPassword;
OperatingSystems = os; OperatingSystems = os;
Architectures = arch; Architectures = arch;
Languages = language; Languages = language;
LowViolence = lowViolence; LowViolence = lowViolence;
Username = EnsureNonEmpty(username); Username = username;
Password = EnsureNonEmpty(password); Password = password;
RememberPassword = rememberPassword; RememberPassword = rememberPassword;
Directory = directory; Directory = directory;
FileList = fileList; FileList = fileList;
@ -118,13 +113,6 @@ namespace DepotDownloader
MaxDownloads = maxDownloads; MaxDownloads = maxDownloads;
LoginId = loginId; LoginId = loginId;
} }
// Workaround for https://github.com/dotnet/command-line-api/issues/1244
private static string? EnsureNonEmpty(string? s)
{
return s == string.Empty ? null : s;
}
public bool Debug { get; } public bool Debug { get; }
public uint AppId { get; } public uint AppId { get; }

Loading…
Cancel
Save