Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Dependencies>
<ProductDependencies>
<Dependency Name="System.CommandLine" Version="2.0.0-beta4.23307.1">
<Dependency Name="System.CommandLine" Version="2.0.0-beta4.25072.1">
<Uri>https://github.com/dotnet/command-line-api</Uri>
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
</Dependency>
<Dependency Name="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.23307.1">
<Uri>https://github.com/dotnet/command-line-api</Uri>
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
</Dependency>
<Dependency Name="System.CommandLine.Rendering" Version="0.4.0-alpha.23307.1">
<Uri>https://github.com/dotnet/command-line-api</Uri>
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
<Sha>060374e56c1b2e741b6525ca8417006efb54fbd7</Sha>
</Dependency>
<!-- Intermediate is necessary for source build. -->
<Dependency Name="Microsoft.SourceBuild.Intermediate.command-line-api" Version="0.1.430701">
<Dependency Name="Microsoft.SourceBuild.Intermediate.command-line-api" Version="0.1.607201">
<Uri>https://github.com/dotnet/command-line-api</Uri>
<Sha>02fe27cd6a9b001c8feb7938e6ef4b3799745759</Sha>
<Sha>060374e56c1b2e741b6525ca8417006efb54fbd7</Sha>
<SourceBuild RepoName="command-line-api" ManagedOnly="true" />
</Dependency>
<!-- Intermediate is necessary for source build. -->
Expand Down
4 changes: 1 addition & 3 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
</PropertyGroup>
<PropertyGroup>
<!-- commandline -->
<SystemCommandLineVersion>2.0.0-beta4.23307.1</SystemCommandLineVersion>
<SystemCommandLineNamingConventionBinderVersion>2.0.0-beta4.23307.1</SystemCommandLineNamingConventionBinderVersion>
<SystemCommandLineRenderingVersion>0.4.0-alpha.23307.1</SystemCommandLineRenderingVersion>
<SystemCommandLineVersion>2.0.0-beta4.25072.1</SystemCommandLineVersion>
<!-- msbuild -->
<MicrosoftBuildVersion>17.8.3</MicrosoftBuildVersion>
<MicrosoftBuildTasksCoreVersion>17.8.3</MicrosoftBuildTasksCoreVersion>
Expand Down
90 changes: 43 additions & 47 deletions src/dotnet-sourcelink/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.CommandLine.NamingConventionBinder;
using System.CommandLine.Parsing;
using System.IO;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -62,77 +59,82 @@ private static string GetSourceLinkVersion()
return attribute.InformationalVersion.Split('+').First();
}

private static CliRootCommand GetRootCommand()
private static RootCommand GetRootCommand()
{
var authArg = new CliOption<string>("--auth", "-a")
var pathArg = new Argument<string>("path")
{
Description = "Path to an assembly or .pdb"
};
var authArg = new Option<string>("--auth", "-a")
{
Description = "Authentication method"
};
authArg.AcceptOnlyFromAmong(AuthenticationMethod.Basic);

var userArg = new CliOption<string>("--user", "-u")
var authEncodingArg = new Option<Encoding>("--auth-encoding", "-e")
{
CustomParser = arg => Encoding.GetEncoding(arg.Tokens.Single().Value),
Description = "Encoding to use for authentication value"
};

var userArg = new Option<string>("--user", "-u")
{
Description = "Username to use to authenticate",
Arity = ArgumentArity.ExactlyOne
};

var passwordArg = new CliOption<string>("--password", "-p")
var passwordArg = new Option<string>("--password", "-p")
{
Description = "Password to use to authenticate",
Arity = ArgumentArity.ExactlyOne
};

var offlineArg = new CliOption<bool>("--offline")
var offlineArg = new Option<bool>("--offline")
{
Description = "Offline mode - skip validation of sourcelink URL targets"
};

var test = new CliCommand("test", "TODO")
var test = new Command("test", "TODO")
{
new CliArgument<string>("path")
{
Description = "Path to an assembly or .pdb"
},
pathArg,
authArg,
new CliOption<Encoding>("--auth-encoding", "-e")
{
CustomParser = arg => Encoding.GetEncoding(arg.Tokens.Single().Value),
Description = "Encoding to use for authentication value"
},
authEncodingArg,
userArg,
passwordArg,
offlineArg,
};
test.Action = CommandHandler.Create<string, string?, Encoding?, string?, string?, bool, ParseResult>(TestAsync);

test.SetAction((parseResult, cancellationToken) =>
{
string path = parseResult.GetValue(pathArg)!;
string? authMethod = parseResult.GetValue(authArg);
Encoding? authEncoding = parseResult.GetValue(authEncodingArg);
string? user = parseResult.GetValue(userArg);
string? password = parseResult.GetValue(passwordArg);
bool offline = parseResult.GetValue(offlineArg);

return TestAsync(path, authMethod, authEncoding, user, password, offline, parseResult, cancellationToken);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CommandHandler.Create was part of NamingConventionBinder which would use reflection just to achieve what I've written here

});

var printJson = new CliCommand("print-json", "Print Source Link JSON stored in the PDB")
var printJson = new Command("print-json", "Print Source Link JSON stored in the PDB")
{
new CliArgument<string>("path")
{
Description = "Path to an assembly or .pdb"
}
pathArg
};
printJson.Action = CommandHandler.Create<string, ParseResult>(PrintJsonAsync);
printJson.SetAction((parseResult, ct) => PrintJsonAsync(parseResult.GetValue(pathArg)!, parseResult));

var printDocuments = new CliCommand("print-documents", "TODO")
var printDocuments = new Command("print-documents", "TODO")
{
new CliArgument<string>("path")
{
Description = "Path to an assembly or .pdb"
}
pathArg
};
printDocuments.Action = CommandHandler.Create<string, ParseResult>(PrintDocumentsAsync);
printDocuments.SetAction((parseResult, ct) => PrintDocumentsAsync(parseResult.GetValue(pathArg)!, parseResult));

var printUrls = new CliCommand("print-urls", "TODO")
var printUrls = new Command("print-urls", "TODO")
{
new CliArgument<string>("path")
{
Description = "Path to an assembly or .pdb"
}
pathArg
};
printUrls.Action = CommandHandler.Create<string, ParseResult>(PrintUrlsAsync);
printUrls.SetAction((parseResult, ct) => PrintUrlsAsync(parseResult.GetValue(pathArg)!, parseResult));

var root = new CliRootCommand()
var root = new RootCommand()
{
test,
printJson,
Expand Down Expand Up @@ -176,20 +178,14 @@ private static async Task<int> TestAsync(
string? user,
string? password,
bool offline,
ParseResult parseResult)
ParseResult parseResult,
CancellationToken cancellationToken)
{
var authenticationHeader = (authMethod != null) ? GetAuthenticationHeader(authMethod, authEncoding ?? Encoding.ASCII, user!, password!) : null;

var cancellationSource = new CancellationTokenSource();
Console.CancelKeyPress += (sender, e) =>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
e.Cancel = true;
cancellationSource.Cancel();
};

try
{
return await new Program(parseResult).TestAsync(path, authenticationHeader, offline, cancellationSource.Token).ConfigureAwait(false);
return await new Program(parseResult).TestAsync(path, authenticationHeader, offline, cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
Expand Down
2 changes: 0 additions & 2 deletions src/dotnet-sourcelink/dotnet-sourcelink.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

<ItemGroup>
<PackageReference Include="System.CommandLine" />
<PackageReference Include="System.CommandLine.NamingConventionBinder" />
<PackageReference Include="System.CommandLine.Rendering" />
</ItemGroup>

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