Skip to content

Commit 3c34adc

Browse files
authored
update System.CommandLine (#1356)
* update System.CommandLine, remove dependency to NamingConventionBinder and Rendering * bump Microsoft.SourceBuild.Intermediate.command-line-api
1 parent f1cc7ef commit 3c34adc

File tree

4 files changed

+48
-64
lines changed

4 files changed

+48
-64
lines changed

eng/Version.Details.xml

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Dependencies>
33
<ProductDependencies>
4-
<Dependency Name="System.CommandLine" Version="2.0.0-beta4.23307.1">
4+
<Dependency Name="System.CommandLine" Version="2.0.0-beta4.25072.1">
55
<Uri>https://github.com/dotnet/command-line-api</Uri>
6-
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
7-
</Dependency>
8-
<Dependency Name="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.23307.1">
9-
<Uri>https://github.com/dotnet/command-line-api</Uri>
10-
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
11-
</Dependency>
12-
<Dependency Name="System.CommandLine.Rendering" Version="0.4.0-alpha.23307.1">
13-
<Uri>https://github.com/dotnet/command-line-api</Uri>
14-
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
6+
<Sha>060374e56c1b2e741b6525ca8417006efb54fbd7</Sha>
157
</Dependency>
168
<!-- Intermediate is necessary for source build. -->
17-
<Dependency Name="Microsoft.SourceBuild.Intermediate.command-line-api" Version="0.1.430701">
9+
<Dependency Name="Microsoft.SourceBuild.Intermediate.command-line-api" Version="0.1.607201">
1810
<Uri>https://github.com/dotnet/command-line-api</Uri>
19-
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
11+
<Sha>060374e56c1b2e741b6525ca8417006efb54fbd7</Sha>
2012
<SourceBuild RepoName="command-line-api" ManagedOnly="true" />
2113
</Dependency>
2214
<!-- Intermediate is necessary for source build. -->

eng/Versions.props

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
</PropertyGroup>
1111
<PropertyGroup>
1212
<!-- commandline -->
13-
<SystemCommandLineVersion>2.0.0-beta4.23307.1</SystemCommandLineVersion>
14-
<SystemCommandLineNamingConventionBinderVersion>2.0.0-beta4.23307.1</SystemCommandLineNamingConventionBinderVersion>
15-
<SystemCommandLineRenderingVersion>0.4.0-alpha.23307.1</SystemCommandLineRenderingVersion>
13+
<SystemCommandLineVersion>2.0.0-beta4.25072.1</SystemCommandLineVersion>
1614
<!-- msbuild -->
1715
<MicrosoftBuildVersion>17.8.3</MicrosoftBuildVersion>
1816
<MicrosoftBuildTasksCoreVersion>17.8.3</MicrosoftBuildTasksCoreVersion>

src/dotnet-sourcelink/Program.cs

+43-47
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
using System.Collections.Generic;
55
using System.Collections.Immutable;
66
using System.CommandLine;
7-
using System.CommandLine.Invocation;
8-
using System.CommandLine.NamingConventionBinder;
9-
using System.CommandLine.Parsing;
107
using System.IO;
118
using System.Linq;
129
using System.Net;
@@ -62,77 +59,82 @@ private static string GetSourceLinkVersion()
6259
return attribute.InformationalVersion.Split('+').First();
6360
}
6461

65-
private static CliRootCommand GetRootCommand()
62+
private static RootCommand GetRootCommand()
6663
{
67-
var authArg = new CliOption<string>("--auth", "-a")
64+
var pathArg = new Argument<string>("path")
65+
{
66+
Description = "Path to an assembly or .pdb"
67+
};
68+
var authArg = new Option<string>("--auth", "-a")
6869
{
6970
Description = "Authentication method"
7071
};
7172
authArg.AcceptOnlyFromAmong(AuthenticationMethod.Basic);
7273

73-
var userArg = new CliOption<string>("--user", "-u")
74+
var authEncodingArg = new Option<Encoding>("--auth-encoding", "-e")
75+
{
76+
CustomParser = arg => Encoding.GetEncoding(arg.Tokens.Single().Value),
77+
Description = "Encoding to use for authentication value"
78+
};
79+
80+
var userArg = new Option<string>("--user", "-u")
7481
{
7582
Description = "Username to use to authenticate",
7683
Arity = ArgumentArity.ExactlyOne
7784
};
7885

79-
var passwordArg = new CliOption<string>("--password", "-p")
86+
var passwordArg = new Option<string>("--password", "-p")
8087
{
8188
Description = "Password to use to authenticate",
8289
Arity = ArgumentArity.ExactlyOne
8390
};
8491

85-
var offlineArg = new CliOption<bool>("--offline")
92+
var offlineArg = new Option<bool>("--offline")
8693
{
8794
Description = "Offline mode - skip validation of sourcelink URL targets"
8895
};
8996

90-
var test = new CliCommand("test", "TODO")
97+
var test = new Command("test", "TODO")
9198
{
92-
new CliArgument<string>("path")
93-
{
94-
Description = "Path to an assembly or .pdb"
95-
},
99+
pathArg,
96100
authArg,
97-
new CliOption<Encoding>("--auth-encoding", "-e")
98-
{
99-
CustomParser = arg => Encoding.GetEncoding(arg.Tokens.Single().Value),
100-
Description = "Encoding to use for authentication value"
101-
},
101+
authEncodingArg,
102102
userArg,
103103
passwordArg,
104104
offlineArg,
105105
};
106-
test.Action = CommandHandler.Create<string, string?, Encoding?, string?, string?, bool, ParseResult>(TestAsync);
106+
107+
test.SetAction((parseResult, cancellationToken) =>
108+
{
109+
string path = parseResult.GetValue(pathArg)!;
110+
string? authMethod = parseResult.GetValue(authArg);
111+
Encoding? authEncoding = parseResult.GetValue(authEncodingArg);
112+
string? user = parseResult.GetValue(userArg);
113+
string? password = parseResult.GetValue(passwordArg);
114+
bool offline = parseResult.GetValue(offlineArg);
115+
116+
return TestAsync(path, authMethod, authEncoding, user, password, offline, parseResult, cancellationToken);
117+
});
107118

108-
var printJson = new CliCommand("print-json", "Print Source Link JSON stored in the PDB")
119+
var printJson = new Command("print-json", "Print Source Link JSON stored in the PDB")
109120
{
110-
new CliArgument<string>("path")
111-
{
112-
Description = "Path to an assembly or .pdb"
113-
}
121+
pathArg
114122
};
115-
printJson.Action = CommandHandler.Create<string, ParseResult>(PrintJsonAsync);
123+
printJson.SetAction((parseResult, ct) => PrintJsonAsync(parseResult.GetValue(pathArg)!, parseResult));
116124

117-
var printDocuments = new CliCommand("print-documents", "TODO")
125+
var printDocuments = new Command("print-documents", "TODO")
118126
{
119-
new CliArgument<string>("path")
120-
{
121-
Description = "Path to an assembly or .pdb"
122-
}
127+
pathArg
123128
};
124-
printDocuments.Action = CommandHandler.Create<string, ParseResult>(PrintDocumentsAsync);
129+
printDocuments.SetAction((parseResult, ct) => PrintDocumentsAsync(parseResult.GetValue(pathArg)!, parseResult));
125130

126-
var printUrls = new CliCommand("print-urls", "TODO")
131+
var printUrls = new Command("print-urls", "TODO")
127132
{
128-
new CliArgument<string>("path")
129-
{
130-
Description = "Path to an assembly or .pdb"
131-
}
133+
pathArg
132134
};
133-
printUrls.Action = CommandHandler.Create<string, ParseResult>(PrintUrlsAsync);
135+
printUrls.SetAction((parseResult, ct) => PrintUrlsAsync(parseResult.GetValue(pathArg)!, parseResult));
134136

135-
var root = new CliRootCommand()
137+
var root = new RootCommand()
136138
{
137139
test,
138140
printJson,
@@ -176,20 +178,14 @@ private static async Task<int> TestAsync(
176178
string? user,
177179
string? password,
178180
bool offline,
179-
ParseResult parseResult)
181+
ParseResult parseResult,
182+
CancellationToken cancellationToken)
180183
{
181184
var authenticationHeader = (authMethod != null) ? GetAuthenticationHeader(authMethod, authEncoding ?? Encoding.ASCII, user!, password!) : null;
182185

183-
var cancellationSource = new CancellationTokenSource();
184-
Console.CancelKeyPress += (sender, e) =>
185-
{
186-
e.Cancel = true;
187-
cancellationSource.Cancel();
188-
};
189-
190186
try
191187
{
192-
return await new Program(parseResult).TestAsync(path, authenticationHeader, offline, cancellationSource.Token).ConfigureAwait(false);
188+
return await new Program(parseResult).TestAsync(path, authenticationHeader, offline, cancellationToken).ConfigureAwait(false);
193189
}
194190
catch (OperationCanceledException)
195191
{

src/dotnet-sourcelink/dotnet-sourcelink.csproj

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
<ItemGroup>
1818
<PackageReference Include="System.CommandLine" />
19-
<PackageReference Include="System.CommandLine.NamingConventionBinder" />
20-
<PackageReference Include="System.CommandLine.Rendering" />
2119
</ItemGroup>
2220

2321
<Import Project="..\SourceLink.Tools\Microsoft.SourceLink.Tools.projitems" Label="Shared" />

0 commit comments

Comments
 (0)