diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index d1e2a05fa..ed0246775 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -1,22 +1,14 @@ - + https://github.com/dotnet/command-line-api - 02fe27cd6a9b001c8feb7938e6ef4b3799745759 - - - https://github.com/dotnet/command-line-api - 02fe27cd6a9b001c8feb7938e6ef4b3799745759 - - - https://github.com/dotnet/command-line-api - 02fe27cd6a9b001c8feb7938e6ef4b3799745759 + 060374e56c1b2e741b6525ca8417006efb54fbd7 - + https://github.com/dotnet/command-line-api - 02fe27cd6a9b001c8feb7938e6ef4b3799745759 + 060374e56c1b2e741b6525ca8417006efb54fbd7 diff --git a/eng/Versions.props b/eng/Versions.props index 881284e83..0a46d2bcb 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -10,9 +10,7 @@ - 2.0.0-beta4.23307.1 - 2.0.0-beta4.23307.1 - 0.4.0-alpha.23307.1 + 2.0.0-beta4.25072.1 17.8.3 17.8.3 diff --git a/src/dotnet-sourcelink/Program.cs b/src/dotnet-sourcelink/Program.cs index e422d4cdd..319c79aeb 100644 --- a/src/dotnet-sourcelink/Program.cs +++ b/src/dotnet-sourcelink/Program.cs @@ -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; @@ -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("--auth", "-a") + var pathArg = new Argument("path") + { + Description = "Path to an assembly or .pdb" + }; + var authArg = new Option("--auth", "-a") { Description = "Authentication method" }; authArg.AcceptOnlyFromAmong(AuthenticationMethod.Basic); - var userArg = new CliOption("--user", "-u") + var authEncodingArg = new Option("--auth-encoding", "-e") + { + CustomParser = arg => Encoding.GetEncoding(arg.Tokens.Single().Value), + Description = "Encoding to use for authentication value" + }; + + var userArg = new Option("--user", "-u") { Description = "Username to use to authenticate", Arity = ArgumentArity.ExactlyOne }; - var passwordArg = new CliOption("--password", "-p") + var passwordArg = new Option("--password", "-p") { Description = "Password to use to authenticate", Arity = ArgumentArity.ExactlyOne }; - var offlineArg = new CliOption("--offline") + var offlineArg = new Option("--offline") { Description = "Offline mode - skip validation of sourcelink URL targets" }; - var test = new CliCommand("test", "TODO") + var test = new Command("test", "TODO") { - new CliArgument("path") - { - Description = "Path to an assembly or .pdb" - }, + pathArg, authArg, - new CliOption("--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(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); + }); - 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("path") - { - Description = "Path to an assembly or .pdb" - } + pathArg }; - printJson.Action = CommandHandler.Create(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("path") - { - Description = "Path to an assembly or .pdb" - } + pathArg }; - printDocuments.Action = CommandHandler.Create(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("path") - { - Description = "Path to an assembly or .pdb" - } + pathArg }; - printUrls.Action = CommandHandler.Create(PrintUrlsAsync); + printUrls.SetAction((parseResult, ct) => PrintUrlsAsync(parseResult.GetValue(pathArg)!, parseResult)); - var root = new CliRootCommand() + var root = new RootCommand() { test, printJson, @@ -176,20 +178,14 @@ private static async Task 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) => - { - 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) { diff --git a/src/dotnet-sourcelink/dotnet-sourcelink.csproj b/src/dotnet-sourcelink/dotnet-sourcelink.csproj index 497629714..71f0a3e5d 100644 --- a/src/dotnet-sourcelink/dotnet-sourcelink.csproj +++ b/src/dotnet-sourcelink/dotnet-sourcelink.csproj @@ -16,8 +16,6 @@ - -