From fcfbe8bc8c424273924dd8fa9f5badda804da92d Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Fri, 7 Jun 2019 12:30:08 -0700 Subject: [PATCH 1/3] update System.CommandLine --- MLS.Agent/CommandLine/CommandLineParser.cs | 49 +++++++++------- MLS.Agent/MLS.Agent.csproj | 22 ++----- .../LocalCodeFenceAnnotationsParser.cs | 58 +++++++++++-------- MLS.PackageTool/MLS.PackageTool.csproj | 2 +- Microsoft.DotNet.Try.Client/package-lock.json | 44 ++++---------- .../Microsoft.DotNet.Try.Markdown.csproj | 4 +- ...DotNet.Try.ProjectTemplate.Tutorial.csproj | 4 +- Microsoft.DotNet.Try.js/package-lock.json | 3 +- Samples/Beginners/myapp/myapp.csproj | 4 +- .../ExploreCsharpEight.csproj | 4 +- .../CommandLineBuilderExtensions.cs | 12 ++-- WasmCodeRunner/MLS.WasmCodeRunner.csproj | 2 +- WorkspaceServer/DirectoryAccessor.cs | 6 +- .../Packaging/BlazorPackageInitializer.cs | 2 +- WorkspaceServer/WorkspaceServer.csproj | 2 +- docs/GettingStarted/Snippets/Snippets.csproj | 4 +- 16 files changed, 101 insertions(+), 121 deletions(-) diff --git a/MLS.Agent/CommandLine/CommandLineParser.cs b/MLS.Agent/CommandLine/CommandLineParser.cs index 2a0b2f979..04a430def 100644 --- a/MLS.Agent/CommandLine/CommandLineParser.cs +++ b/MLS.Agent/CommandLine/CommandLineParser.cs @@ -126,14 +126,14 @@ RootCommand StartInTryMode() var command = new RootCommand { Name = "dotnet-try", - Description = ".NET interactive documentation in your browser", - Argument = new Argument - { - Arity = ArgumentArity.ZeroOrOne, - Name = nameof(StartupOptions.Dir).ToLower(), - Description = "Specify the path to the root directory for your documentation" - }.ExistingOnly() + Description = ".NET interactive documentation in your browser" }; + command.AddArgument(new Argument + { + Arity = ArgumentArity.ZeroOrOne, + Name = nameof(StartupOptions.Dir).ToLower(), + Description = "Specify the path to the root directory for your documentation" + }.ExistingOnly()); command.AddOption(new Option( "--add-package-source", @@ -301,13 +301,15 @@ Command GitHub() Command Jupyter() { - var jupyterCommand = new Command("jupyter", "Starts dotnet try as a Jupyter kernel"); - jupyterCommand.IsHidden = true; + var jupyterCommand = new Command("jupyter", "Starts dotnet try as a Jupyter kernel") + { + IsHidden = true + }; var connectionFileArgument = new Argument { Name = "ConnectionFile" }.ExistingOnly(); - jupyterCommand.Argument = connectionFileArgument; + jupyterCommand.AddArgument(connectionFileArgument); jupyterCommand.Handler = CommandHandler.Create((options, console, context) => { @@ -335,8 +337,10 @@ Command Pack() { var packCommand = new Command("pack", "Create a Try .NET package"); packCommand.IsHidden = true; - packCommand.Argument = new Argument(); - packCommand.Argument.Name = nameof(PackOptions.PackTarget); + packCommand.AddArgument(new Argument + { + Name = nameof(PackOptions.PackTarget) + }); packCommand.AddOption(new Option("--version", "The version of the Try .NET package", @@ -356,8 +360,10 @@ Command Pack() Command Install() { var installCommand = new Command("install", "Install a Try .NET package"); - installCommand.Argument = new Argument(); - installCommand.Argument.Name = nameof(InstallOptions.PackageName); + installCommand.AddArgument(new Argument + { + Name = nameof(InstallOptions.PackageName) + }); installCommand.IsHidden = true; var option = new Option("--add-source", @@ -372,14 +378,15 @@ Command Install() Command Verify() { - var verifyCommand = new Command("verify", "Verify Markdown files in the target directory and its children.") + var dir = new Argument(() => new DirectoryInfo(Directory.GetCurrentDirectory())) { - Argument = new Argument(() => new DirectoryInfo(Directory.GetCurrentDirectory())) - { - Name = nameof(VerifyOptions.Dir).ToLower(), - Description = "Specify the path to the root directory" - }.ExistingOnly() - }; + Name = nameof(VerifyOptions.Dir).ToLower(), + Description = "Specify the path to the root directory" + }.ExistingOnly(); + + var verifyCommand = new Command("verify", "Verify Markdown files in the target directory and its children."); + + verifyCommand.AddArgument(dir); verifyCommand.Handler = CommandHandler.Create((options, console, startupOptions) => { diff --git a/MLS.Agent/MLS.Agent.csproj b/MLS.Agent/MLS.Agent.csproj index 452b99c54..e6f08357a 100644 --- a/MLS.Agent/MLS.Agent.csproj +++ b/MLS.Agent/MLS.Agent.csproj @@ -86,7 +86,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all @@ -126,11 +126,7 @@ - + <_TryDotNetCssExists Condition="Exists('$(MSBuildThisFileDirectory)wwwroot\css\trydotnet.css')">true @@ -164,12 +160,7 @@ - + <_TryDotNetMinJsExists Condition="Exists('$(TryDotNetJsFile)')">true @@ -187,12 +178,7 @@ - + <_TryDotNetClientExists Condition="Exists('$(ClientOutputFile)')">true diff --git a/MLS.Agent/Markdown/LocalCodeFenceAnnotationsParser.cs b/MLS.Agent/Markdown/LocalCodeFenceAnnotationsParser.cs index b1e33ed32..2e36681c2 100644 --- a/MLS.Agent/Markdown/LocalCodeFenceAnnotationsParser.cs +++ b/MLS.Agent/Markdown/LocalCodeFenceAnnotationsParser.cs @@ -66,22 +66,25 @@ protected override ModelBinder CreateModelBinder() private static void AddSourceFileOption(Command command) { var sourceFileArg = new Argument( - result => - { - var filename = result.Tokens.Select(t => t.Value).SingleOrDefault(); - - if (filename == null) - { - return ArgumentResult.Success(null); - } - - if (RelativeFilePath.TryParse(filename, out var relativeFilePath)) - { - return ArgumentResult.Success(relativeFilePath); - } - - return ArgumentResult.Failure($"Error parsing the filename: {filename}"); - }) + (SymbolResult result, out RelativeFilePath relativeFilePath) => + { + var filename = result.Tokens.Select(t => t.Value).SingleOrDefault(); + + if (filename == null) + { + relativeFilePath = null; + return true; + } + + if (RelativeFilePath.TryParse(filename, out relativeFilePath)) + { + return true; + } + + result.ErrorMessage = $"Error parsing the filename: {filename}"; + + return false; + }) { Name = "SourceFile", Arity = ArgumentArity.ZeroOrOne @@ -112,17 +115,22 @@ private static void AddProjectOption( IDirectoryAccessor directoryAccessor, string projectFileExtension) { - var projectOptionArgument = new Argument(result => - { - var projectPath = new RelativeFilePath(result.Tokens.Select(t => t.Value).Single()); - - if (directoryAccessor.FileExists(projectPath)) + var projectOptionArgument = new Argument( + (SymbolResult result, out FileInfo projectFile) => { - return ArgumentResult.Success(directoryAccessor.GetFullyQualifiedPath(projectPath)); - } + var projectPath = new RelativeFilePath(result.Tokens.Select(t => t.Value).Single()); - return ArgumentResult.Failure($"Project not found: {projectPath.Value}"); - }) + if (directoryAccessor.FileExists(projectPath)) + { + projectFile = directoryAccessor.GetFullyQualifiedFilePath(projectPath); + + return true; + } + + result.ErrorMessage = $"Project not found: {projectPath.Value}"; + projectFile = null; + return false; + }) { Name = "project", Arity = ArgumentArity.ExactlyOne diff --git a/MLS.PackageTool/MLS.PackageTool.csproj b/MLS.PackageTool/MLS.PackageTool.csproj index 758030691..be9da3b63 100644 --- a/MLS.PackageTool/MLS.PackageTool.csproj +++ b/MLS.PackageTool/MLS.PackageTool.csproj @@ -20,7 +20,7 @@ - + diff --git a/Microsoft.DotNet.Try.Client/package-lock.json b/Microsoft.DotNet.Try.Client/package-lock.json index ae6558cdc..12fe1595c 100644 --- a/Microsoft.DotNet.Try.Client/package-lock.json +++ b/Microsoft.DotNet.Try.Client/package-lock.json @@ -4560,8 +4560,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -4582,14 +4581,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -4604,20 +4601,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -4734,8 +4728,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -4747,7 +4740,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -4762,7 +4754,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -4770,14 +4761,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -4796,7 +4785,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -4877,8 +4865,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -4890,7 +4877,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -4976,8 +4962,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -5013,7 +4998,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -5033,7 +5017,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -5077,14 +5060,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, @@ -9743,8 +9724,7 @@ "version": "1.2.0", "resolved": "https://msazure.pkgs.visualstudio.com/_packaging/MLS/npm/registry/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true, - "optional": true + "dev": true } } }, diff --git a/Microsoft.DotNet.Try.Markdown/Microsoft.DotNet.Try.Markdown.csproj b/Microsoft.DotNet.Try.Markdown/Microsoft.DotNet.Try.Markdown.csproj index 4c7ba20a9..96cfb1efe 100644 --- a/Microsoft.DotNet.Try.Markdown/Microsoft.DotNet.Try.Markdown.csproj +++ b/Microsoft.DotNet.Try.Markdown/Microsoft.DotNet.Try.Markdown.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 @@ -13,7 +13,7 @@ - + diff --git a/Microsoft.DotNet.Try.ProjectTemplate/Tutorial/content/Microsoft.DotNet.Try.ProjectTemplate.Tutorial.csproj b/Microsoft.DotNet.Try.ProjectTemplate/Tutorial/content/Microsoft.DotNet.Try.ProjectTemplate.Tutorial.csproj index 67b9c73c2..cec2817ba 100644 --- a/Microsoft.DotNet.Try.ProjectTemplate/Tutorial/content/Microsoft.DotNet.Try.ProjectTemplate.Tutorial.csproj +++ b/Microsoft.DotNet.Try.ProjectTemplate/Tutorial/content/Microsoft.DotNet.Try.ProjectTemplate.Tutorial.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/Microsoft.DotNet.Try.js/package-lock.json b/Microsoft.DotNet.Try.js/package-lock.json index 32e72fbf3..fb8dadc16 100644 --- a/Microsoft.DotNet.Try.js/package-lock.json +++ b/Microsoft.DotNet.Try.js/package-lock.json @@ -5700,8 +5700,7 @@ "version": "1.2.0", "resolved": "https://msazure.pkgs.visualstudio.com/_packaging/MLS/npm/registry/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true, - "optional": true + "dev": true } } }, diff --git a/Samples/Beginners/myapp/myapp.csproj b/Samples/Beginners/myapp/myapp.csproj index b282444b6..4656c801e 100644 --- a/Samples/Beginners/myapp/myapp.csproj +++ b/Samples/Beginners/myapp/myapp.csproj @@ -6,8 +6,8 @@ - - + + diff --git a/Samples/csharp8/ExploreCsharpEight/ExploreCsharpEight.csproj b/Samples/csharp8/ExploreCsharpEight/ExploreCsharpEight.csproj index ad8f5c904..d2523d3d8 100644 --- a/Samples/csharp8/ExploreCsharpEight/ExploreCsharpEight.csproj +++ b/Samples/csharp8/ExploreCsharpEight/ExploreCsharpEight.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/WasmCodeRunner/CommandLineBuilderExtensions.cs b/WasmCodeRunner/CommandLineBuilderExtensions.cs index 4977c7cc3..88ac86483 100644 --- a/WasmCodeRunner/CommandLineBuilderExtensions.cs +++ b/WasmCodeRunner/CommandLineBuilderExtensions.cs @@ -30,8 +30,6 @@ public static CommandLineBuilder ConfigureRootCommandFromMethod( builder.Command.ConfigureFromMethod(method); - - return builder; } @@ -64,11 +62,11 @@ public static void ConfigureFromMethod( if (method.GetParameters() .FirstOrDefault(p => _argumentParameterNames.Contains(p.Name)) is ParameterInfo argsParam) { - command.Argument = new Argument + command.AddArgument(new Argument { ArgumentType = argsParam.ParameterType, Name = argsParam.Name - }; + }); } command.Handler = CommandHandler.Create(method); @@ -89,7 +87,7 @@ public static IEnumerable