Skip to content

Commit ce5c986

Browse files
committed
Convert InputModel into a record to avoid the bulky constructor
1 parent 281506f commit ce5c986

File tree

1 file changed

+47
-70
lines changed

1 file changed

+47
-70
lines changed

DepotDownloader/Program.cs

Lines changed: 47 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ public static Task<int> Main(string[] args)
2424
{
2525
new Option<bool>("--debug") { IsHidden = true },
2626

27-
new Option<uint>("--app", "The AppID to download") { IsRequired = true, ArgumentHelpName = "id" },
27+
new Option<uint>("--app", "The AppID to download") { IsRequired = true, ArgumentHelpName = "id", Name = "AppId" },
2828

29-
new Option<uint[]>("--depot", "The DepotID to download") { ArgumentHelpName = "id" },
30-
new Option<ulong[]>("--manifest", "Manifest id of content to download (requires --depot, default: current for branch)"),
29+
new Option<uint[]>("--depot", "The DepotID to download") { ArgumentHelpName = "id", Name = "Depots" },
30+
new Option<ulong[]>("--manifest", "Manifest id of content to download (requires --depot, default: current for branch)") { ArgumentHelpName = "id", Name = "Manifests" },
3131

32-
new Option<ulong?>("--ugc", "The UGC ID to download"),
33-
new Option<ulong[]>("--pubfile", "The PublishedFileId to download (will automatically resolve to UGC id)"),
32+
new Option<ulong?>("--ugc", "The UGC ID to download") { ArgumentHelpName = "id" },
33+
new Option<ulong[]>("--pubfile", "The PublishedFileId to download (will automatically resolve to UGC id)") { ArgumentHelpName = "id", Name = "PublishedFileIds" },
3434

3535
new Option<string?>(new[] { "--branch", "--beta" }, "Download from specified branch if available"),
3636
new Option<string?>(new[] { "--branch-password", "--betapassword" }, "Branch password if applicable"),
3737

38-
new Option<string[]>("--os", () => new[] { Util.GetSteamOS() }, "The operating system for which to download the game").FromAmong("all", "windows", "macos", "linux"),
39-
new Option<string[]>("--arch", () => new[] { Util.GetSteamArch() }, "The architecture for which to download the game").FromAmong("64", "32"),
40-
new Option<string[]>("--language", () => new[] { "english" }, "The language for which to download the game"),
38+
new Option<string[]>("--os", () => new[] { Util.GetSteamOS() }, "The operating system for which to download the game") { Name = "OperatingSystems" }.FromAmong("all", "windows", "macos", "linux"),
39+
new Option<string[]>("--arch", () => new[] { Util.GetSteamArch() }, "The architecture for which to download the game") { Name = "Architectures" }.FromAmong("64", "32"),
40+
new Option<string[]>("--language", () => new[] { "english" }, "The language for which to download the game") { ArgumentHelpName = "language", Name = "Languages" },
4141
new Option<bool>("--lowviolence", "Download low violence depots"),
4242

4343
new Option<string?>("--username", "The username of the account to login to for restricted content"),
@@ -46,7 +46,7 @@ public static Task<int> Main(string[] args)
4646

4747
new Option<DirectoryInfo>(new[] { "--directory", "--dir" }, "The directory in which to place downloaded files"),
4848
new Option<FileInfo>("--filelist", "A list of files to download (from the manifest). Prefix file path with 'regex:' if you want to match with regex").ExistingOnly(),
49-
new Option<bool>(new[] { "--validate", "--verify-all" }, "Include checksum verification of files already downloaded"),
49+
new Option<bool>(new[] { "--validate", "--verify-all" }, "Include checksum verification of files already downloaded") { Name = "Validate" },
5050
new Option<bool>("--manifest-only", "Downloads a human readable manifest for any depots that would be downloaded"),
5151

5252
new Option<int?>("--cellid", "The overridden CellID of the content server to download from"),
@@ -59,7 +59,19 @@ public static Task<int> Main(string[] args)
5959

6060
return new CommandLineBuilder(rootCommand)
6161
.UseDefaults()
62-
.UseHelp(help => help.HelpBuilder.CustomizeLayout(GetHelpLayout))
62+
.UseHelp(help =>
63+
{
64+
// Workaround https://github.com/dotnet/command-line-api/issues/1550
65+
foreach (var option in rootCommand.Options)
66+
{
67+
if (option.HasAlias(option.Name))
68+
{
69+
help.HelpBuilder.CustomizeSymbol(option, context => HelpBuilder.Default.GetIdentifierSymbolUsageLabel(option, context)[(option.Name.Length + 2)..]);
70+
}
71+
}
72+
73+
help.HelpBuilder.CustomizeLayout(GetHelpLayout);
74+
})
6375
.Build().InvokeAsync(args);
6476
}
6577

@@ -85,66 +97,31 @@ private static IEnumerable<HelpSectionDelegate> GetHelpLayout(HelpContext _)
8597
yield return HelpBuilder.Default.AdditionalArgumentsSection();
8698
}
8799

88-
public class InputModel
89-
{
90-
public InputModel(bool debug, uint app, uint[] depot, ulong[] manifest, ulong? ugc, ulong[] pubfile, string? branch, string? branchPassword, string[] os, string[] arch, string[] language, bool lowViolence, string? username, string? password, bool rememberPassword, DirectoryInfo? directory, FileInfo? fileList, bool validate, bool manifestOnly, int? cellId, int maxServers, int maxDownloads, uint? loginId)
91-
{
92-
Debug = debug;
93-
AppId = app;
94-
Depots = depot;
95-
Manifests = manifest;
96-
UgcId = ugc;
97-
PublishedFileIds = pubfile;
98-
Branch = branch;
99-
BranchPassword = branchPassword;
100-
OperatingSystems = os;
101-
Architectures = arch;
102-
Languages = language;
103-
LowViolence = lowViolence;
104-
Username = username;
105-
Password = password;
106-
RememberPassword = rememberPassword;
107-
Directory = directory;
108-
FileList = fileList;
109-
Validate = validate;
110-
ManifestOnly = manifestOnly;
111-
CellId = cellId;
112-
MaxServers = maxServers;
113-
MaxDownloads = maxDownloads;
114-
LoginId = loginId;
115-
}
116-
public bool Debug { get; }
117-
118-
public uint AppId { get; }
119-
120-
public uint[] Depots { get; }
121-
public ulong[] Manifests { get; }
122-
123-
public ulong? UgcId { get; }
124-
public ulong[] PublishedFileIds { get; }
125-
126-
public string? Branch { get; }
127-
public string? BranchPassword { get; }
128-
129-
public string[] OperatingSystems { get; }
130-
public string[] Architectures { get; }
131-
public string[] Languages { get; }
132-
public bool LowViolence { get; }
133-
134-
public string? Username { get; }
135-
public string? Password { get; }
136-
public bool RememberPassword { get; }
137-
138-
public DirectoryInfo? Directory { get; }
139-
public FileInfo? FileList { get; }
140-
public bool Validate { get; }
141-
public bool ManifestOnly { get; }
142-
143-
public int? CellId { get; }
144-
public int MaxServers { get; }
145-
public int MaxDownloads { get; }
146-
public uint? LoginId { get; }
147-
}
100+
public record InputModel(
101+
bool Debug,
102+
uint AppId,
103+
uint[] Depots,
104+
ulong[] Manifests,
105+
ulong? UgcId,
106+
ulong[] PublishedFileIds,
107+
string? Branch,
108+
string? BranchPassword,
109+
string[] OperatingSystems,
110+
string[] Architectures,
111+
string[] Languages,
112+
bool LowViolence,
113+
string? Username,
114+
string? Password,
115+
bool RememberPassword,
116+
DirectoryInfo? Directory,
117+
FileInfo? FileList,
118+
bool Validate,
119+
bool ManifestOnly,
120+
int? CellId,
121+
int MaxServers,
122+
int MaxDownloads,
123+
uint? LoginId
124+
);
148125

149126
public static async Task<int> DownloadAsync(InputModel input)
150127
{

0 commit comments

Comments
 (0)