From d40a87bc443c7f6ce42386ad366d912be10ddb1a Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Thu, 2 Mar 2017 19:36:51 -0800 Subject: [PATCH 001/149] introduce dotnet complete command --- scripts/register-completions.bash | 15 + scripts/register-completions.ps1 | 6 + scripts/register-completions.zsh | 12 + src/dotnet/MsbuildProject.cs | 7 + src/dotnet/Program.cs | 3 + src/dotnet/ProjectExtensions.cs | 11 +- .../dotnet-complete/CompleteCommand.cs | 68 +++ src/dotnet/dotnet-complete/commands/Create.cs | 529 ++++++++++++++++++ src/dotnet/dotnet.csproj | 1 + 9 files changed, 650 insertions(+), 2 deletions(-) create mode 100644 scripts/register-completions.bash create mode 100644 scripts/register-completions.ps1 create mode 100644 scripts/register-completions.zsh create mode 100644 src/dotnet/commands/dotnet-complete/CompleteCommand.cs create mode 100644 src/dotnet/dotnet-complete/commands/Create.cs diff --git a/scripts/register-completions.bash b/scripts/register-completions.bash new file mode 100644 index 000000000..635e59112 --- /dev/null +++ b/scripts/register-completions.bash @@ -0,0 +1,15 @@ +#!/bin/bash +# Parameter completion for the dotnet CLI + +_dotnet_bash_complete() +{ + local word=${COMP_WORDS[COMP_CWORD]} + local dotnetPath=${COMP_WORDS[1]} + + local completions=("$(./bin/Debug/netcoreapp1.0/osx.10.11-x64/publish/dotnet complete --position ${COMP_POINT} "${COMP_LINE}")") + + # https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html + COMPREPLY=( $(compgen -W "$completions" -- "$word") ) +} + +complete -f -F _dotnet_bash_complete dotnet \ No newline at end of file diff --git a/scripts/register-completions.ps1 b/scripts/register-completions.ps1 new file mode 100644 index 000000000..cc19f9702 --- /dev/null +++ b/scripts/register-completions.ps1 @@ -0,0 +1,6 @@ +Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock { + param($commandName, $wordToComplete, $cursorPosition) + C:\dev\github\cli\artifacts\win10-x64\stage2\dotnet.exe complete --position $cursorPosition "$wordToComplete" | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) + } + } \ No newline at end of file diff --git a/scripts/register-completions.zsh b/scripts/register-completions.zsh new file mode 100644 index 000000000..727897232 --- /dev/null +++ b/scripts/register-completions.zsh @@ -0,0 +1,12 @@ +# Parameter completion for the dotnet CLI + +_dotnet_zsh_complete() +{ + local dotnetPath=$words[1] + + local completions=("$(./bin/Debug/netcoreapp1.0/osx.10.11-x64/publish/dotnet complete "$words")") + + reply=( "${(ps:\n:)completions}" ) +} + +compctl -K _dotnet_zsh_complete dotnet \ No newline at end of file diff --git a/src/dotnet/MsbuildProject.cs b/src/dotnet/MsbuildProject.cs index 1f5811cd2..860d38799 100644 --- a/src/dotnet/MsbuildProject.cs +++ b/src/dotnet/MsbuildProject.cs @@ -24,6 +24,7 @@ namespace Microsoft.DotNet.Tools private ProjectCollection _projects; private List _cachedTfms = null; + private IEnumerable cachedRuntimeIdentifiers; private MsbuildProject(ProjectCollection projects, ProjectRootElement project) { @@ -149,6 +150,12 @@ namespace Microsoft.DotNet.Tools return ProjectRootElement.GetAllItemsWithElementType(ProjectItemElementType); } + public IEnumerable GetRuntimeIdentifiers() + { + return cachedRuntimeIdentifiers ?? + (cachedRuntimeIdentifiers = GetEvaluatedProject().GetRuntimeIdentifiers()); + } + public IEnumerable GetTargetFrameworks() { if (_cachedTfms != null) diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 12aaf631f..38e570881 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -12,6 +12,7 @@ using Microsoft.DotNet.PlatformAbstractions; using Microsoft.DotNet.Tools.Add; using Microsoft.DotNet.Tools.Build; using Microsoft.DotNet.Tools.Clean; +using Microsoft.DotNet.Tools.Complete; using Microsoft.DotNet.Tools.Help; using Microsoft.DotNet.Tools.List; using Microsoft.DotNet.Tools.Migrate; @@ -29,6 +30,7 @@ using Microsoft.DotNet.Tools.Test; using Microsoft.DotNet.Tools.VSTest; using Microsoft.DotNet.Tools.Cache; using NuGet.Frameworks; +using Command = Microsoft.DotNet.Cli.Utils.Command; namespace Microsoft.DotNet.Cli { @@ -54,6 +56,7 @@ namespace Microsoft.DotNet.Cli ["sln"] = SlnCommand.Run, ["test"] = TestCommand.Run, ["vstest"] = VSTestCommand.Run, + ["complete"] = CompleteCommand.Run, }; public static int Main(string[] args) diff --git a/src/dotnet/ProjectExtensions.cs b/src/dotnet/ProjectExtensions.cs index 1ed154477..ab5065383 100644 --- a/src/dotnet/ProjectExtensions.cs +++ b/src/dotnet/ProjectExtensions.cs @@ -1,9 +1,7 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Build.Construction; using Microsoft.Build.Evaluation; -using Microsoft.DotNet.ProjectJsonMigration; using NuGet.Frameworks; using System.Collections.Generic; using System.Linq; @@ -12,6 +10,15 @@ namespace Microsoft.DotNet.Tools.ProjectExtensions { internal static class ProjectExtensions { + public static IEnumerable GetRuntimeIdentifiers(this Project project) + { + return project + .GetPropertyCommaSeparatedValues("RuntimeIdentifier") + .Concat(project.GetPropertyCommaSeparatedValues("RuntimeIdentifiers")) + .Select(value => value.ToLower()) + .Distinct(); + } + public static IEnumerable GetTargetFrameworks(this Project project) { var targetFramewoksStrings = project diff --git a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs new file mode 100644 index 000000000..ed05473af --- /dev/null +++ b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs @@ -0,0 +1,68 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.IO; +using System.Linq; +using System.Text; +using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Cli.Utils; +using Command = Microsoft.DotNet.Cli.CommandLine.Command; + +namespace Microsoft.DotNet.Tools.Complete +{ + public class CompleteCommand + { + private static readonly Command dotnetCommand = Create.DotnetCommand(); + + public static int Run(string[] args) + { + DebugHelper.HandleDebugSwitch(ref args); + + var log = new StringBuilder(); + log.AppendLine($"args: {string.Join(" ", args.Select(a => $"\"{a}\""))}"); + + var result = dotnetCommand["complete"].Parse(args); + + log.AppendLine("diagram (1): " + result.Diagram()); + + var complete = result["complete"]; + + var suggestions = Suggestions(complete, log); + + log.AppendLine($"suggestions: {Environment.NewLine}{string.Join(Environment.NewLine, suggestions)}"); + + File.WriteAllText("parse.log", log.ToString()); + + foreach (var suggestion in suggestions) + { + Console.WriteLine(suggestion); + } + + return 0; + } + + private static string[] Suggestions(AppliedOption complete, StringBuilder log) + { + var input = complete.Arguments.SingleOrDefault() ?? ""; + + var positionOption = complete.AppliedOptions.SingleOrDefault(a => a.Name == "position"); + if (positionOption != null) + { + var position = positionOption.Value(); + + if (position > input.Length) + { + input += " "; + } + } + + var result = dotnetCommand.Parse(input); + + log.AppendLine("diagram (2): " + result.Diagram()); + + return result.Suggestions() + .ToArray(); + } + } +} \ No newline at end of file diff --git a/src/dotnet/dotnet-complete/commands/Create.cs b/src/dotnet/dotnet-complete/commands/Create.cs new file mode 100644 index 000000000..0650a6079 --- /dev/null +++ b/src/dotnet/dotnet-complete/commands/Create.cs @@ -0,0 +1,529 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Threading; +using Microsoft.Build.Evaluation; +using Microsoft.DotNet.Cli.CommandLine; +using Newtonsoft.Json.Linq; +using static Microsoft.DotNet.Cli.CommandLine.Accept; +using static Microsoft.DotNet.Cli.CommandLine.Create; +using Command = Microsoft.DotNet.Cli.CommandLine.Command; + +namespace Microsoft.DotNet.Tools.Complete +{ + public static class Create + { + public static Command DotnetCommand() => + Command("dotnet", + ".NET Command Line Tools (2.0.0-alpha-alpha-004866)", + NoArguments, + New(), + Restore(), + Build(), + Publish(), + Run(), + Test(), + Pack(), + Migrate(), + Clean(), + Sln(), + Add(), + Remove(), + List(), + NuGet(), + Command("msbuild", ""), + Command("vstest", ""), + Complete(), + HelpOption(), + Option("--info", ""), + VerbosityOption()); + + private static Command Complete() => + Command("complete", "", + ExactlyOneArgument + .With(name: "path"), + Option("--position", "", + ExactlyOneArgument + .With(name: "command"), + o => int.Parse(o.Arguments.Single()))); + + private static Command Add() => + Command("add", "", + ExactlyOneArgument, + Package(), + Reference(), + HelpOption()); + + private static Command Build() => + Command("build", + ".NET Builder", + HelpOption(), + Option("-o|--output", + "Output directory in which to place built artifacts.", + ExactlyOneArgument + .With(name: "OUTPUT_DIR")), + Option("-f|--framework", + "Target framework to build for. The target framework has to be specified in the project file.", + AnyOneOf(TargetFrameworksFromProjectFile)), + Option("-r|--runtime", + "Target runtime to build for. The default is to build a portable application.", + WithSuggestionsFrom(_ => RunTimesFromProjectFile())), + Option("-c|--configuration", + "Configuration to use for building the project. Default for most projects is \"Debug\".", + ExactlyOneArgument + .With(name: "CONFIGURATION") + .WithSuggestionsFrom(_ => new[] { "DEBUG", "RELEASE" })), + Option("--version-suffix", "Defines the value for the $(VersionSuffix) property in the project", + ExactlyOneArgument + .With(name: "VERSION_SUFFIX")), + Option("--no-incremental", "Disables incremental build."), + Option("--no-dependencies", "Set this flag to ignore project-to-project references and only build the root project"), + VerbosityOption()); + + private static Command Clean() => + Command("clean", + ".NET Clean Command", + HelpOption(), + Option("-o|--output", "Directory in which the build outputs have been placed.", + ExactlyOneArgument + .With(name: "OUTPUT_DIR")), + Option("-f|--framework", "Clean a specific framework.", + ExactlyOneArgument + .With(name: "FRAMEWORK") + .WithSuggestionsFrom(_ => TargetFrameworksFromProjectFile())), + Option("-c|--configuration", + "Clean a specific configuration.", + ExactlyOneArgument + .With(name: "CONFIGURATION") + .WithSuggestionsFrom(_ => new[] { "DEBUG", "RELEASE" }))); + + private static Command List() => + Command("list", "", + ExactlyOneArgument + .With(name: "PROJECT", + description: + "The project file to operate on. If a file is not specified, the command will search the current directory for one."), + HelpOption(), + Command("reference", "Command to list project to project references", + ExactlyOneArgument + .With(name: "PROJECT") + .With(description: "The project file to operate on. If a file is not specified, the command will search the current directory for one."), + HelpOption())); + + private static Command Migrate() => + Command("migrate", + ".NET Migrate Command", + HelpOption(), + Option("-t|--template-file", + "Base MSBuild template to use for migrated app. The default is the project included in dotnet new."), + Option("-v|--sdk-package-version", + "The version of the SDK package that will be referenced in the migrated app. The default is the version of the SDK in dotnet new."), + Option("-x|--xproj-file", + "The path to the xproj file to use. Required when there is more than one xproj in a project directory."), + Option("-s|--skip-project-references", + "Skip migrating project references. By default, project references are migrated recursively."), + Option("-r|--report-file", + "Output migration report to the given file in addition to the console."), + Option("--format-report-file-json", + "Output migration report file as json rather than user messages."), + Option("--skip-backup", + "Skip moving project.json, global.json, and *.xproj to a `backup` directory after successful migration.")); + + private static Command New() => + Command("new", + "Initialize .NET projects.", + WithSuggestionsFrom("console", + "classlib", + "mstest", + "xunit", + "web", + "mvc", + "webapi", + "sln"), + Option("-l|--list", + "List templates containing the specified name."), + Option("-lang|--language", + "Specifies the language of the template to create", + WithSuggestionsFrom("C#", "F#") + .With(defaultValue: () => "C#")), + Option("-n|--name", + "The name for the output being created. If no name is specified, the name of the current directory is used."), + Option("-o|--output", + "Location to place the generated output."), + Option("-h|--help", + "Displays help for this command."), + Option("-all|--show-all", + "Shows all templates")); + + private static Command NuGet() => + Command("nuget", + "NuGet Command Line 4.0.0.0", + HelpOption(), + Option("--version", + "Show version information"), + Option("-v|--verbosity", + "The verbosity of logging to use. Allowed values: Debug, Verbose, Information, Minimal, Warning, Error.", + ExactlyOneArgument + .With(name: "verbosity")), + Command("delete", + "Deletes a package from the server.", + ExactlyOneArgument + .With(name: "root", + description: "The Package Id and version."), + HelpOption(), + Option("--force-english-output", + "Forces the application to run using an invariant, English-based culture."), + Option("-s|--source", + "Specifies the server URL", + ExactlyOneArgument + .With(name: "source")), + Option("--non-interactive", + "Do not prompt for user input or confirmations."), + Option("-k|--api-key", + "The API key for the server.", + ExactlyOneArgument + .With(name: "apiKey"))), + Command("locals", + "Clears or lists local NuGet resources such as http requests cache, packages cache or machine-wide global packages folder.", + AnyOneOf(@"all", @"http-cache", @"global-packages", @"temp") + .With(description: "Cache Location(s) Specifies the cache location(s) to list or clear."), + HelpOption(), + Option("--force-english-output", + "Forces the application to run using an invariant, English-based culture."), + Option("-c|--clear", "Clear the selected local resources or cache location(s)."), + Option("-l|--list", "List the selected local resources or cache location(s).")), + Command("push", + "Pushes a package to the server and publishes it.", + HelpOption(), + Option("--force-english-output", + "Forces the application to run using an invariant, English-based culture."), + Option("-s|--source", + "Specifies the server URL", + ExactlyOneArgument + .With(name: "source")), + Option("-ss|--symbol-source", + "Specifies the symbol server URL. If not specified, nuget.smbsrc.net is used when pushing to nuget.org.", + ExactlyOneArgument + .With(name: "source")), + Option("-t|--timeout", + "Specifies the timeout for pushing to a server in seconds. Defaults to 300 seconds (5 minutes).", + ExactlyOneArgument + .With(name: "timeout")), + Option("-k|--api-key", "The API key for the server.", + ExactlyOneArgument + .With(name: "apiKey")), + Option("-sk|--symbol-api-key", "The API key for the symbol server.", + ExactlyOneArgument + .With(name: "apiKey")), + Option("-d|--disable-buffering", + "Disable buffering when pushing to an HTTP(S) server to decrease memory usage."), + Option("-n|--no-symbols", + "If a symbols package exists, it will not be pushed to a symbols server."))); + + private static Command Pack() => + Command("pack", + ".NET Core NuGet Package Packer", + HelpOption(), + Option("-o|--output", + "Directory in which to place built packages.", + ExactlyOneArgument + .With(name: "OUTPUT_DIR")), + Option("--no-build", + "Skip building the project prior to packing. By default, the project will be built."), + Option("--include-symbols", + "Include packages with symbols in addition to regular packages in output directory."), + Option("--include-source", + "Include PDBs and source files. Source files go into the src folder in the resulting nuget package"), + Option("-c|--configuration", + "Configuration to use for building the project. Default for most projects is \"Debug\".", + ExactlyOneArgument + .With(name: "CONFIGURATION") + .WithSuggestionsFrom(_ => new[] { "DEBUG", "RELEASE" })), + Option("--version-suffix", + "Defines the value for the $(VersionSuffix) property in the project.", + ExactlyOneArgument + .With(name: "VERSION_SUFFIX")), + Option("-s|--serviceable", + "Set the serviceable flag in the package. For more information, please see https://aka.ms/nupkgservicing."), + VerbosityOption() + ); + + private static Command Package() => + Command("package", + ".NET Add Package reference Command", + ExactlyOneArgument + .WithSuggestionsFrom(QueryNuGet), + HelpOption(), + Option("-v|--version", + "Version for the package to be added.", + ExactlyOneArgument + .With(name: "VERSION")), + Option("-f|--framework", + "Add reference only when targetting a specific framework", + ExactlyOneArgument + .With(name: "FRAMEWORK")), + Option("-n|--no-restore ", + "Add reference without performing restore preview and compatibility check."), + Option("-s|--source", + "Use specific NuGet package sources to use during the restore."), + Option("--package-directory", + "Restore the packages to this Directory .", + ExactlyOneArgument + .With(name: "PACKAGE_DIRECTORY"))); + + private static Command Publish() => + Command("publish", + ".NET Publisher", + ExactlyOneArgument, + HelpOption(), + Option("-f|--framework", + "Target framework to publish for. The target framework has to be specified in the project file.", + AnyOneOf(TargetFrameworksFromProjectFile) + .With(name: "FRAMEWORK")), + Option("-r|--runtime", + "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.", + ExactlyOneArgument + .With(name: "RUNTIME_IDENTIFIER")), + Option("-o|--output", + "Output directory in which to place the published artifacts.", + ExactlyOneArgument + .With(name: "OUTPUT_DIR")), + Option("-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", + ExactlyOneArgument + .With(name: "CONFIGURATION") + .WithSuggestionsFrom(_ => new[] { "DEBUG", "RELEASE" })), + Option("--version-suffix", "Defines the value for the $(VersionSuffix) property in the project.", + ExactlyOneArgument + .With(name: "VERSION_SUFFIX")), + VerbosityOption()); + + private static Command Remove() => + Command("remove", + "", + HelpOption(), + Command("package", + "Command to remove package reference.", + HelpOption()), + Command("reference", + "Command to remove project to project reference", + WithSuggestionsFrom(_ => ProjectReferencesFromProjectFile()), + HelpOption(), + Option("-f|--framework", + "Remove reference only when targetting a specific framework", + ExactlyOneArgument + .With(name: "FRAMEWORK")))); + + private static Command Reference() => + Command("reference", + "Command to add project to project reference", + OneOrMoreArguments, + HelpOption(), + Option("-f|--framework", + "Add reference only when targetting a specific framework", + ExactlyOneArgument + .WithSuggestionsFrom( + _ => TargetFrameworksFromProjectFile().ToArray()) + // .With(name: "FRAMEWORK") + )); + + private static Command Restore() => + Command("restore", + ".NET dependency restorer", + HelpOption(), + Option("-s|--source", + "Specifies a NuGet package source to use during the restore.", + ExactlyOneArgument + .With(name: "SOURCE")), + Option("-r|--runtime", + "Target runtime to restore packages for.", + WithSuggestionsFrom(_ => RunTimesFromProjectFile()) + .With(name: "RUNTIME_IDENTIFIER")), + Option("--packages", + "Directory to install packages in.", + ExactlyOneArgument + .With(name: "PACKAGES_DIRECTORY")), + Option("--disable-parallel", + "Disables restoring multiple projects in parallel."), + Option("--configfile", + "The NuGet configuration file to use.", + ExactlyOneArgument + .With(name: "FILE")), + Option("--no-cache", + "Do not cache packages and http requests."), + Option("--ignore-failed-sources", + "Treat package source failures as warnings."), + Option("--no-dependencies", + "Set this flag to ignore project to project references and only restore the root project"), + VerbosityOption()); + + private static Command Run() => + Command("run", + ".NET Run Command", + HelpOption(), + Option("-c|--configuration", + @"Configuration to use for building the project. Default for most projects is ""Debug"".", + ExactlyOneArgument + .WithSuggestionsFrom(_ => new[] { "DEBUG", "RELEASE" })), + Option("-f|--framework", + "Build and run the app using the specified framework. The framework has to be specified in the project file.", + AnyOneOf(TargetFrameworksFromProjectFile)), + Option("-p|--project", + "The path to the project file to run (defaults to the current directory if there is only one project).", + ZeroOrOneArgument)); + + private static Command Sln() => + Command("sln", + ".NET modify solution file command", + HelpOption(), + Command("add", + ".NET Add project(s) to a solution file Command", + ExactlyOneArgument + .With(name: "SLN_FILE"), + HelpOption()), + Command("list", + "List all projects in the solution.", + ExactlyOneArgument + .With(name: "SLN_FILE"), + HelpOption()), + Command("remove", + "Remove the specified project(s) from the solution. The project is not impacted.")); + + private static Command Test() => + Command("test", + ".NET Test Driver", + Option("-h|--help", + "Show help information"), + Option("-s|--settings", + "Settings to use when running tests.", + ExactlyOneArgument + .With(name: "SETTINGS_FILE")), + Option("-t|--list-tests", + "Lists discovered tests"), + Option("--filter", + @"Run tests that match the given expression. + Examples: + Run tests with priority set to 1: --filter ""Priority = 1"" + Run a test with the specified full name: --filter ""FullyQualifiedName=Namespace.ClassName.MethodName"" + Run tests that contain the specified name: --filter ""FullyQualifiedName~Namespace.Class"" + More info on filtering support: https://aka.ms/vstest-filtering", + ExactlyOneArgument + .With(name: "EXPRESSION")), + Option("-a|--test-adapter-path", + "Use custom adapters from the given path in the test run.\r\n Example: --test-adapter-path "), + Option("-l|--logger", + "Specify a logger for test results.\r\n Example: --logger \"trx[;LogFileName=]\"", + ExactlyOneArgument + .With(name: "LoggerUri/FriendlyName")), + Option("-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", + ExactlyOneArgument + .With(name: "CONFIGURATION") + .WithSuggestionsFrom(_ => new[] { "DEBUG", "RELEASE" })), + Option("-f|--framework", + "Looks for test binaries for a specific framework", + AnyOneOf(() => TargetFrameworksFromProjectFile().ToArray()) + .With(name: "FRAMEWORK")), + Option("-o|--output", + "Directory in which to find the binaries to be run", + ExactlyOneArgument + .With(name: "OUTPUT_DIR")), + Option("-d|--diag", + "Enable verbose logs for test platform.\r\n Logs are written to the provided file.", + ExactlyOneArgument + .With(name: "PATH_TO_FILE")), + Option("--no-build", + "Do not build project before testing."), + VerbosityOption()); + + private static Option HelpOption() => + Option("-h|--help", + "Show help information", + NoArguments, + materialize: o => o.Option.Command().HelpView()); + + private static Option VerbosityOption() => + Option("-v|--verbosity", + "Set the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]", + AnyOneOf("q[uiet]", + "m[inimal]", + "n[ormal]", + "d[etailed]")); + + public static string[] KnownRuntimes = + { + "win10-x86", + "win10-x64", + "win10-arm64", + "osx.10.11-x64", + "centos.7-x64", + "debian.8-x64", + "linuxmint.17-x64", + "opensuse.13.2-x64", + "rhel.7.2-x64", + "ubuntu.14.04-x64", + "ubuntu.16.04-x64", + }; + + private static IEnumerable QueryNuGet(string match) + { + var httpClient = new HttpClient(); + + string result = null; + + try + { + var cancellation = new CancellationTokenSource(TimeSpan.FromSeconds(10)); + var response = httpClient.GetAsync($"https://api-v2v3search-0.nuget.org/query?q={match}&skip=0&take=100&prerelease=true", cancellation.Token) + .Result; + + result = response.Content.ReadAsStringAsync().Result; + } + catch (Exception) + { + yield break; + } + + var json = JObject.Parse(result); + + foreach (var id in json["data"]) + { + yield return id["id"].Value(); + } + } + + private static IEnumerable TargetFrameworksFromProjectFile() + { + var msbuildProj = MsbuildProject.FromFileOrDirectory( + new ProjectCollection(), + Directory.GetCurrentDirectory()); + + foreach (var tfm in msbuildProj.GetTargetFrameworks()) + { + yield return tfm.GetShortFolderName(); + } + } + + private static IEnumerable RunTimesFromProjectFile() + { + var msbuildProj = MsbuildProject.FromFileOrDirectory( + new ProjectCollection(), + Directory.GetCurrentDirectory()); + + return msbuildProj.GetRuntimeIdentifiers(); + } + + private static IEnumerable ProjectReferencesFromProjectFile() + { + var msbuildProj = MsbuildProject.FromFileOrDirectory( + new ProjectCollection(), + Directory.GetCurrentDirectory()); + + return msbuildProj.GetProjectToProjectReferences() + .Select(r => r.Include); + } + } +} \ No newline at end of file diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index a855b26b8..01bf57817 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -39,6 +39,7 @@ + From 614f71d19f69f3e2645ca1b3885de84a74eefadf Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Thu, 2 Mar 2017 21:45:44 -0800 Subject: [PATCH 002/149] add help text for a couple of commands --- src/dotnet/dotnet-complete/commands/Create.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dotnet/dotnet-complete/commands/Create.cs b/src/dotnet/dotnet-complete/commands/Create.cs index 0650a6079..72be2e7be 100644 --- a/src/dotnet/dotnet-complete/commands/Create.cs +++ b/src/dotnet/dotnet-complete/commands/Create.cs @@ -53,7 +53,8 @@ namespace Microsoft.DotNet.Tools.Complete o => int.Parse(o.Arguments.Single()))); private static Command Add() => - Command("add", "", + Command("add", + ".NET Add Command", ExactlyOneArgument, Package(), Reference(), @@ -103,7 +104,8 @@ namespace Microsoft.DotNet.Tools.Complete .WithSuggestionsFrom(_ => new[] { "DEBUG", "RELEASE" }))); private static Command List() => - Command("list", "", + Command("list", + ".NET List Command", ExactlyOneArgument .With(name: "PROJECT", description: @@ -304,7 +306,7 @@ namespace Microsoft.DotNet.Tools.Complete private static Command Remove() => Command("remove", - "", + ".NET Remove Command", HelpOption(), Command("package", "Command to remove package reference.", From 8b0dd3579c431f4c812bef9cda0bf63f0e99af91 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Fri, 3 Mar 2017 13:14:36 -0800 Subject: [PATCH 003/149] a couple of parser unit tests --- .../dotnet-complete/CompleteCommand.cs | 11 +- .../commands/ParserExtensions.cs | 11 ++ .../commands/{Create.cs => ParserFor.cs} | 132 ++++++++---------- src/dotnet/dotnet.csproj | 2 +- test/dotnet.Tests/ParseTests.cs | 54 +++++++ test/dotnet.Tests/dotnet.Tests.csproj | 1 + 6 files changed, 132 insertions(+), 79 deletions(-) create mode 100644 src/dotnet/dotnet-complete/commands/ParserExtensions.cs rename src/dotnet/dotnet-complete/commands/{Create.cs => ParserFor.cs} (89%) create mode 100644 test/dotnet.Tests/ParseTests.cs diff --git a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs index ed05473af..0518df868 100644 --- a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs +++ b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs @@ -7,14 +7,11 @@ using System.Linq; using System.Text; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; -using Command = Microsoft.DotNet.Cli.CommandLine.Command; namespace Microsoft.DotNet.Tools.Complete { public class CompleteCommand { - private static readonly Command dotnetCommand = Create.DotnetCommand(); - public static int Run(string[] args) { DebugHelper.HandleDebugSwitch(ref args); @@ -22,7 +19,11 @@ namespace Microsoft.DotNet.Tools.Complete var log = new StringBuilder(); log.AppendLine($"args: {string.Join(" ", args.Select(a => $"\"{a}\""))}"); - var result = dotnetCommand["complete"].Parse(args); + // get the parser for the current subcommand + var completeCommandParser = ParserFor.DotnetCommand["complete"]; + + // parse the arguments + var result = completeCommandParser.Parse(args); log.AppendLine("diagram (1): " + result.Diagram()); @@ -57,7 +58,7 @@ namespace Microsoft.DotNet.Tools.Complete } } - var result = dotnetCommand.Parse(input); + var result = ParserFor.DotnetCommand.Parse(input); log.AppendLine("diagram (2): " + result.Diagram()); diff --git a/src/dotnet/dotnet-complete/commands/ParserExtensions.cs b/src/dotnet/dotnet-complete/commands/ParserExtensions.cs new file mode 100644 index 000000000..825a1067c --- /dev/null +++ b/src/dotnet/dotnet-complete/commands/ParserExtensions.cs @@ -0,0 +1,11 @@ +using System; +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Tools +{ + public static class ParserExtensions + { + public static void ShowHelp(this ParseResult parseResult) => + Console.WriteLine(parseResult.Command().HelpView()); + } +} \ No newline at end of file diff --git a/src/dotnet/dotnet-complete/commands/Create.cs b/src/dotnet/dotnet-complete/commands/ParserFor.cs similarity index 89% rename from src/dotnet/dotnet-complete/commands/Create.cs rename to src/dotnet/dotnet-complete/commands/ParserFor.cs index 72be2e7be..cf64aa10f 100644 --- a/src/dotnet/dotnet-complete/commands/Create.cs +++ b/src/dotnet/dotnet-complete/commands/ParserFor.cs @@ -9,18 +9,18 @@ using System.Net.Http; using System.Threading; using Microsoft.Build.Evaluation; using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Tools.Common; using Newtonsoft.Json.Linq; using static Microsoft.DotNet.Cli.CommandLine.Accept; using static Microsoft.DotNet.Cli.CommandLine.Create; using Command = Microsoft.DotNet.Cli.CommandLine.Command; -namespace Microsoft.DotNet.Tools.Complete +namespace Microsoft.DotNet.Tools { - public static class Create + public static class ParserFor { - public static Command DotnetCommand() => - Command("dotnet", - ".NET Command Line Tools (2.0.0-alpha-alpha-004866)", + private static readonly Command _dotnetCommand = Command("dotnet", + ".NET Command Line Tools", NoArguments, New(), Restore(), @@ -41,7 +41,45 @@ namespace Microsoft.DotNet.Tools.Complete Complete(), HelpOption(), Option("--info", ""), - VerbosityOption()); + VerbosityOption(), + Option("-d", "")); + + public static Command DotnetCommand { get; } = _dotnetCommand; + + private static Command Add() => + Command("add", + ".NET Add Command", + ExactlyOneArgument.DefaultToCurrentDirectory(), + Command("package", + ".NET Add Package reference Command", + ExactlyOneArgument + .WithSuggestionsFrom(QueryNuGet), + HelpOption(), + Option("-v|--version", + "Version for the package to be added.", + ExactlyOneArgument + .With(name: "VERSION")), + Option("-f|--framework", + "Add reference only when targetting a specific framework", + ExactlyOneArgument + .With(name: "FRAMEWORK")), + Option("-n|--no-restore ", + "Add reference without performing restore preview and compatibility check."), + Option("-s|--source", + "Use specific NuGet package sources to use during the restore."), + Option("--package-directory", + "Restore the packages to this Directory .", + ExactlyOneArgument + .With(name: "PACKAGE_DIRECTORY"))), + Command("reference", + "Command to add project to project reference", + OneOrMoreArguments, + HelpOption(), + Option("-f|--framework", + "Add reference only when targetting a specific framework", + AnyOneOf(TargetFrameworksFromProjectFile) + .With(name: "FRAMEWORK"))), + HelpOption()); private static Command Complete() => Command("complete", "", @@ -52,14 +90,6 @@ namespace Microsoft.DotNet.Tools.Complete .With(name: "command"), o => int.Parse(o.Arguments.Single()))); - private static Command Add() => - Command("add", - ".NET Add Command", - ExactlyOneArgument, - Package(), - Reference(), - HelpOption()); - private static Command Build() => Command("build", ".NET Builder", @@ -73,7 +103,7 @@ namespace Microsoft.DotNet.Tools.Complete AnyOneOf(TargetFrameworksFromProjectFile)), Option("-r|--runtime", "Target runtime to build for. The default is to build a portable application.", - WithSuggestionsFrom(_ => RunTimesFromProjectFile())), + AnyOneOf(RunTimesFromProjectFile)), Option("-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", ExactlyOneArgument @@ -106,10 +136,11 @@ namespace Microsoft.DotNet.Tools.Complete private static Command List() => Command("list", ".NET List Command", - ExactlyOneArgument + ZeroOrOneArgument .With(name: "PROJECT", description: - "The project file to operate on. If a file is not specified, the command will search the current directory for one."), + "The project file to operate on. If a file is not specified, the command will search the current directory for one.") + .DefaultToCurrentDirectory(), HelpOption(), Command("reference", "Command to list project to project references", ExactlyOneArgument @@ -252,31 +283,7 @@ namespace Microsoft.DotNet.Tools.Complete .With(name: "VERSION_SUFFIX")), Option("-s|--serviceable", "Set the serviceable flag in the package. For more information, please see https://aka.ms/nupkgservicing."), - VerbosityOption() - ); - - private static Command Package() => - Command("package", - ".NET Add Package reference Command", - ExactlyOneArgument - .WithSuggestionsFrom(QueryNuGet), - HelpOption(), - Option("-v|--version", - "Version for the package to be added.", - ExactlyOneArgument - .With(name: "VERSION")), - Option("-f|--framework", - "Add reference only when targetting a specific framework", - ExactlyOneArgument - .With(name: "FRAMEWORK")), - Option("-n|--no-restore ", - "Add reference without performing restore preview and compatibility check."), - Option("-s|--source", - "Use specific NuGet package sources to use during the restore."), - Option("--package-directory", - "Restore the packages to this Directory .", - ExactlyOneArgument - .With(name: "PACKAGE_DIRECTORY"))); + VerbosityOption()); private static Command Publish() => Command("publish", @@ -289,7 +296,7 @@ namespace Microsoft.DotNet.Tools.Complete .With(name: "FRAMEWORK")), Option("-r|--runtime", "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.", - ExactlyOneArgument + AnyOneOf(RunTimesFromProjectFile) .With(name: "RUNTIME_IDENTIFIER")), Option("-o|--output", "Output directory in which to place the published artifacts.", @@ -307,32 +314,22 @@ namespace Microsoft.DotNet.Tools.Complete private static Command Remove() => Command("remove", ".NET Remove Command", + ZeroOrOneArgument + .With(name: "PROJECT") + .DefaultToCurrentDirectory(), HelpOption(), Command("package", "Command to remove package reference.", HelpOption()), Command("reference", "Command to remove project to project reference", - WithSuggestionsFrom(_ => ProjectReferencesFromProjectFile()), + AnyOneOf(ProjectReferencesFromProjectFile), HelpOption(), Option("-f|--framework", "Remove reference only when targetting a specific framework", ExactlyOneArgument .With(name: "FRAMEWORK")))); - private static Command Reference() => - Command("reference", - "Command to add project to project reference", - OneOrMoreArguments, - HelpOption(), - Option("-f|--framework", - "Add reference only when targetting a specific framework", - ExactlyOneArgument - .WithSuggestionsFrom( - _ => TargetFrameworksFromProjectFile().ToArray()) - // .With(name: "FRAMEWORK") - )); - private static Command Restore() => Command("restore", ".NET dependency restorer", @@ -343,7 +340,7 @@ namespace Microsoft.DotNet.Tools.Complete .With(name: "SOURCE")), Option("-r|--runtime", "Target runtime to restore packages for.", - WithSuggestionsFrom(_ => RunTimesFromProjectFile()) + AnyOneOf(RunTimesFromProjectFile) .With(name: "RUNTIME_IDENTIFIER")), Option("--packages", "Directory to install packages in.", @@ -381,6 +378,7 @@ namespace Microsoft.DotNet.Tools.Complete private static Command Sln() => Command("sln", ".NET modify solution file command", + HelpOption(), Command("add", ".NET Add project(s) to a solution file Command", @@ -441,6 +439,9 @@ namespace Microsoft.DotNet.Tools.Complete "Do not build project before testing."), VerbosityOption()); + private static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => + rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory())); + private static Option HelpOption() => Option("-h|--help", "Show help information", @@ -455,21 +456,6 @@ namespace Microsoft.DotNet.Tools.Complete "n[ormal]", "d[etailed]")); - public static string[] KnownRuntimes = - { - "win10-x86", - "win10-x64", - "win10-arm64", - "osx.10.11-x64", - "centos.7-x64", - "debian.8-x64", - "linuxmint.17-x64", - "opensuse.13.2-x64", - "rhel.7.2-x64", - "ubuntu.14.04-x64", - "ubuntu.16.04-x64", - }; - private static IEnumerable QueryNuGet(string match) { var httpClient = new HttpClient(); diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index 01bf57817..4a6355cd3 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -39,7 +39,7 @@ - + diff --git a/test/dotnet.Tests/ParseTests.cs b/test/dotnet.Tests/ParseTests.cs new file mode 100644 index 000000000..b4b5d5c2b --- /dev/null +++ b/test/dotnet.Tests/ParseTests.cs @@ -0,0 +1,54 @@ +using System; +using System.IO; +using FluentAssertions; +using System.Linq; +using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Tools; +using Microsoft.DotNet.Tools.Common; +using Xunit; +using Xunit.Abstractions; + +namespace Microsoft.DotNet.Tests +{ + public class AddReferenceParserTests + { + private readonly ITestOutputHelper output; + + public AddReferenceParserTests(ITestOutputHelper output) + { + this.output = output; + } + + [Fact] + public void dotnet_add_reference_has_default_argument_set_to_current_directory() + { + var command = ParserFor.DotnetCommand; + + var result = command.Parse("dotnet add reference my.csproj"); + + output.WriteLine(result.Diagram()); + + result["dotnet"]["add"] + .Arguments + .Should() + .BeEquivalentTo( + PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory())); + } + + [Fact] + public void dotnet_add_reference_without_argument_results_in_an_error() + { + var command = ParserFor.DotnetCommand["add"]; + + var result = command.Parse("add reference"); + + output.WriteLine(result.Diagram()); + + result + .Errors + .Select(e => e.Message) + .Should() + .BeEquivalentTo("Required argument missing for command: reference"); + } + } +} \ No newline at end of file diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index d360368cf..6d62e4124 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,5 +42,6 @@ + From 5f227c1c45419ceb70236b4e17b063d78485fee1 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Mon, 6 Mar 2017 11:57:19 -0800 Subject: [PATCH 004/149] split parser definitions across multiple files --- src/dotnet/CommonOptions.cs | 26 + src/dotnet/CompleteCommandParser.cs | 21 + src/dotnet/DotNetTopLevelCommandBase.cs | 76 +-- src/dotnet/ParseResultExtensions.cs | 14 + src/dotnet/Parser.cs | 37 ++ src/dotnet/Program.cs | 3 - .../commands/dotnet-add/AddCommandParser.cs | 74 +++ .../dotnet-build/BuildCommandParser.cs | 39 ++ .../dotnet-clean/CleanCommandParser.cs | 27 + .../dotnet-complete/CompleteCommand.cs | 24 +- .../commands/dotnet-list/ListCommandParser.cs | 26 + .../dotnet-migrate/MigrateCommandParser.cs | 29 + .../commands/dotnet-new/NewCommandParser.cs | 39 ++ .../dotnet-nuget/NuGetCommandParser.cs | 78 +++ .../commands/dotnet-pack/PackCommandParser.cs | 38 ++ .../dotnet-publish/PublishCommandParser.cs | 36 ++ .../dotnet-remove/RemoveCommandParser.cs | 29 + .../dotnet-restore/RestoreCommandParser.cs | 41 ++ .../commands/dotnet-run/RunCommandParser.cs | 25 + .../commands/dotnet-sln/SlnCommandParser.cs | 27 + .../commands/dotnet-test/TestCommandParser.cs | 54 ++ src/dotnet/dotnet-complete/Suggest.cs | 42 ++ .../commands/ParserExtensions.cs | 11 - .../dotnet-complete/commands/ParserFor.cs | 517 ------------------ src/dotnet/dotnet.csproj | 7 +- .../AddReferenceParserTests.cs} | 19 +- 26 files changed, 757 insertions(+), 602 deletions(-) create mode 100644 src/dotnet/CommonOptions.cs create mode 100644 src/dotnet/CompleteCommandParser.cs create mode 100644 src/dotnet/ParseResultExtensions.cs create mode 100644 src/dotnet/Parser.cs create mode 100644 src/dotnet/commands/dotnet-add/AddCommandParser.cs create mode 100644 src/dotnet/commands/dotnet-build/BuildCommandParser.cs create mode 100644 src/dotnet/commands/dotnet-clean/CleanCommandParser.cs create mode 100644 src/dotnet/commands/dotnet-list/ListCommandParser.cs create mode 100644 src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs create mode 100644 src/dotnet/commands/dotnet-new/NewCommandParser.cs create mode 100644 src/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs create mode 100644 src/dotnet/commands/dotnet-pack/PackCommandParser.cs create mode 100644 src/dotnet/commands/dotnet-publish/PublishCommandParser.cs create mode 100644 src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs create mode 100644 src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs create mode 100644 src/dotnet/commands/dotnet-run/RunCommandParser.cs create mode 100644 src/dotnet/commands/dotnet-sln/SlnCommandParser.cs create mode 100644 src/dotnet/commands/dotnet-test/TestCommandParser.cs create mode 100644 src/dotnet/dotnet-complete/Suggest.cs delete mode 100644 src/dotnet/dotnet-complete/commands/ParserExtensions.cs delete mode 100644 src/dotnet/dotnet-complete/commands/ParserFor.cs rename test/dotnet.Tests/{ParseTests.cs => ParserTests/AddReferenceParserTests.cs} (65%) diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs new file mode 100644 index 000000000..7cabd551c --- /dev/null +++ b/src/dotnet/CommonOptions.cs @@ -0,0 +1,26 @@ +using System.IO; +using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Tools.Common; + +namespace Microsoft.DotNet.Cli +{ + internal static class CommonOptions + { + public static Option HelpOption() => + Create.Option("-h|--help", + "Show help information", + Accept.NoArguments, + materialize: o => o.Option.Command().HelpView()); + + public static Option VerbosityOption() => + Create.Option("-v|--verbosity", + "Set the verbosity level of the command. Allowed values are q[uiet],m[inimal],n[ormal],d[etailed], anddiag[nostic]", + Accept.AnyOneOf("quiet", + "minimal", + "normal", + "detailed")); + + public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => + rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory())); + } +} \ No newline at end of file diff --git a/src/dotnet/CompleteCommandParser.cs b/src/dotnet/CompleteCommandParser.cs new file mode 100644 index 000000000..b4add15ea --- /dev/null +++ b/src/dotnet/CompleteCommandParser.cs @@ -0,0 +1,21 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Linq; +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + internal static class CompleteCommandParser + { + public static Command Complete() => + Create.Command("complete", "", + Accept.ExactlyOneArgument + .With(name: "path"), + Create.Option("--position", "", + Accept.ExactlyOneArgument + .With(name: "command"), + o => Int32.Parse(o.Arguments.Single()))); + } +} \ No newline at end of file diff --git a/src/dotnet/DotNetTopLevelCommandBase.cs b/src/dotnet/DotNetTopLevelCommandBase.cs index 640d8dccc..89aa1a6e6 100644 --- a/src/dotnet/DotNetTopLevelCommandBase.cs +++ b/src/dotnet/DotNetTopLevelCommandBase.cs @@ -3,12 +3,9 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.Tools; -using Microsoft.DotNet.Tools.Common; namespace Microsoft.DotNet.Cli { @@ -24,61 +21,44 @@ namespace Microsoft.DotNet.Cli { DebugHelper.HandleDebugSwitch(ref args); - CommandLineApplication command = new CommandLineApplication(throwOnUnexpectedArg: true) + var result = Parser.DotnetCommand[CommandName] + .Parse(args); + + Reporter.Verbose.WriteLine(result.Diagram()); + + var command = result[CommandName]; + + if (command.HasOption("help")) { - Name = $"dotnet {CommandName}", - FullName = FullCommandNameLocalized, - }; - - command.HelpOption("-h|--help"); - - command.Argument(ArgumentName, ArgumentDescriptionLocalized); - - foreach (var subCommandCreator in SubCommands) - { - var subCommand = subCommandCreator(); - command.AddCommand(subCommand); - - subCommand.OnExecute(() => { - try - { - if (!command.Arguments.Any()) - { - throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, ArgumentDescriptionLocalized); - } - - var projectOrDirectory = command.Arguments.First().Value; - if (string.IsNullOrEmpty(projectOrDirectory)) - { - projectOrDirectory = PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory()); - } - - return subCommand.Run(projectOrDirectory); - } - catch (GracefulException e) - { - Reporter.Error.WriteLine(e.Message.Red()); - subCommand.ShowHelp(); - return 1; - } - }); + result.ShowHelp(); + return 0; } + if (result.Errors.Any()) + { + Reporter.Error.WriteLine(result.Errors.First().Message.Red()); + return 1; + } + + var subCommand = SubCommands + .Select(c => c()) + .FirstOrDefault(c => c.Name == command.AppliedOptions.First().Name); + + var fileOrDirectory = command.AppliedOptions + .First() + .Arguments + .FirstOrDefault(); + try { - return command.Execute(args); + return subCommand.Run(fileOrDirectory); } catch (GracefulException e) { Reporter.Error.WriteLine(e.Message.Red()); - command.ShowHelp(); - return 1; - } - catch (CommandParsingException e) - { - Reporter.Error.WriteLine(e.Message.Red()); + subCommand.ShowHelp(); return 1; } } } -} +} \ No newline at end of file diff --git a/src/dotnet/ParseResultExtensions.cs b/src/dotnet/ParseResultExtensions.cs new file mode 100644 index 000000000..1eeac1662 --- /dev/null +++ b/src/dotnet/ParseResultExtensions.cs @@ -0,0 +1,14 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + public static class ParseResultExtensions + { + public static void ShowHelp(this ParseResult parseResult) => + Console.WriteLine(parseResult.Command().HelpView()); + } +} \ No newline at end of file diff --git a/src/dotnet/Parser.cs b/src/dotnet/Parser.cs new file mode 100644 index 000000000..c57e9d87b --- /dev/null +++ b/src/dotnet/Parser.cs @@ -0,0 +1,37 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Linq; +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + public static class Parser + { + public static Command DotnetCommand { get; } = + Create.Command("dotnet", + ".NET Command Line Tools", + Accept.NoArguments, + NewCommandParser.New(), + RestoreCommandParser.Restore(), + BuildCommandParser.Build(), + PublishCommandParser.Publish(), + RunCommandParser.Run(), + TestCommandParser.Test(), + PackCommandParser.Pack(), + MigrateCommandParser.Migrate(), + CleanCommandParser.Clean(), + SlnCommandParser.Sln(), + AddCommandParser.Add(), + RemoveCommandParser.Remove(), + ListCommandParser.List(), + NuGetCommandParser.NuGet(), + Create.Command("msbuild", ""), + Create.Command("vstest", ""), CompleteCommandParser.Complete(), + CommonOptions.HelpOption(), + Create.Option("--info", ""), + CommonOptions.VerbosityOption(), + Create.Option("-d", "")); + } +} \ No newline at end of file diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 38e570881..d463dea58 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -6,13 +6,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Configurer; using Microsoft.DotNet.PlatformAbstractions; using Microsoft.DotNet.Tools.Add; using Microsoft.DotNet.Tools.Build; using Microsoft.DotNet.Tools.Clean; -using Microsoft.DotNet.Tools.Complete; using Microsoft.DotNet.Tools.Help; using Microsoft.DotNet.Tools.List; using Microsoft.DotNet.Tools.Migrate; @@ -23,7 +21,6 @@ using Microsoft.DotNet.Tools.Pack; using Microsoft.DotNet.Tools.Publish; using Microsoft.DotNet.Tools.Remove; using Microsoft.DotNet.Tools.Restore; -using Microsoft.DotNet.Tools.RestoreProjectJson; using Microsoft.DotNet.Tools.Run; using Microsoft.DotNet.Tools.Sln; using Microsoft.DotNet.Tools.Test; diff --git a/src/dotnet/commands/dotnet-add/AddCommandParser.cs b/src/dotnet/commands/dotnet-add/AddCommandParser.cs new file mode 100644 index 000000000..6e4a1881f --- /dev/null +++ b/src/dotnet/commands/dotnet-add/AddCommandParser.cs @@ -0,0 +1,74 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Threading; +using Microsoft.DotNet.Cli.CommandLine; +using Newtonsoft.Json.Linq; + +namespace Microsoft.DotNet.Cli +{ + internal static class AddCommandParser + { + public static Command Add() => + Create.Command("add", + ".NET Add Command", + Accept.ExactlyOneArgument.DefaultToCurrentDirectory(), + Create.Command("package", + ".NET Add Package reference Command", + Accept.ExactlyOneArgument + .WithSuggestionsFrom(QueryNuGet), CommonOptions.HelpOption(), + Create.Option("-v|--version", + "Version for the package to be added.", + Accept.ExactlyOneArgument + .With(name: "VERSION")), + Create.Option("-f|--framework", + "Add reference only when targetting a specific framework", + Accept.ExactlyOneArgument + .With(name: "FRAMEWORK")), + Create.Option("-n|--no-restore ", + "Add reference without performing restore preview and compatibility check."), + Create.Option("-s|--source", + "Use specific NuGet package sources to use during the restore."), + Create.Option("--package-directory", + "Restore the packages to this Directory .", + Accept.ExactlyOneArgument + .With(name: "PACKAGE_DIRECTORY"))), + Create.Command("reference", + "Command to add project to project reference", + Accept.OneOrMoreArguments, CommonOptions.HelpOption(), + Create.Option("-f|--framework", + "Add reference only when targetting a specific framework", + Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) + .With(name: "FRAMEWORK"))), CommonOptions.HelpOption()); + + public static IEnumerable QueryNuGet(string match) + { + var httpClient = new HttpClient(); + + string result; + + try + { + var cancellation = new CancellationTokenSource(TimeSpan.FromSeconds(10)); + var response = httpClient.GetAsync($"https://api-v2v3search-0.nuget.org/query?q={match}&skip=0&take=100&prerelease=true", cancellation.Token) + .Result; + + result = response.Content.ReadAsStringAsync().Result; + } + catch (Exception) + { + yield break; + } + + var json = JObject.Parse(result); + + foreach (var id in json["data"]) + { + yield return id["id"].Value(); + } + } + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs new file mode 100644 index 000000000..f93feb438 --- /dev/null +++ b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs @@ -0,0 +1,39 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + internal static class BuildCommandParser + { + public static Command Build() => + Create.Command("build", + ".NET Builder", + CommonOptions.HelpOption(), + Create.Option("-o|--output", + "Output directory in which to place built artifacts.", + Accept.ExactlyOneArgument + .With(name: "OUTPUT_DIR")), + Create.Option("-f|--framework", + "Target framework to build for. The target framework has to be specified in the project file.", + Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile)), + Create.Option("-r|--runtime", + "Target runtime to build for. The default is to build a portable application.", + Accept.AnyOneOf(Suggest.RunTimesFromProjectFile)), + Create.Option("-c|--configuration", + "Configuration to use for building the project. Default for most projects is \"Debug\".", + Accept.ExactlyOneArgument + .With(name: "CONFIGURATION") + .WithSuggestionsFrom("DEBUG", "RELEASE")), + Create.Option("--version-suffix", + "Defines the value for the $(VersionSuffix) property in the project", + Accept.ExactlyOneArgument + .With(name: "VERSION_SUFFIX")), + Create.Option("--no-incremental", + "Disables incremental build."), + Create.Option("--no-dependencies", + "Set this flag to ignore project-to-project references and only build the root project"), + CommonOptions.VerbosityOption()); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs b/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs new file mode 100644 index 000000000..dfdc5d1ac --- /dev/null +++ b/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs @@ -0,0 +1,27 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + internal static class CleanCommandParser + { + public static Command Clean() => + Create.Command("clean", + ".NET Clean Command", + CommonOptions.HelpOption(), + Create.Option("-o|--output", "Directory in which the build outputs have been placed.", + Accept.ExactlyOneArgument + .With(name: "OUTPUT_DIR")), + Create.Option("-f|--framework", "Clean a specific framework.", + Accept.ExactlyOneArgument + .With(name: "FRAMEWORK") + .WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile())), + Create.Option("-c|--configuration", + "Clean a specific configuration.", + Accept.ExactlyOneArgument + .With(name: "CONFIGURATION") + .WithSuggestionsFrom("DEBUG", "RELEASE"))); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs index 0518df868..f8b08125e 100644 --- a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs +++ b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs @@ -8,7 +8,7 @@ using System.Text; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; -namespace Microsoft.DotNet.Tools.Complete +namespace Microsoft.DotNet.Cli { public class CompleteCommand { @@ -16,24 +16,22 @@ namespace Microsoft.DotNet.Tools.Complete { DebugHelper.HandleDebugSwitch(ref args); - var log = new StringBuilder(); - log.AppendLine($"args: {string.Join(" ", args.Select(a => $"\"{a}\""))}"); - // get the parser for the current subcommand - var completeCommandParser = ParserFor.DotnetCommand["complete"]; + var completeCommandParser = Parser.DotnetCommand["complete"]; // parse the arguments var result = completeCommandParser.Parse(args); - log.AppendLine("diagram (1): " + result.Diagram()); - var complete = result["complete"]; - var suggestions = Suggestions(complete, log); - - log.AppendLine($"suggestions: {Environment.NewLine}{string.Join(Environment.NewLine, suggestions)}"); + var suggestions = Suggestions(complete); +#if DEBUG + var log = new StringBuilder(); + log.AppendLine($"args: {string.Join(" ", args.Select(a => $"\"{a}\""))}"); + log.AppendLine("diagram: " + result.Diagram()); File.WriteAllText("parse.log", log.ToString()); +#endif foreach (var suggestion in suggestions) { @@ -43,7 +41,7 @@ namespace Microsoft.DotNet.Tools.Complete return 0; } - private static string[] Suggestions(AppliedOption complete, StringBuilder log) + private static string[] Suggestions(AppliedOption complete) { var input = complete.Arguments.SingleOrDefault() ?? ""; @@ -58,9 +56,7 @@ namespace Microsoft.DotNet.Tools.Complete } } - var result = ParserFor.DotnetCommand.Parse(input); - - log.AppendLine("diagram (2): " + result.Diagram()); + var result = Parser.DotnetCommand.Parse(input); return result.Suggestions() .ToArray(); diff --git a/src/dotnet/commands/dotnet-list/ListCommandParser.cs b/src/dotnet/commands/dotnet-list/ListCommandParser.cs new file mode 100644 index 000000000..ddfde2b6f --- /dev/null +++ b/src/dotnet/commands/dotnet-list/ListCommandParser.cs @@ -0,0 +1,26 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + internal static class ListCommandParser + { + public static Command List() => + Create.Command("list", + ".NET List Command", + Accept.ZeroOrOneArgument + .With(name: "PROJECT", + description: + "The project file to operate on. If a file is not specified, the command will search the current directory for one.") + .DefaultToCurrentDirectory(), + CommonOptions.HelpOption(), + Create.Command("reference", "Command to list project to project references", + Accept.ExactlyOneArgument + .With(name: "PROJECT", + description: + "The project file to operate on. If a file is not specified, the command will search the current directory for one."), + CommonOptions.HelpOption())); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs b/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs new file mode 100644 index 000000000..2f30281af --- /dev/null +++ b/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs @@ -0,0 +1,29 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + internal static class MigrateCommandParser + { + public static Command Migrate() => + Create.Command("migrate", + ".NET Migrate Command", + CommonOptions.HelpOption(), + Create.Option("-t|--template-file", + "Base MSBuild template to use for migrated app. The default is the project included in dotnet new."), + Create.Option("-v|--sdk-package-version", + "The version of the SDK package that will be referenced in the migrated app. The default is the version of the SDK in dotnet new."), + Create.Option("-x|--xproj-file", + "The path to the xproj file to use. Required when there is more than one xproj in a project directory."), + Create.Option("-s|--skip-project-references", + "Skip migrating project references. By default, project references are migrated recursively."), + Create.Option("-r|--report-file", + "Output migration report to the given file in addition to the console."), + Create.Option("--format-report-file-json", + "Output migration report file as json rather than user messages."), + Create.Option("--skip-backup", + "Skip moving project.json, global.json, and *.xproj to a `backup` directory after successful migration.")); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-new/NewCommandParser.cs b/src/dotnet/commands/dotnet-new/NewCommandParser.cs new file mode 100644 index 000000000..36f49c8b9 --- /dev/null +++ b/src/dotnet/commands/dotnet-new/NewCommandParser.cs @@ -0,0 +1,39 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + internal static class NewCommandParser + { + public static Command New() => + Create.Command("new", + "Initialize .NET projects.", + Accept + .ExactlyOneArgument + .WithSuggestionsFrom( + "console", + "classlib", + "mstest", + "xunit", + "web", + "mvc", + "webapi", + "sln"), + Create.Option("-l|--list", + "List templates containing the specified name."), + Create.Option("-lang|--language", + "Specifies the language of the template to create", + Accept.WithSuggestionsFrom("C#", "F#") + .With(defaultValue: () => "C#")), + Create.Option("-n|--name", + "The name for the output being created. If no name is specified, the name of the current directory is used."), + Create.Option("-o|--output", + "Location to place the generated output."), + Create.Option("-h|--help", + "Displays help for this command."), + Create.Option("-all|--show-all", + "Shows all templates")); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs b/src/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs new file mode 100644 index 000000000..2358c685e --- /dev/null +++ b/src/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs @@ -0,0 +1,78 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + internal static class NuGetCommandParser + { + public static Command NuGet() => + Create.Command("nuget", + "NuGet Command Line 4.0.0.0", + CommonOptions.HelpOption(), + Create.Option("--version", + "Show version information"), + Create.Option("-v|--verbosity", + "The verbosity of logging to use. Allowed values: Debug, Verbose, Information, Minimal, Warning, Error.", + Accept.ExactlyOneArgument + .With(name: "verbosity")), + Create.Command("delete", + "Deletes a package from the server.", + Accept.ExactlyOneArgument + .With(name: "root", + description: "The Package Id and version."), + CommonOptions.HelpOption(), + Create.Option("--force-english-output", + "Forces the application to run using an invariant, English-based culture."), + Create.Option("-s|--source", + "Specifies the server URL", + Accept.ExactlyOneArgument + .With(name: "source")), + Create.Option("--non-interactive", + "Do not prompt for user input or confirmations."), + Create.Option("-k|--api-key", + "The API key for the server.", + Accept.ExactlyOneArgument + .With(name: "apiKey"))), + Create.Command("locals", + "Clears or lists local NuGet resources such as http requests cache, packages cache or machine-wide global packages folder.", + Accept.AnyOneOf(@"all", + @"http-cache", + @"global-packages", + @"temp") + .With(description: "Cache Location(s) Specifies the cache location(s) to list or clear."), + CommonOptions.HelpOption(), + Create.Option("--force-english-output", + "Forces the application to run using an invariant, English-based culture."), + Create.Option("-c|--clear", "Clear the selected local resources or cache location(s)."), + Create.Option("-l|--list", "List the selected local resources or cache location(s).")), + Create.Command("push", + "Pushes a package to the server and publishes it.", + CommonOptions.HelpOption(), + Create.Option("--force-english-output", + "Forces the application to run using an invariant, English-based culture."), + Create.Option("-s|--source", + "Specifies the server URL", + Accept.ExactlyOneArgument + .With(name: "source")), + Create.Option("-ss|--symbol-source", + "Specifies the symbol server URL. If not specified, nuget.smbsrc.net is used when pushing to nuget.org.", + Accept.ExactlyOneArgument + .With(name: "source")), + Create.Option("-t|--timeout", + "Specifies the timeout for pushing to a server in seconds. Defaults to 300 seconds (5 minutes).", + Accept.ExactlyOneArgument + .With(name: "timeout")), + Create.Option("-k|--api-key", "The API key for the server.", + Accept.ExactlyOneArgument + .With(name: "apiKey")), + Create.Option("-sk|--symbol-api-key", "The API key for the symbol server.", + Accept.ExactlyOneArgument + .With(name: "apiKey")), + Create.Option("-d|--disable-buffering", + "Disable buffering when pushing to an HTTP(S) server to decrease memory usage."), + Create.Option("-n|--no-symbols", + "If a symbols package exists, it will not be pushed to a symbols server."))); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-pack/PackCommandParser.cs b/src/dotnet/commands/dotnet-pack/PackCommandParser.cs new file mode 100644 index 000000000..1f36cd9a3 --- /dev/null +++ b/src/dotnet/commands/dotnet-pack/PackCommandParser.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + internal static class PackCommandParser + { + public static Command Pack() => + Create.Command("pack", + ".NET Core NuGet Package Packer", + CommonOptions.HelpOption(), + Create.Option("-o|--output", + "Directory in which to place built packages.", + Accept.ExactlyOneArgument + .With(name: "OUTPUT_DIR")), + Create.Option("--no-build", + "Skip building the project prior to packing. By default, the project will be built."), + Create.Option("--include-symbols", + "Include packages with symbols in addition to regular packages in output directory."), + Create.Option("--include-source", + "Include PDBs and source files. Source files go into the src folder in the resulting nuget package"), + Create.Option("-c|--configuration", + "Configuration to use for building the project. Default for most projects is \"Debug\".", + Accept.ExactlyOneArgument + .With(name: "CONFIGURATION") + .WithSuggestionsFrom("DEBUG", + "RELEASE")), + Create.Option("--version-suffix", + "Defines the value for the $(VersionSuffix) property in the project.", + Accept.ExactlyOneArgument + .With(name: "VERSION_SUFFIX")), + Create.Option("-s|--serviceable", + "Set the serviceable flag in the package. For more information, please see https://aka.ms/nupkgservicing."), + CommonOptions.VerbosityOption()); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs new file mode 100644 index 000000000..a9ede850d --- /dev/null +++ b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs @@ -0,0 +1,36 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + internal static class PublishCommandParser + { + public static Command Publish() => + Create.Command("publish", + ".NET Publisher", + Accept.ExactlyOneArgument, + CommonOptions.HelpOption(), + Create.Option("-f|--framework", + "Target framework to publish for. The target framework has to be specified in the project file.", + Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) + .With(name: "FRAMEWORK")), + Create.Option("-r|--runtime", + "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.", + Accept.AnyOneOf(Suggest.RunTimesFromProjectFile) + .With(name: "RUNTIME_IDENTIFIER")), + Create.Option("-o|--output", + "Output directory in which to place the published artifacts.", + Accept.ExactlyOneArgument + .With(name: "OUTPUT_DIR")), + Create.Option("-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", + Accept.ExactlyOneArgument + .With(name: "CONFIGURATION") + .WithSuggestionsFrom("DEBUG", "RELEASE")), + Create.Option("--version-suffix", "Defines the value for the $(VersionSuffix) property in the project.", + Accept.ExactlyOneArgument + .With(name: "VERSION_SUFFIX")), + CommonOptions.VerbosityOption()); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs b/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs new file mode 100644 index 000000000..0e99c019b --- /dev/null +++ b/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs @@ -0,0 +1,29 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + internal static class RemoveCommandParser + { + public static Command Remove() => + Create.Command("remove", + ".NET Remove Command", + Accept.ZeroOrOneArgument + .With(name: "PROJECT") + .DefaultToCurrentDirectory(), + CommonOptions.HelpOption(), + Create.Command("package", + "Command to remove package reference.", + CommonOptions.HelpOption()), + Create.Command("reference", + "Command to remove project to project reference", + Accept.AnyOneOf(Suggest.ProjectReferencesFromProjectFile), + CommonOptions.HelpOption(), + Create.Option("-f|--framework", + "Remove reference only when targetting a specific framework", + Accept.ExactlyOneArgument + .With(name: "FRAMEWORK")))); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs b/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs new file mode 100644 index 000000000..0cc2f82d3 --- /dev/null +++ b/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs @@ -0,0 +1,41 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + internal static class RestoreCommandParser + { + public static Command Restore() => + Create.Command("restore", + ".NET dependency restorer", + Accept.ZeroOrOneArgument, + CommonOptions.HelpOption(), + Create.Option("-s|--source", + "Specifies a NuGet package source to use during the restore.", + Accept.ExactlyOneArgument + .With(name: "SOURCE")), + Create.Option("-r|--runtime", + "Target runtime to restore packages for.", + Accept.AnyOneOf(Suggest.RunTimesFromProjectFile) + .With(name: "RUNTIME_IDENTIFIER")), + Create.Option("--packages", + "Directory to install packages in.", + Accept.ExactlyOneArgument + .With(name: "PACKAGES_DIRECTORY")), + Create.Option("--disable-parallel", + "Disables restoring multiple projects in parallel."), + Create.Option("--configfile", + "The NuGet configuration file to use.", + Accept.ExactlyOneArgument + .With(name: "FILE")), + Create.Option("--no-cache", + "Do not cache packages and http requests."), + Create.Option("--ignore-failed-sources", + "Treat package source failures as warnings."), + Create.Option("--no-dependencies", + "Set this flag to ignore project to project references and only restore the root project"), + CommonOptions.VerbosityOption()); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-run/RunCommandParser.cs b/src/dotnet/commands/dotnet-run/RunCommandParser.cs new file mode 100644 index 000000000..dba6ec68a --- /dev/null +++ b/src/dotnet/commands/dotnet-run/RunCommandParser.cs @@ -0,0 +1,25 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + internal static class RunCommandParser + { + public static Command Run() => + Create.Command("run", + ".NET Run Command", + CommonOptions.HelpOption(), + Create.Option("-c|--configuration", + @"Configuration to use for building the project. Default for most projects is ""Debug"".", + Accept.ExactlyOneArgument + .WithSuggestionsFrom("DEBUG", "RELEASE")), + Create.Option("-f|--framework", + "Build and run the app using the specified framework. The framework has to be specified in the project file.", + Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile)), + Create.Option("-p|--project", + "The path to the project file to run (defaults to the current directory if there is only one project).", + Accept.ZeroOrOneArgument)); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs new file mode 100644 index 000000000..9d9f073e4 --- /dev/null +++ b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs @@ -0,0 +1,27 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + internal static class SlnCommandParser + { + public static Command Sln() => + Create.Command("sln", + ".NET modify solution file command", + CommonOptions.HelpOption(), + Create.Command("add", + ".NET Add project(s) to a solution file Command", + Accept.ExactlyOneArgument + .With(name: "SLN_FILE"), + CommonOptions.HelpOption()), + Create.Command("list", + "List all projects in the solution.", + Accept.ExactlyOneArgument + .With(name: "SLN_FILE"), + CommonOptions.HelpOption()), + Create.Command("remove", + "Remove the specified project(s) from the solution. The project is not impacted.")); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/dotnet/commands/dotnet-test/TestCommandParser.cs new file mode 100644 index 000000000..2340ee4b3 --- /dev/null +++ b/src/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -0,0 +1,54 @@ +using System.Linq; +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + internal static class TestCommandParser + { + public static Command Test() => + Create.Command("test", + ".NET Test Driver", + Create.Option("-h|--help", + "Show help information"), + Create.Option("-s|--settings", + "Settings to use when running tests.", + Accept.ExactlyOneArgument + .With(name: "SETTINGS_FILE")), + Create.Option("-t|--list-tests", + "Lists discovered tests"), + Create.Option("--filter", + @"Run tests that match the given expression. + Examples: + Run tests with priority set to 1: --filter ""Priority = 1"" + Run a test with the specified full name: --filter ""FullyQualifiedName=Namespace.ClassName.MethodName"" + Run tests that contain the specified name: --filter ""FullyQualifiedName~Namespace.Class"" + More info on filtering support: https://aka.ms/vstest-filtering", + Accept.ExactlyOneArgument + .With(name: "EXPRESSION")), + Create.Option("-a|--test-adapter-path", + "Use custom adapters from the given path in the test run.\r\n Example: --test-adapter-path "), + Create.Option("-l|--logger", + "Specify a logger for test results.\r\n Example: --logger \"trx[;LogFileName=]\"", + Accept.ExactlyOneArgument + .With(name: "LoggerUri/FriendlyName")), + Create.Option("-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", + Accept.ExactlyOneArgument + .With(name: "CONFIGURATION") + .WithSuggestionsFrom("DEBUG", "RELEASE")), + Create.Option("-f|--framework", + "Looks for test binaries for a specific framework", + Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) + .With(name: "FRAMEWORK")), + Create.Option("-o|--output", + "Directory in which to find the binaries to be run", + Accept.ExactlyOneArgument + .With(name: "OUTPUT_DIR")), + Create.Option("-d|--diag", + "Enable verbose logs for test platform.\r\n Logs are written to the provided file.", + Accept.ExactlyOneArgument + .With(name: "PATH_TO_FILE")), + Create.Option("--no-build", + "Do not build project before testing."), + CommonOptions.VerbosityOption()); + } +} \ No newline at end of file diff --git a/src/dotnet/dotnet-complete/Suggest.cs b/src/dotnet/dotnet-complete/Suggest.cs new file mode 100644 index 000000000..e4b78e65c --- /dev/null +++ b/src/dotnet/dotnet-complete/Suggest.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Microsoft.Build.Evaluation; +using Microsoft.DotNet.Tools; + +namespace Microsoft.DotNet.Cli +{ + internal static class Suggest + { + public static IEnumerable TargetFrameworksFromProjectFile() + { + var msbuildProj = MsbuildProject.FromFileOrDirectory( + new ProjectCollection(), + Directory.GetCurrentDirectory()); + + foreach (var tfm in msbuildProj.GetTargetFrameworks()) + { + yield return tfm.GetShortFolderName(); + } + } + + public static IEnumerable RunTimesFromProjectFile() + { + var msbuildProj = MsbuildProject.FromFileOrDirectory( + new ProjectCollection(), + Directory.GetCurrentDirectory()); + + return msbuildProj.GetRuntimeIdentifiers(); + } + + public static IEnumerable ProjectReferencesFromProjectFile() + { + var msbuildProj = MsbuildProject.FromFileOrDirectory( + new ProjectCollection(), + Directory.GetCurrentDirectory()); + + return msbuildProj.GetProjectToProjectReferences() + .Select(r => r.Include); + } + } +} \ No newline at end of file diff --git a/src/dotnet/dotnet-complete/commands/ParserExtensions.cs b/src/dotnet/dotnet-complete/commands/ParserExtensions.cs deleted file mode 100644 index 825a1067c..000000000 --- a/src/dotnet/dotnet-complete/commands/ParserExtensions.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using Microsoft.DotNet.Cli.CommandLine; - -namespace Microsoft.DotNet.Tools -{ - public static class ParserExtensions - { - public static void ShowHelp(this ParseResult parseResult) => - Console.WriteLine(parseResult.Command().HelpView()); - } -} \ No newline at end of file diff --git a/src/dotnet/dotnet-complete/commands/ParserFor.cs b/src/dotnet/dotnet-complete/commands/ParserFor.cs deleted file mode 100644 index cf64aa10f..000000000 --- a/src/dotnet/dotnet-complete/commands/ParserFor.cs +++ /dev/null @@ -1,517 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net.Http; -using System.Threading; -using Microsoft.Build.Evaluation; -using Microsoft.DotNet.Cli.CommandLine; -using Microsoft.DotNet.Tools.Common; -using Newtonsoft.Json.Linq; -using static Microsoft.DotNet.Cli.CommandLine.Accept; -using static Microsoft.DotNet.Cli.CommandLine.Create; -using Command = Microsoft.DotNet.Cli.CommandLine.Command; - -namespace Microsoft.DotNet.Tools -{ - public static class ParserFor - { - private static readonly Command _dotnetCommand = Command("dotnet", - ".NET Command Line Tools", - NoArguments, - New(), - Restore(), - Build(), - Publish(), - Run(), - Test(), - Pack(), - Migrate(), - Clean(), - Sln(), - Add(), - Remove(), - List(), - NuGet(), - Command("msbuild", ""), - Command("vstest", ""), - Complete(), - HelpOption(), - Option("--info", ""), - VerbosityOption(), - Option("-d", "")); - - public static Command DotnetCommand { get; } = _dotnetCommand; - - private static Command Add() => - Command("add", - ".NET Add Command", - ExactlyOneArgument.DefaultToCurrentDirectory(), - Command("package", - ".NET Add Package reference Command", - ExactlyOneArgument - .WithSuggestionsFrom(QueryNuGet), - HelpOption(), - Option("-v|--version", - "Version for the package to be added.", - ExactlyOneArgument - .With(name: "VERSION")), - Option("-f|--framework", - "Add reference only when targetting a specific framework", - ExactlyOneArgument - .With(name: "FRAMEWORK")), - Option("-n|--no-restore ", - "Add reference without performing restore preview and compatibility check."), - Option("-s|--source", - "Use specific NuGet package sources to use during the restore."), - Option("--package-directory", - "Restore the packages to this Directory .", - ExactlyOneArgument - .With(name: "PACKAGE_DIRECTORY"))), - Command("reference", - "Command to add project to project reference", - OneOrMoreArguments, - HelpOption(), - Option("-f|--framework", - "Add reference only when targetting a specific framework", - AnyOneOf(TargetFrameworksFromProjectFile) - .With(name: "FRAMEWORK"))), - HelpOption()); - - private static Command Complete() => - Command("complete", "", - ExactlyOneArgument - .With(name: "path"), - Option("--position", "", - ExactlyOneArgument - .With(name: "command"), - o => int.Parse(o.Arguments.Single()))); - - private static Command Build() => - Command("build", - ".NET Builder", - HelpOption(), - Option("-o|--output", - "Output directory in which to place built artifacts.", - ExactlyOneArgument - .With(name: "OUTPUT_DIR")), - Option("-f|--framework", - "Target framework to build for. The target framework has to be specified in the project file.", - AnyOneOf(TargetFrameworksFromProjectFile)), - Option("-r|--runtime", - "Target runtime to build for. The default is to build a portable application.", - AnyOneOf(RunTimesFromProjectFile)), - Option("-c|--configuration", - "Configuration to use for building the project. Default for most projects is \"Debug\".", - ExactlyOneArgument - .With(name: "CONFIGURATION") - .WithSuggestionsFrom(_ => new[] { "DEBUG", "RELEASE" })), - Option("--version-suffix", "Defines the value for the $(VersionSuffix) property in the project", - ExactlyOneArgument - .With(name: "VERSION_SUFFIX")), - Option("--no-incremental", "Disables incremental build."), - Option("--no-dependencies", "Set this flag to ignore project-to-project references and only build the root project"), - VerbosityOption()); - - private static Command Clean() => - Command("clean", - ".NET Clean Command", - HelpOption(), - Option("-o|--output", "Directory in which the build outputs have been placed.", - ExactlyOneArgument - .With(name: "OUTPUT_DIR")), - Option("-f|--framework", "Clean a specific framework.", - ExactlyOneArgument - .With(name: "FRAMEWORK") - .WithSuggestionsFrom(_ => TargetFrameworksFromProjectFile())), - Option("-c|--configuration", - "Clean a specific configuration.", - ExactlyOneArgument - .With(name: "CONFIGURATION") - .WithSuggestionsFrom(_ => new[] { "DEBUG", "RELEASE" }))); - - private static Command List() => - Command("list", - ".NET List Command", - ZeroOrOneArgument - .With(name: "PROJECT", - description: - "The project file to operate on. If a file is not specified, the command will search the current directory for one.") - .DefaultToCurrentDirectory(), - HelpOption(), - Command("reference", "Command to list project to project references", - ExactlyOneArgument - .With(name: "PROJECT") - .With(description: "The project file to operate on. If a file is not specified, the command will search the current directory for one."), - HelpOption())); - - private static Command Migrate() => - Command("migrate", - ".NET Migrate Command", - HelpOption(), - Option("-t|--template-file", - "Base MSBuild template to use for migrated app. The default is the project included in dotnet new."), - Option("-v|--sdk-package-version", - "The version of the SDK package that will be referenced in the migrated app. The default is the version of the SDK in dotnet new."), - Option("-x|--xproj-file", - "The path to the xproj file to use. Required when there is more than one xproj in a project directory."), - Option("-s|--skip-project-references", - "Skip migrating project references. By default, project references are migrated recursively."), - Option("-r|--report-file", - "Output migration report to the given file in addition to the console."), - Option("--format-report-file-json", - "Output migration report file as json rather than user messages."), - Option("--skip-backup", - "Skip moving project.json, global.json, and *.xproj to a `backup` directory after successful migration.")); - - private static Command New() => - Command("new", - "Initialize .NET projects.", - WithSuggestionsFrom("console", - "classlib", - "mstest", - "xunit", - "web", - "mvc", - "webapi", - "sln"), - Option("-l|--list", - "List templates containing the specified name."), - Option("-lang|--language", - "Specifies the language of the template to create", - WithSuggestionsFrom("C#", "F#") - .With(defaultValue: () => "C#")), - Option("-n|--name", - "The name for the output being created. If no name is specified, the name of the current directory is used."), - Option("-o|--output", - "Location to place the generated output."), - Option("-h|--help", - "Displays help for this command."), - Option("-all|--show-all", - "Shows all templates")); - - private static Command NuGet() => - Command("nuget", - "NuGet Command Line 4.0.0.0", - HelpOption(), - Option("--version", - "Show version information"), - Option("-v|--verbosity", - "The verbosity of logging to use. Allowed values: Debug, Verbose, Information, Minimal, Warning, Error.", - ExactlyOneArgument - .With(name: "verbosity")), - Command("delete", - "Deletes a package from the server.", - ExactlyOneArgument - .With(name: "root", - description: "The Package Id and version."), - HelpOption(), - Option("--force-english-output", - "Forces the application to run using an invariant, English-based culture."), - Option("-s|--source", - "Specifies the server URL", - ExactlyOneArgument - .With(name: "source")), - Option("--non-interactive", - "Do not prompt for user input or confirmations."), - Option("-k|--api-key", - "The API key for the server.", - ExactlyOneArgument - .With(name: "apiKey"))), - Command("locals", - "Clears or lists local NuGet resources such as http requests cache, packages cache or machine-wide global packages folder.", - AnyOneOf(@"all", @"http-cache", @"global-packages", @"temp") - .With(description: "Cache Location(s) Specifies the cache location(s) to list or clear."), - HelpOption(), - Option("--force-english-output", - "Forces the application to run using an invariant, English-based culture."), - Option("-c|--clear", "Clear the selected local resources or cache location(s)."), - Option("-l|--list", "List the selected local resources or cache location(s).")), - Command("push", - "Pushes a package to the server and publishes it.", - HelpOption(), - Option("--force-english-output", - "Forces the application to run using an invariant, English-based culture."), - Option("-s|--source", - "Specifies the server URL", - ExactlyOneArgument - .With(name: "source")), - Option("-ss|--symbol-source", - "Specifies the symbol server URL. If not specified, nuget.smbsrc.net is used when pushing to nuget.org.", - ExactlyOneArgument - .With(name: "source")), - Option("-t|--timeout", - "Specifies the timeout for pushing to a server in seconds. Defaults to 300 seconds (5 minutes).", - ExactlyOneArgument - .With(name: "timeout")), - Option("-k|--api-key", "The API key for the server.", - ExactlyOneArgument - .With(name: "apiKey")), - Option("-sk|--symbol-api-key", "The API key for the symbol server.", - ExactlyOneArgument - .With(name: "apiKey")), - Option("-d|--disable-buffering", - "Disable buffering when pushing to an HTTP(S) server to decrease memory usage."), - Option("-n|--no-symbols", - "If a symbols package exists, it will not be pushed to a symbols server."))); - - private static Command Pack() => - Command("pack", - ".NET Core NuGet Package Packer", - HelpOption(), - Option("-o|--output", - "Directory in which to place built packages.", - ExactlyOneArgument - .With(name: "OUTPUT_DIR")), - Option("--no-build", - "Skip building the project prior to packing. By default, the project will be built."), - Option("--include-symbols", - "Include packages with symbols in addition to regular packages in output directory."), - Option("--include-source", - "Include PDBs and source files. Source files go into the src folder in the resulting nuget package"), - Option("-c|--configuration", - "Configuration to use for building the project. Default for most projects is \"Debug\".", - ExactlyOneArgument - .With(name: "CONFIGURATION") - .WithSuggestionsFrom(_ => new[] { "DEBUG", "RELEASE" })), - Option("--version-suffix", - "Defines the value for the $(VersionSuffix) property in the project.", - ExactlyOneArgument - .With(name: "VERSION_SUFFIX")), - Option("-s|--serviceable", - "Set the serviceable flag in the package. For more information, please see https://aka.ms/nupkgservicing."), - VerbosityOption()); - - private static Command Publish() => - Command("publish", - ".NET Publisher", - ExactlyOneArgument, - HelpOption(), - Option("-f|--framework", - "Target framework to publish for. The target framework has to be specified in the project file.", - AnyOneOf(TargetFrameworksFromProjectFile) - .With(name: "FRAMEWORK")), - Option("-r|--runtime", - "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.", - AnyOneOf(RunTimesFromProjectFile) - .With(name: "RUNTIME_IDENTIFIER")), - Option("-o|--output", - "Output directory in which to place the published artifacts.", - ExactlyOneArgument - .With(name: "OUTPUT_DIR")), - Option("-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", - ExactlyOneArgument - .With(name: "CONFIGURATION") - .WithSuggestionsFrom(_ => new[] { "DEBUG", "RELEASE" })), - Option("--version-suffix", "Defines the value for the $(VersionSuffix) property in the project.", - ExactlyOneArgument - .With(name: "VERSION_SUFFIX")), - VerbosityOption()); - - private static Command Remove() => - Command("remove", - ".NET Remove Command", - ZeroOrOneArgument - .With(name: "PROJECT") - .DefaultToCurrentDirectory(), - HelpOption(), - Command("package", - "Command to remove package reference.", - HelpOption()), - Command("reference", - "Command to remove project to project reference", - AnyOneOf(ProjectReferencesFromProjectFile), - HelpOption(), - Option("-f|--framework", - "Remove reference only when targetting a specific framework", - ExactlyOneArgument - .With(name: "FRAMEWORK")))); - - private static Command Restore() => - Command("restore", - ".NET dependency restorer", - HelpOption(), - Option("-s|--source", - "Specifies a NuGet package source to use during the restore.", - ExactlyOneArgument - .With(name: "SOURCE")), - Option("-r|--runtime", - "Target runtime to restore packages for.", - AnyOneOf(RunTimesFromProjectFile) - .With(name: "RUNTIME_IDENTIFIER")), - Option("--packages", - "Directory to install packages in.", - ExactlyOneArgument - .With(name: "PACKAGES_DIRECTORY")), - Option("--disable-parallel", - "Disables restoring multiple projects in parallel."), - Option("--configfile", - "The NuGet configuration file to use.", - ExactlyOneArgument - .With(name: "FILE")), - Option("--no-cache", - "Do not cache packages and http requests."), - Option("--ignore-failed-sources", - "Treat package source failures as warnings."), - Option("--no-dependencies", - "Set this flag to ignore project to project references and only restore the root project"), - VerbosityOption()); - - private static Command Run() => - Command("run", - ".NET Run Command", - HelpOption(), - Option("-c|--configuration", - @"Configuration to use for building the project. Default for most projects is ""Debug"".", - ExactlyOneArgument - .WithSuggestionsFrom(_ => new[] { "DEBUG", "RELEASE" })), - Option("-f|--framework", - "Build and run the app using the specified framework. The framework has to be specified in the project file.", - AnyOneOf(TargetFrameworksFromProjectFile)), - Option("-p|--project", - "The path to the project file to run (defaults to the current directory if there is only one project).", - ZeroOrOneArgument)); - - private static Command Sln() => - Command("sln", - ".NET modify solution file command", - - HelpOption(), - Command("add", - ".NET Add project(s) to a solution file Command", - ExactlyOneArgument - .With(name: "SLN_FILE"), - HelpOption()), - Command("list", - "List all projects in the solution.", - ExactlyOneArgument - .With(name: "SLN_FILE"), - HelpOption()), - Command("remove", - "Remove the specified project(s) from the solution. The project is not impacted.")); - - private static Command Test() => - Command("test", - ".NET Test Driver", - Option("-h|--help", - "Show help information"), - Option("-s|--settings", - "Settings to use when running tests.", - ExactlyOneArgument - .With(name: "SETTINGS_FILE")), - Option("-t|--list-tests", - "Lists discovered tests"), - Option("--filter", - @"Run tests that match the given expression. - Examples: - Run tests with priority set to 1: --filter ""Priority = 1"" - Run a test with the specified full name: --filter ""FullyQualifiedName=Namespace.ClassName.MethodName"" - Run tests that contain the specified name: --filter ""FullyQualifiedName~Namespace.Class"" - More info on filtering support: https://aka.ms/vstest-filtering", - ExactlyOneArgument - .With(name: "EXPRESSION")), - Option("-a|--test-adapter-path", - "Use custom adapters from the given path in the test run.\r\n Example: --test-adapter-path "), - Option("-l|--logger", - "Specify a logger for test results.\r\n Example: --logger \"trx[;LogFileName=]\"", - ExactlyOneArgument - .With(name: "LoggerUri/FriendlyName")), - Option("-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", - ExactlyOneArgument - .With(name: "CONFIGURATION") - .WithSuggestionsFrom(_ => new[] { "DEBUG", "RELEASE" })), - Option("-f|--framework", - "Looks for test binaries for a specific framework", - AnyOneOf(() => TargetFrameworksFromProjectFile().ToArray()) - .With(name: "FRAMEWORK")), - Option("-o|--output", - "Directory in which to find the binaries to be run", - ExactlyOneArgument - .With(name: "OUTPUT_DIR")), - Option("-d|--diag", - "Enable verbose logs for test platform.\r\n Logs are written to the provided file.", - ExactlyOneArgument - .With(name: "PATH_TO_FILE")), - Option("--no-build", - "Do not build project before testing."), - VerbosityOption()); - - private static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => - rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory())); - - private static Option HelpOption() => - Option("-h|--help", - "Show help information", - NoArguments, - materialize: o => o.Option.Command().HelpView()); - - private static Option VerbosityOption() => - Option("-v|--verbosity", - "Set the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]", - AnyOneOf("q[uiet]", - "m[inimal]", - "n[ormal]", - "d[etailed]")); - - private static IEnumerable QueryNuGet(string match) - { - var httpClient = new HttpClient(); - - string result = null; - - try - { - var cancellation = new CancellationTokenSource(TimeSpan.FromSeconds(10)); - var response = httpClient.GetAsync($"https://api-v2v3search-0.nuget.org/query?q={match}&skip=0&take=100&prerelease=true", cancellation.Token) - .Result; - - result = response.Content.ReadAsStringAsync().Result; - } - catch (Exception) - { - yield break; - } - - var json = JObject.Parse(result); - - foreach (var id in json["data"]) - { - yield return id["id"].Value(); - } - } - - private static IEnumerable TargetFrameworksFromProjectFile() - { - var msbuildProj = MsbuildProject.FromFileOrDirectory( - new ProjectCollection(), - Directory.GetCurrentDirectory()); - - foreach (var tfm in msbuildProj.GetTargetFrameworks()) - { - yield return tfm.GetShortFolderName(); - } - } - - private static IEnumerable RunTimesFromProjectFile() - { - var msbuildProj = MsbuildProject.FromFileOrDirectory( - new ProjectCollection(), - Directory.GetCurrentDirectory()); - - return msbuildProj.GetRuntimeIdentifiers(); - } - - private static IEnumerable ProjectReferencesFromProjectFile() - { - var msbuildProj = MsbuildProject.FromFileOrDirectory( - new ProjectCollection(), - Directory.GetCurrentDirectory()); - - return msbuildProj.GetProjectToProjectReferences() - .Select(r => r.Include); - } - } -} \ No newline at end of file diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index 4a6355cd3..3f0d29978 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -10,6 +10,7 @@ true true $(PackageTargetFallback);dotnet5.4 + Microsoft.DotNet.Cli @@ -39,10 +40,14 @@ - + + + + + diff --git a/test/dotnet.Tests/ParseTests.cs b/test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs similarity index 65% rename from test/dotnet.Tests/ParseTests.cs rename to test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs index b4b5d5c2b..51bb79f75 100644 --- a/test/dotnet.Tests/ParseTests.cs +++ b/test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs @@ -1,14 +1,17 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using System; using System.IO; -using FluentAssertions; using System.Linq; +using FluentAssertions; using Microsoft.DotNet.Cli.CommandLine; -using Microsoft.DotNet.Tools; using Microsoft.DotNet.Tools.Common; using Xunit; using Xunit.Abstractions; +using Parser = Microsoft.DotNet.Cli.Parser; -namespace Microsoft.DotNet.Tests +namespace Microsoft.DotNet.Tests.ParserTests { public class AddReferenceParserTests { @@ -20,9 +23,9 @@ namespace Microsoft.DotNet.Tests } [Fact] - public void dotnet_add_reference_has_default_argument_set_to_current_directory() + public void AddReferenceHasDefaultArgumentSetToCurrentDirectory() { - var command = ParserFor.DotnetCommand; + var command = Parser.DotnetCommand; var result = command.Parse("dotnet add reference my.csproj"); @@ -36,11 +39,11 @@ namespace Microsoft.DotNet.Tests } [Fact] - public void dotnet_add_reference_without_argument_results_in_an_error() + public void AddReferenceWithoutArgumentResultsInAnError() { - var command = ParserFor.DotnetCommand["add"]; + var command = Parser.DotnetCommand; - var result = command.Parse("add reference"); + var result = command.Parse("dotnet add reference"); output.WriteLine(result.Diagram()); From 6b66db74364a2e2d72791a5193e45f72b4435943 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Mon, 6 Mar 2017 12:08:26 -0800 Subject: [PATCH 005/149] a few small code cleanups --- scripts/register-completions.bash | 5 ++--- scripts/register-completions.ps1 | 3 ++- scripts/register-completions.zsh | 4 ++-- src/dotnet/CommonOptions.cs | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/register-completions.bash b/scripts/register-completions.bash index 635e59112..b4753def3 100644 --- a/scripts/register-completions.bash +++ b/scripts/register-completions.bash @@ -1,14 +1,13 @@ #!/bin/bash -# Parameter completion for the dotnet CLI +# bash parameter completion for the dotnet CLI _dotnet_bash_complete() { local word=${COMP_WORDS[COMP_CWORD]} local dotnetPath=${COMP_WORDS[1]} - local completions=("$(./bin/Debug/netcoreapp1.0/osx.10.11-x64/publish/dotnet complete --position ${COMP_POINT} "${COMP_LINE}")") + local completions=("$(dotnet complete --position ${COMP_POINT} "${COMP_LINE}")") - # https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html COMPREPLY=( $(compgen -W "$completions" -- "$word") ) } diff --git a/scripts/register-completions.ps1 b/scripts/register-completions.ps1 index cc19f9702..58023e52b 100644 --- a/scripts/register-completions.ps1 +++ b/scripts/register-completions.ps1 @@ -1,6 +1,7 @@ +# PowerShell parameter completion shim for the dotnet CLI Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock { param($commandName, $wordToComplete, $cursorPosition) - C:\dev\github\cli\artifacts\win10-x64\stage2\dotnet.exe complete --position $cursorPosition "$wordToComplete" | ForEach-Object { + dotnet.exe complete --position $cursorPosition "$wordToComplete" | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } } \ No newline at end of file diff --git a/scripts/register-completions.zsh b/scripts/register-completions.zsh index 727897232..9f290bc68 100644 --- a/scripts/register-completions.zsh +++ b/scripts/register-completions.zsh @@ -1,10 +1,10 @@ -# Parameter completion for the dotnet CLI +# zsh parameter completion for the dotnet CLI _dotnet_zsh_complete() { local dotnetPath=$words[1] - local completions=("$(./bin/Debug/netcoreapp1.0/osx.10.11-x64/publish/dotnet complete "$words")") + local completions=("$(dotnet complete "$words")") reply=( "${(ps:\n:)completions}" ) } diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index 7cabd551c..62af13c21 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -15,10 +15,10 @@ namespace Microsoft.DotNet.Cli public static Option VerbosityOption() => Create.Option("-v|--verbosity", "Set the verbosity level of the command. Allowed values are q[uiet],m[inimal],n[ormal],d[etailed], anddiag[nostic]", - Accept.AnyOneOf("quiet", - "minimal", - "normal", - "detailed")); + Accept.AnyOneOf("q", "quiet", + "m", "minimal", + "n", "normal", + "d", "detailed")); public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory())); From 0094fd4e0868025702e843094ae8b735d0f69e0c Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 6 Mar 2017 16:34:05 -0800 Subject: [PATCH 006/149] revert subcommand change, align CliCommandLine versions --- src/dotnet/DotNetTopLevelCommandBase.cs | 72 ++++++++++++++++--------- src/dotnet/dotnet.csproj | 2 +- test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 3 files changed, 48 insertions(+), 28 deletions(-) diff --git a/src/dotnet/DotNetTopLevelCommandBase.cs b/src/dotnet/DotNetTopLevelCommandBase.cs index 89aa1a6e6..640d8dccc 100644 --- a/src/dotnet/DotNetTopLevelCommandBase.cs +++ b/src/dotnet/DotNetTopLevelCommandBase.cs @@ -3,9 +3,12 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.Tools; +using Microsoft.DotNet.Tools.Common; namespace Microsoft.DotNet.Cli { @@ -21,44 +24,61 @@ namespace Microsoft.DotNet.Cli { DebugHelper.HandleDebugSwitch(ref args); - var result = Parser.DotnetCommand[CommandName] - .Parse(args); - - Reporter.Verbose.WriteLine(result.Diagram()); - - var command = result[CommandName]; - - if (command.HasOption("help")) + CommandLineApplication command = new CommandLineApplication(throwOnUnexpectedArg: true) { - result.ShowHelp(); - return 0; - } + Name = $"dotnet {CommandName}", + FullName = FullCommandNameLocalized, + }; - if (result.Errors.Any()) + command.HelpOption("-h|--help"); + + command.Argument(ArgumentName, ArgumentDescriptionLocalized); + + foreach (var subCommandCreator in SubCommands) { - Reporter.Error.WriteLine(result.Errors.First().Message.Red()); - return 1; + var subCommand = subCommandCreator(); + command.AddCommand(subCommand); + + subCommand.OnExecute(() => { + try + { + if (!command.Arguments.Any()) + { + throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, ArgumentDescriptionLocalized); + } + + var projectOrDirectory = command.Arguments.First().Value; + if (string.IsNullOrEmpty(projectOrDirectory)) + { + projectOrDirectory = PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory()); + } + + return subCommand.Run(projectOrDirectory); + } + catch (GracefulException e) + { + Reporter.Error.WriteLine(e.Message.Red()); + subCommand.ShowHelp(); + return 1; + } + }); } - var subCommand = SubCommands - .Select(c => c()) - .FirstOrDefault(c => c.Name == command.AppliedOptions.First().Name); - - var fileOrDirectory = command.AppliedOptions - .First() - .Arguments - .FirstOrDefault(); - try { - return subCommand.Run(fileOrDirectory); + return command.Execute(args); } catch (GracefulException e) { Reporter.Error.WriteLine(e.Message.Red()); - subCommand.ShowHelp(); + command.ShowHelp(); + return 1; + } + catch (CommandParsingException e) + { + Reporter.Error.WriteLine(e.Message.Red()); return 1; } } } -} \ No newline at end of file +} diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index 3f0d29978..fb24f652e 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index 6d62e4124..825c0a095 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From 69bc90dc6f39f859735f9c5e4f1edca07c87a08d Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 6 Mar 2017 20:53:26 -0800 Subject: [PATCH 007/149] dotnet restore using new parser --- src/dotnet/ArgumentForwardingExtensions.cs | 41 +++++ src/dotnet/CommonOptions.cs | 23 +-- src/dotnet/commands/dotnet-restore/Program.cs | 140 ++---------------- .../dotnet-restore/RestoreCommandParser.cs | 77 ++++++---- .../ArgumentForwardingExtensionsTests.cs | 47 ++++++ 5 files changed, 164 insertions(+), 164 deletions(-) create mode 100644 src/dotnet/ArgumentForwardingExtensions.cs create mode 100644 test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs diff --git a/src/dotnet/ArgumentForwardingExtensions.cs b/src/dotnet/ArgumentForwardingExtensions.cs new file mode 100644 index 000000000..6a559a798 --- /dev/null +++ b/src/dotnet/ArgumentForwardingExtensions.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + public static class ArgumentForwardingExtensions + { + public static ArgumentsRule ForwardAs( + this ArgumentsRule rule, + string template) => + rule.MaterializeAs(o => + new ForwardedArgument(string.Format(template, o.Arguments.Single()))); + + public static ArgumentsRule ForwardAs( + this ArgumentsRule rule, + Func format) => + rule.MaterializeAs(o => + new ForwardedArgument(format(o))); + + public static IEnumerable ArgsToBeForwarded( + this AppliedOption command) => + command.AppliedOptions + .Select(o => o.Value()) + .OfType() + .Select(o => o.ToString()); + + private class ForwardedArgument + { + private readonly string _value; + + public ForwardedArgument(string value) + { + _value = value; + } + + public override string ToString() => _value; + } + } +} \ No newline at end of file diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index 62af13c21..0337bb8aa 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -7,18 +7,21 @@ namespace Microsoft.DotNet.Cli internal static class CommonOptions { public static Option HelpOption() => - Create.Option("-h|--help", - "Show help information", - Accept.NoArguments, - materialize: o => o.Option.Command().HelpView()); + Create.Option( + "-h|--help", + "Show help information", + Accept.NoArguments, + materialize: o => o.Option.Command().HelpView()); public static Option VerbosityOption() => - Create.Option("-v|--verbosity", - "Set the verbosity level of the command. Allowed values are q[uiet],m[inimal],n[ormal],d[etailed], anddiag[nostic]", - Accept.AnyOneOf("q", "quiet", - "m", "minimal", - "n", "normal", - "d", "detailed")); + Create.Option( + "-v|--verbosity", + "Set the verbosity level of the command. Allowed values are q[uiet],m[inimal],n[ormal],d[etailed], anddiag[nostic]", + Accept.AnyOneOf("q", "quiet", + "m", "minimal", + "n", "normal", + "d", "detailed") + .ForwardAs("/verbosity:{0}")); public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory())); diff --git a/src/dotnet/commands/dotnet-restore/Program.cs b/src/dotnet/commands/dotnet-restore/Program.cs index 2ba2e350e..d24c0cd44 100644 --- a/src/dotnet/commands/dotnet-restore/Program.cs +++ b/src/dotnet/commands/dotnet-restore/Program.cs @@ -6,7 +6,7 @@ using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; using Microsoft.DotNet.Cli; -using System.Diagnostics; +using Parser = Microsoft.DotNet.Cli.Parser; namespace Microsoft.DotNet.Tools.Restore { @@ -21,133 +21,21 @@ namespace Microsoft.DotNet.Tools.Restore { DebugHelper.HandleDebugSwitch(ref args); - CommandLineApplication cmd = new CommandLineApplication(throwOnUnexpectedArg: false) + var parser = Parser.DotnetCommand["restore"]; + + var result = parser.Parse(args); + + var restore = result["restore"]; + + var msbuildArgs = new List { - Name = "restore", - FullName = LocalizableStrings.AppFullName, - Description = LocalizableStrings.AppDescription, - HandleRemainingArguments = true, - ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText + "/NoLogo", + "/t:Restore", + "/ConsoleLoggerParameters:Verbosity=Minimal" }; - cmd.HelpOption("-h|--help"); - - var argRoot = cmd.Argument( - $"[{LocalizableStrings.CmdArgument}]", - LocalizableStrings.CmdArgumentDescription, - multipleValues: true); - - var sourceOption = cmd.Option( - $"-s|--source <{LocalizableStrings.CmdSourceOption}>", - LocalizableStrings.CmdSourceOptionDescription, - CommandOptionType.MultipleValue); - - var runtimeOption = cmd.Option( - $"-r|--runtime <{LocalizableStrings.CmdRuntimeOption}>", - LocalizableStrings.CmdRuntimeOptionDescription, - CommandOptionType.MultipleValue); - - var packagesOption = cmd.Option( - $"--packages <{LocalizableStrings.CmdPackagesOption}>", - LocalizableStrings.CmdPackagesOptionDescription, - CommandOptionType.SingleValue); - - var disableParallelOption = cmd.Option( - "--disable-parallel", - LocalizableStrings.CmdDisableParallelOptionDescription, - CommandOptionType.NoValue); - - var configFileOption = cmd.Option( - $"--configfile <{LocalizableStrings.CmdConfigFileOption}>", - LocalizableStrings.CmdConfigFileOptionDescription, - CommandOptionType.SingleValue); - - var noCacheOption = cmd.Option( - "--no-cache", - LocalizableStrings.CmdNoCacheOptionDescription, - CommandOptionType.NoValue); - - var ignoreFailedSourcesOption = cmd.Option( - "--ignore-failed-sources", - LocalizableStrings.CmdIgnoreFailedSourcesOptionDescription, - CommandOptionType.NoValue); - - var noDependenciesOption = cmd.Option( - "--no-dependencies", - LocalizableStrings.CmdNoDependenciesOptionDescription, - CommandOptionType.NoValue); - - CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(cmd); - - List msbuildArgs = null; - cmd.OnExecute(() => - { - msbuildArgs = new List() - { - "/NoLogo", - "/t:Restore", - "/ConsoleLoggerParameters:Verbosity=Minimal" - }; - - if (sourceOption.HasValue()) - { - msbuildArgs.Add($"/p:RestoreSources={string.Join("%3B", sourceOption.Values)}"); - } - - if (runtimeOption.HasValue()) - { - msbuildArgs.Add($"/p:RuntimeIdentifiers={string.Join("%3B", runtimeOption.Values)}"); - } - - if (packagesOption.HasValue()) - { - msbuildArgs.Add($"/p:RestorePackagesPath={packagesOption.Value()}"); - } - - if (disableParallelOption.HasValue()) - { - msbuildArgs.Add($"/p:RestoreDisableParallel=true"); - } - - if (configFileOption.HasValue()) - { - msbuildArgs.Add($"/p:RestoreConfigFile={configFileOption.Value()}"); - } - - if (noCacheOption.HasValue()) - { - msbuildArgs.Add($"/p:RestoreNoCache=true"); - } - - if (ignoreFailedSourcesOption.HasValue()) - { - msbuildArgs.Add($"/p:RestoreIgnoreFailedSources=true"); - } - - if (noDependenciesOption.HasValue()) - { - msbuildArgs.Add($"/p:RestoreRecursive=false"); - } - - if (verbosityOption.HasValue()) - { - msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}"); - } - - // Add in arguments - msbuildArgs.AddRange(argRoot.Values); - - // Add remaining arguments that the parser did not understand - msbuildArgs.AddRange(cmd.RemainingArguments); - - return 0; - }); - - int exitCode = cmd.Execute(args); - if (msbuildArgs == null) - { - throw new CommandCreationException(exitCode); - } + msbuildArgs.AddRange(restore.ArgsToBeForwarded()); + msbuildArgs.AddRange(restore.Arguments); return new RestoreCommand(msbuildArgs, msbuildPath); } @@ -169,4 +57,4 @@ namespace Microsoft.DotNet.Tools.Restore return cmd.Execute(); } } -} +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs b/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs index 0cc2f82d3..44340ef6b 100644 --- a/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs +++ b/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs @@ -9,33 +9,54 @@ namespace Microsoft.DotNet.Cli { public static Command Restore() => Create.Command("restore", - ".NET dependency restorer", - Accept.ZeroOrOneArgument, - CommonOptions.HelpOption(), - Create.Option("-s|--source", - "Specifies a NuGet package source to use during the restore.", - Accept.ExactlyOneArgument - .With(name: "SOURCE")), - Create.Option("-r|--runtime", - "Target runtime to restore packages for.", - Accept.AnyOneOf(Suggest.RunTimesFromProjectFile) - .With(name: "RUNTIME_IDENTIFIER")), - Create.Option("--packages", - "Directory to install packages in.", - Accept.ExactlyOneArgument - .With(name: "PACKAGES_DIRECTORY")), - Create.Option("--disable-parallel", - "Disables restoring multiple projects in parallel."), - Create.Option("--configfile", - "The NuGet configuration file to use.", - Accept.ExactlyOneArgument - .With(name: "FILE")), - Create.Option("--no-cache", - "Do not cache packages and http requests."), - Create.Option("--ignore-failed-sources", - "Treat package source failures as warnings."), - Create.Option("--no-dependencies", - "Set this flag to ignore project to project references and only restore the root project"), - CommonOptions.VerbosityOption()); + ".NET dependency restorer", + Accept.OneOrMoreArguments, + CommonOptions.HelpOption(), + Create.Option( + "-s|--source", + "Specifies a NuGet package source to use during the restore.", + Accept.OneOrMoreArguments + .With(name: "SOURCE") + .ForwardAs(o => $"/p:RestoreSources={string.Join("%3B", o.Arguments)}")), + Create.Option( + "-r|--runtime", + "Target runtime to restore packages for.", + Accept.OneOrMoreArguments + .WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile()) + .With(name: "RUNTIME_IDENTIFIER") + .ForwardAs(o => $"/p:RuntimeIdentifiers={string.Join("%3B", o.Arguments)}")), + Create.Option( + "--packages", + "Directory to install packages in.", + Accept.ExactlyOneArgument + .With(name: "PACKAGES_DIRECTORY") + .ForwardAs("/p:RestorePackagesPath={0}")), + Create.Option( + "--disable-parallel", + "Disables restoring multiple projects in parallel.", + Accept.NoArguments + .ForwardAs("/p:RestoreDisableParallel=true")), + Create.Option( + "--configfile", + "The NuGet configuration file to use.", + Accept.ExactlyOneArgument + .With(name: "FILE") + .ForwardAs("/p:RestoreConfigFile={0}")), + Create.Option( + "--no-cache", + "Do not cache packages and http requests.", + Accept.NoArguments + .ForwardAs("/p:RestoreNoCache=true")), + Create.Option( + "--ignore-failed-sources", + "Treat package source failures as warnings.", + Accept.NoArguments + .ForwardAs("/p:RestoreIgnoreFailedSources=true")), + Create.Option( + "--no-dependencies", + "Set this flag to ignore project to project references and only restore the root project", + Accept.NoArguments + .ForwardAs("/p:RestoreRecursive=false")), + CommonOptions.VerbosityOption()); } } \ No newline at end of file diff --git a/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs b/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs new file mode 100644 index 000000000..627d9eea6 --- /dev/null +++ b/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs @@ -0,0 +1,47 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using FluentAssertions; +using Microsoft.DotNet.Cli; +using Microsoft.DotNet.Cli.CommandLine; +using Xunit; +using static Microsoft.DotNet.Cli.CommandLine.Accept; +using static Microsoft.DotNet.Cli.CommandLine.Create; + +namespace Microsoft.DotNet.Tests.ParserTests +{ + public class ArgumentForwardingExtensionsTests + { + [Fact] + public void An_outgoing_command_line_can_be_generated_based_on_a_parse_result() + { + var command = Command("the-command", "", + Option("-o|--one", "", + ZeroOrOneArgument.ForwardAs("/i:{0}")), + Option("-t|--two", "", + ZeroOrOneArgument.ForwardAs("/s:{0}"))); + + var result = command.Parse("the-command -t argument-two-value -o 123"); + + result["the-command"] + .ArgsToBeForwarded() + .Should() + .BeEquivalentTo("/i:123", "/s:argument-two-value"); + } + + [Fact] + public void MultipleArgumentsCanBeJoinedWhenForwarding() + { + var command = Command("the-command", "", + Option("-x", "", + ZeroOrMoreArguments.ForwardAs(o => $"/x:{string.Join("&", o.Arguments)}"))); + + var result = command.Parse("the-command -x one -x two"); + + result["the-command"] + .ArgsToBeForwarded() + .Should() + .BeEquivalentTo("/x:one&two"); + } + } +} \ No newline at end of file From 3dafe9a6e2335ec4d8fdedf6ee19a9888b14cd7f Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 6 Mar 2017 22:10:37 -0800 Subject: [PATCH 008/149] add logging to build --- build_projects/dotnet-cli-build/DotNetTool.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build_projects/dotnet-cli-build/DotNetTool.cs b/build_projects/dotnet-cli-build/DotNetTool.cs index cc3d1cd83..3f164eb0a 100644 --- a/build_projects/dotnet-cli-build/DotNetTool.cs +++ b/build_projects/dotnet-cli-build/DotNetTool.cs @@ -71,7 +71,11 @@ namespace Microsoft.DotNet.Cli.Build protected override string GenerateCommandLineCommands() { - return $"{Command} {Args}"; + var commandLineCommands = $"{Command} {Args}"; + + LogToolCommand($"[DotNetTool] {commandLineCommands}"); + + return commandLineCommands; } protected override void LogToolCommand(string message) From c176b5953f68e53e88eb9aa1e5906dbcb94cdac5 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 7 Mar 2017 07:10:12 -0800 Subject: [PATCH 009/149] additional logging --- src/dotnet/ForwardingApp.cs | 2 + .../dotnet-complete/CompleteCommand.cs | 48 +++++++++++-------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/dotnet/ForwardingApp.cs b/src/dotnet/ForwardingApp.cs index 2ae292b75..01f26aa46 100644 --- a/src/dotnet/ForwardingApp.cs +++ b/src/dotnet/ForwardingApp.cs @@ -80,6 +80,8 @@ namespace Microsoft.DotNet.Cli UseShellExecute = false }; + Reporter.Verbose.WriteLine($"[Forwarding] {processInfo.FileName} {processInfo.Arguments}"); + if (_environmentVariables != null) { foreach (var entry in _environmentVariables) diff --git a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs index f8b08125e..8cb88994b 100644 --- a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs +++ b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs @@ -14,28 +14,34 @@ namespace Microsoft.DotNet.Cli { public static int Run(string[] args) { - DebugHelper.HandleDebugSwitch(ref args); - - // get the parser for the current subcommand - var completeCommandParser = Parser.DotnetCommand["complete"]; - - // parse the arguments - var result = completeCommandParser.Parse(args); - - var complete = result["complete"]; - - var suggestions = Suggestions(complete); - -#if DEBUG - var log = new StringBuilder(); - log.AppendLine($"args: {string.Join(" ", args.Select(a => $"\"{a}\""))}"); - log.AppendLine("diagram: " + result.Diagram()); - File.WriteAllText("parse.log", log.ToString()); -#endif - - foreach (var suggestion in suggestions) + try { - Console.WriteLine(suggestion); + DebugHelper.HandleDebugSwitch(ref args); + + // get the parser for the current subcommand + var parser = Parser.DotnetCommand["complete"]; + + // parse the arguments + var result = parser.Parse(args); + + var complete = result["complete"]; + + var suggestions = Suggestions(complete); + + var log = new StringBuilder(); + log.AppendLine($"args: {string.Join(" ", args.Select(a => $"\"{a}\""))}"); + log.AppendLine("diagram: " + result.Diagram()); + File.WriteAllText("parse.log", log.ToString()); + + foreach (var suggestion in suggestions) + { + Console.WriteLine(suggestion); + } + } + catch (Exception e) + { + File.WriteAllText("dotnet completion exception.log", e.ToString()); + throw; } return 0; From 1ed5b420a9293a1eb39bb27ad979dfa1648cd99a Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 7 Mar 2017 11:28:35 -0800 Subject: [PATCH 010/149] don't split on : or = in restore command parse --- build/DependencyVersions.props | 2 + scripts/register-completions.ps1 | 2 +- src/dotnet/CompleteCommandParser.cs | 21 ------ src/dotnet/ForwardingApp.cs | 2 +- .../dotnet-build/BuildCommandParser.cs | 71 ++++++++++++------- .../dotnet-complete/CompleteCommandParser.cs | 21 ++++++ src/dotnet/commands/dotnet-restore/Program.cs | 7 +- .../dotnet-restore/RestoreCommandParser.cs | 5 +- src/dotnet/dotnet.csproj | 2 +- test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 10 files changed, 80 insertions(+), 55 deletions(-) delete mode 100644 src/dotnet/CompleteCommandParser.cs create mode 100644 src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs diff --git a/build/DependencyVersions.props b/build/DependencyVersions.props index fcf159e33..872193613 100644 --- a/build/DependencyVersions.props +++ b/build/DependencyVersions.props @@ -16,6 +16,8 @@ 1.0.0-beta1-20170209-117 1.0.3 1.0.3 + 0.1.0-alpha-74 + diff --git a/scripts/register-completions.ps1 b/scripts/register-completions.ps1 index 58023e52b..dfc701504 100644 --- a/scripts/register-completions.ps1 +++ b/scripts/register-completions.ps1 @@ -1,7 +1,7 @@ # PowerShell parameter completion shim for the dotnet CLI Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock { param($commandName, $wordToComplete, $cursorPosition) - dotnet.exe complete --position $cursorPosition "$wordToComplete" | ForEach-Object { + C:\dev\github\cli\artifacts\win10-x64\stage2\dotnet.exe complete --position $cursorPosition "$wordToComplete" | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } } \ No newline at end of file diff --git a/src/dotnet/CompleteCommandParser.cs b/src/dotnet/CompleteCommandParser.cs deleted file mode 100644 index b4add15ea..000000000 --- a/src/dotnet/CompleteCommandParser.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Linq; -using Microsoft.DotNet.Cli.CommandLine; - -namespace Microsoft.DotNet.Cli -{ - internal static class CompleteCommandParser - { - public static Command Complete() => - Create.Command("complete", "", - Accept.ExactlyOneArgument - .With(name: "path"), - Create.Option("--position", "", - Accept.ExactlyOneArgument - .With(name: "command"), - o => Int32.Parse(o.Arguments.Single()))); - } -} \ No newline at end of file diff --git a/src/dotnet/ForwardingApp.cs b/src/dotnet/ForwardingApp.cs index 01f26aa46..aad57a197 100644 --- a/src/dotnet/ForwardingApp.cs +++ b/src/dotnet/ForwardingApp.cs @@ -80,7 +80,7 @@ namespace Microsoft.DotNet.Cli UseShellExecute = false }; - Reporter.Verbose.WriteLine($"[Forwarding] {processInfo.FileName} {processInfo.Arguments}"); + Reporter.Output.WriteLine($"[Forwarding] {processInfo.FileName} {processInfo.Arguments}"); if (_environmentVariables != null) { diff --git a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs index f93feb438..9e9a27c1a 100644 --- a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs +++ b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs @@ -8,32 +8,49 @@ namespace Microsoft.DotNet.Cli internal static class BuildCommandParser { public static Command Build() => - Create.Command("build", - ".NET Builder", - CommonOptions.HelpOption(), - Create.Option("-o|--output", - "Output directory in which to place built artifacts.", - Accept.ExactlyOneArgument - .With(name: "OUTPUT_DIR")), - Create.Option("-f|--framework", - "Target framework to build for. The target framework has to be specified in the project file.", - Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile)), - Create.Option("-r|--runtime", - "Target runtime to build for. The default is to build a portable application.", - Accept.AnyOneOf(Suggest.RunTimesFromProjectFile)), - Create.Option("-c|--configuration", - "Configuration to use for building the project. Default for most projects is \"Debug\".", - Accept.ExactlyOneArgument - .With(name: "CONFIGURATION") - .WithSuggestionsFrom("DEBUG", "RELEASE")), - Create.Option("--version-suffix", - "Defines the value for the $(VersionSuffix) property in the project", - Accept.ExactlyOneArgument - .With(name: "VERSION_SUFFIX")), - Create.Option("--no-incremental", - "Disables incremental build."), - Create.Option("--no-dependencies", - "Set this flag to ignore project-to-project references and only build the root project"), - CommonOptions.VerbosityOption()); + Create.Command( + "build", + ".NET Builder", + Accept.ZeroOrOneArgument + .ForwardAs("{0}"), + CommonOptions.HelpOption(), + Create.Option( + "-o|--output", + "Output directory in which to place built artifacts.", + Accept.ExactlyOneArgument + .With(name: "OUTPUT_DIR") + .ForwardAs("/p:OutputPath={0}")), + Create.Option( + "-f|--framework", + "Target framework to build for. The target framework has to be specified in the project file.", + Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) + .ForwardAs("/p:TargetFramework={0}")), + Create.Option( + "-r|--runtime", + "Target runtime to build for. The default is to build a portable application.", + Accept.AnyOneOf(Suggest.RunTimesFromProjectFile) + .ForwardAs("/p:RuntimeIdentifier={0}")), + Create.Option( + "-c|--configuration", + "Configuration to use for building the project. Default for most projects is \"Debug\".", + Accept.ExactlyOneArgument + .With(name: "CONFIGURATION") + .WithSuggestionsFrom("DEBUG", "RELEASE") + .ForwardAs("/p:Configuration={0}")), + Create.Option( + "--version-suffix", + "Defines the value for the $(VersionSuffix) property in the project", + Accept.ExactlyOneArgument + .With(name: "VERSION_SUFFIX") + .ForwardAs("/p:VersionSuffix={0}")), + Create.Option( + "--no-incremental", + "Disables incremental build."), + Create.Option( + "--no-dependencies", + "Set this flag to ignore project-to-project references and only build the root project", + Accept.NoArguments + .ForwardAs("/p:BuildProjectReferences=false")), + CommonOptions.VerbosityOption()); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs b/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs new file mode 100644 index 000000000..f8313355a --- /dev/null +++ b/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs @@ -0,0 +1,21 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Linq; +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + internal static class CompleteCommandParser + { + public static Command Complete() => + Create.Command( + "complete", "", + Accept.ExactlyOneArgument + .With(name: "path") + .MaterializeAs(o => int.Parse(o.Arguments.Single())), + Create.Option("--position", "", + Accept.ExactlyOneArgument + .With(name: "command"))); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-restore/Program.cs b/src/dotnet/commands/dotnet-restore/Program.cs index d24c0cd44..73c1d9794 100644 --- a/src/dotnet/commands/dotnet-restore/Program.cs +++ b/src/dotnet/commands/dotnet-restore/Program.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; using System.Collections.Generic; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; @@ -21,10 +22,14 @@ namespace Microsoft.DotNet.Tools.Restore { DebugHelper.HandleDebugSwitch(ref args); - var parser = Parser.DotnetCommand["restore"]; + var parser = new Cli.CommandLine.Parser( + delimiters: Array.Empty(), + options: Parser.DotnetCommand["restore"]); var result = parser.Parse(args); + Reporter.Verbose.WriteLine(result.Diagram()); + var restore = result["restore"]; var msbuildArgs = new List diff --git a/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs b/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs index 44340ef6b..e9ed45f7a 100644 --- a/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs +++ b/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs @@ -8,9 +8,10 @@ namespace Microsoft.DotNet.Cli internal static class RestoreCommandParser { public static Command Restore() => - Create.Command("restore", + Create.Command( + "restore", ".NET dependency restorer", - Accept.OneOrMoreArguments, + Accept.ExactlyOneArgument, CommonOptions.HelpOption(), Create.Option( "-s|--source", diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index fb24f652e..c97b5fe24 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index 825c0a095..8d940820d 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From 53ea7f62bfaabb742b1140012f9f56659a90cc8b Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 7 Mar 2017 11:29:29 -0800 Subject: [PATCH 011/149] update CliCommandLine version --- src/dotnet/dotnet.csproj | 2 +- test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index c97b5fe24..b1963421e 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index 8d940820d..d7766cd89 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From 30480fa189a360598ec8f0a64abeb4cb8e12b313 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 7 Mar 2017 16:40:18 -0800 Subject: [PATCH 012/149] restore:captures arguments for forwarding to MSBuild --- src/dotnet/Parser.cs | 51 +++++++++--------- .../dotnet-complete/CompleteCommand.cs | 4 +- src/dotnet/commands/dotnet-restore/Program.cs | 7 ++- .../dotnet-restore/RestoreCommandParser.cs | 2 +- src/dotnet/dotnet.csproj | 2 +- .../ParserTests/AddReferenceParserTests.cs | 4 +- .../ParserTests/RestoreParserTests.cs | 52 +++++++++++++++++++ test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 8 files changed, 88 insertions(+), 36 deletions(-) create mode 100644 test/dotnet.Tests/ParserTests/RestoreParserTests.cs diff --git a/src/dotnet/Parser.cs b/src/dotnet/Parser.cs index c57e9d87b..ec1b8b76b 100644 --- a/src/dotnet/Parser.cs +++ b/src/dotnet/Parser.cs @@ -2,36 +2,37 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; -using System.Linq; using Microsoft.DotNet.Cli.CommandLine; namespace Microsoft.DotNet.Cli { public static class Parser { - public static Command DotnetCommand { get; } = - Create.Command("dotnet", - ".NET Command Line Tools", - Accept.NoArguments, - NewCommandParser.New(), - RestoreCommandParser.Restore(), - BuildCommandParser.Build(), - PublishCommandParser.Publish(), - RunCommandParser.Run(), - TestCommandParser.Test(), - PackCommandParser.Pack(), - MigrateCommandParser.Migrate(), - CleanCommandParser.Clean(), - SlnCommandParser.Sln(), - AddCommandParser.Add(), - RemoveCommandParser.Remove(), - ListCommandParser.List(), - NuGetCommandParser.NuGet(), - Create.Command("msbuild", ""), - Create.Command("vstest", ""), CompleteCommandParser.Complete(), - CommonOptions.HelpOption(), - Create.Option("--info", ""), - CommonOptions.VerbosityOption(), - Create.Option("-d", "")); + public static CommandLine.Parser Instance { get; } = new CommandLine.Parser( + delimiters: Array.Empty(), + options: Create.Command("dotnet", + ".NET Command Line Tools", + Accept.NoArguments, + NewCommandParser.New(), + RestoreCommandParser.Restore(), + BuildCommandParser.Build(), + PublishCommandParser.Publish(), + RunCommandParser.Run(), + TestCommandParser.Test(), + PackCommandParser.Pack(), + MigrateCommandParser.Migrate(), + CleanCommandParser.Clean(), + SlnCommandParser.Sln(), + AddCommandParser.Add(), + RemoveCommandParser.Remove(), + ListCommandParser.List(), + NuGetCommandParser.NuGet(), + Create.Command("msbuild", ""), + Create.Command("vstest", ""), + CompleteCommandParser.Complete(), + CommonOptions.HelpOption(), + Create.Option("--info", ""), + CommonOptions.VerbosityOption(), + Create.Option("-d", ""))); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs index 8cb88994b..c314f4141 100644 --- a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs +++ b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs @@ -19,7 +19,7 @@ namespace Microsoft.DotNet.Cli DebugHelper.HandleDebugSwitch(ref args); // get the parser for the current subcommand - var parser = Parser.DotnetCommand["complete"]; + var parser = Parser.Instance["dotnet"]["complete"]; // parse the arguments var result = parser.Parse(args); @@ -62,7 +62,7 @@ namespace Microsoft.DotNet.Cli } } - var result = Parser.DotnetCommand.Parse(input); + var result = Parser.Instance.Parse(input); return result.Suggestions() .ToArray(); diff --git a/src/dotnet/commands/dotnet-restore/Program.cs b/src/dotnet/commands/dotnet-restore/Program.cs index 73c1d9794..65ab11442 100644 --- a/src/dotnet/commands/dotnet-restore/Program.cs +++ b/src/dotnet/commands/dotnet-restore/Program.cs @@ -22,9 +22,7 @@ namespace Microsoft.DotNet.Tools.Restore { DebugHelper.HandleDebugSwitch(ref args); - var parser = new Cli.CommandLine.Parser( - delimiters: Array.Empty(), - options: Parser.DotnetCommand["restore"]); + var parser = Parser.Instance["dotnet"]; var result = parser.Parse(args); @@ -40,8 +38,9 @@ namespace Microsoft.DotNet.Tools.Restore }; msbuildArgs.AddRange(restore.ArgsToBeForwarded()); - msbuildArgs.AddRange(restore.Arguments); + msbuildArgs.AddRange(restore.Arguments); + return new RestoreCommand(msbuildArgs, msbuildPath); } diff --git a/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs b/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs index e9ed45f7a..62ab2f870 100644 --- a/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs +++ b/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs @@ -11,7 +11,7 @@ namespace Microsoft.DotNet.Cli Create.Command( "restore", ".NET dependency restorer", - Accept.ExactlyOneArgument, + Accept.ZeroOrMoreArguments, CommonOptions.HelpOption(), Create.Option( "-s|--source", diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index b1963421e..53de43916 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs b/test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs index 51bb79f75..68121383d 100644 --- a/test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs +++ b/test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs @@ -25,7 +25,7 @@ namespace Microsoft.DotNet.Tests.ParserTests [Fact] public void AddReferenceHasDefaultArgumentSetToCurrentDirectory() { - var command = Parser.DotnetCommand; + var command = Parser.Instance; var result = command.Parse("dotnet add reference my.csproj"); @@ -41,7 +41,7 @@ namespace Microsoft.DotNet.Tests.ParserTests [Fact] public void AddReferenceWithoutArgumentResultsInAnError() { - var command = Parser.DotnetCommand; + var command = Parser.Instance; var result = command.Parse("dotnet add reference"); diff --git a/test/dotnet.Tests/ParserTests/RestoreParserTests.cs b/test/dotnet.Tests/ParserTests/RestoreParserTests.cs new file mode 100644 index 000000000..2dc32cde9 --- /dev/null +++ b/test/dotnet.Tests/ParserTests/RestoreParserTests.cs @@ -0,0 +1,52 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using FluentAssertions; +using Microsoft.DotNet.Cli.CommandLine; +using Xunit; +using Xunit.Abstractions; +using Parser = Microsoft.DotNet.Cli.Parser; + +namespace Microsoft.DotNet.Tests.ParserTests +{ + public class RestoreParserTests + { + private readonly ITestOutputHelper output; + + public RestoreParserTests(ITestOutputHelper output) + { + this.output = output; + } + + [Fact] + public void RestoreCapturesArgumentsToForwardToMSBuildWhenTargetIsSpecified() + { + var parser = Parser.Instance["dotnet"]; + + var result = parser.Parse(@"restore .\some.csproj --packages c:\.nuget\packages /p:SkipInvalidConfigurations=true"); + + output.WriteLine(result.Diagram()); + + result["restore"] + .Arguments + .Should() + .BeEquivalentTo(@".\some.csproj", @"/p:SkipInvalidConfigurations=true"); + } + + [Fact] + public void RestoreCapturesArgumentsToForwardToMSBuildWhenTargetIsNotSpecified() + { + var parser = Parser.Instance["dotnet"]; + + var result = parser.Parse(@"restore --packages c:\.nuget\packages /p:SkipInvalidConfigurations=true"); + + output.WriteLine(result.Diagram()); + + result["restore"] + .Arguments + .Should() + .BeEquivalentTo(@"/p:SkipInvalidConfigurations=true"); + } + } +} \ No newline at end of file diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index d7766cd89..3c6555049 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From fd6f7e48b572a69d93d500d2b3a231b24d1dca07 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Wed, 8 Mar 2017 16:02:24 -0800 Subject: [PATCH 013/149] WIP --- src/dotnet/ParseResultExtensions.cs | 12 +++++++++++- .../commands/dotnet-complete/CompleteCommand.cs | 4 ++-- .../dotnet-complete/CompleteCommandParser.cs | 8 ++++---- src/dotnet/commands/dotnet-restore/Program.cs | 5 +++-- test/dotnet.Tests/ParserTests/RestoreParserTests.cs | 8 ++++---- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/dotnet/ParseResultExtensions.cs b/src/dotnet/ParseResultExtensions.cs index 1eeac1662..894f494fb 100644 --- a/src/dotnet/ParseResultExtensions.cs +++ b/src/dotnet/ParseResultExtensions.cs @@ -2,13 +2,23 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Linq; using Microsoft.DotNet.Cli.CommandLine; namespace Microsoft.DotNet.Cli { + public static class ParserExtensions + { + public static ParseResult ParseFrom( + this CommandLine.Parser parser, + string context, + string[] args) => + parser.Parse(context.Split(' ').Concat(args).ToArray()); + } + public static class ParseResultExtensions { - public static void ShowHelp(this ParseResult parseResult) => + public static void ShowHelp(this ParseResult parseResult) => Console.WriteLine(parseResult.Command().HelpView()); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs index c314f4141..444ecfe08 100644 --- a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs +++ b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs @@ -19,10 +19,10 @@ namespace Microsoft.DotNet.Cli DebugHelper.HandleDebugSwitch(ref args); // get the parser for the current subcommand - var parser = Parser.Instance["dotnet"]["complete"]; + var parser = Parser.Instance; // parse the arguments - var result = parser.Parse(args); + var result = parser.ParseFrom("dotnet complete", args); var complete = result["complete"]; diff --git a/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs b/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs index f8313355a..c42db5fc1 100644 --- a/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs +++ b/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs @@ -12,10 +12,10 @@ namespace Microsoft.DotNet.Cli Create.Command( "complete", "", Accept.ExactlyOneArgument - .With(name: "path") - .MaterializeAs(o => int.Parse(o.Arguments.Single())), + .With(name: "path"), Create.Option("--position", "", - Accept.ExactlyOneArgument - .With(name: "command"))); + Accept.ExactlyOneArgument + .With(name: "command") + .MaterializeAs(o => int.Parse(o.Arguments.Single())))); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-restore/Program.cs b/src/dotnet/commands/dotnet-restore/Program.cs index 65ab11442..39d42a87f 100644 --- a/src/dotnet/commands/dotnet-restore/Program.cs +++ b/src/dotnet/commands/dotnet-restore/Program.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Linq; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; @@ -22,9 +23,9 @@ namespace Microsoft.DotNet.Tools.Restore { DebugHelper.HandleDebugSwitch(ref args); - var parser = Parser.Instance["dotnet"]; + var parser = Parser.Instance; - var result = parser.Parse(args); + var result = parser.ParseFrom("dotnet restore", args); Reporter.Verbose.WriteLine(result.Diagram()); diff --git a/test/dotnet.Tests/ParserTests/RestoreParserTests.cs b/test/dotnet.Tests/ParserTests/RestoreParserTests.cs index 2dc32cde9..44733f907 100644 --- a/test/dotnet.Tests/ParserTests/RestoreParserTests.cs +++ b/test/dotnet.Tests/ParserTests/RestoreParserTests.cs @@ -22,9 +22,9 @@ namespace Microsoft.DotNet.Tests.ParserTests [Fact] public void RestoreCapturesArgumentsToForwardToMSBuildWhenTargetIsSpecified() { - var parser = Parser.Instance["dotnet"]; + var parser = Parser.Instance["dotnet"]["restore"]; - var result = parser.Parse(@"restore .\some.csproj --packages c:\.nuget\packages /p:SkipInvalidConfigurations=true"); + var result = parser.Parse(@".\some.csproj --packages c:\.nuget\packages /p:SkipInvalidConfigurations=true"); output.WriteLine(result.Diagram()); @@ -37,9 +37,9 @@ namespace Microsoft.DotNet.Tests.ParserTests [Fact] public void RestoreCapturesArgumentsToForwardToMSBuildWhenTargetIsNotSpecified() { - var parser = Parser.Instance["dotnet"]; + var parser = Parser.Instance["dotnet"]["restore"]; - var result = parser.Parse(@"restore --packages c:\.nuget\packages /p:SkipInvalidConfigurations=true"); + var result = parser.Parse(@"--packages c:\.nuget\packages /p:SkipInvalidConfigurations=true"); output.WriteLine(result.Diagram()); From 1a0ba248838d89e916338ad583839108c8baead2 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Wed, 8 Mar 2017 17:53:07 -0800 Subject: [PATCH 014/149] publish command using new parser --- src/dotnet/commands/dotnet-publish/Program.cs | 101 ++---------------- .../dotnet-publish/PublishCommandParser.cs | 21 ++-- 2 files changed, 24 insertions(+), 98 deletions(-) diff --git a/src/dotnet/commands/dotnet-publish/Program.cs b/src/dotnet/commands/dotnet-publish/Program.cs index 96214a26d..081a5c1e5 100644 --- a/src/dotnet/commands/dotnet-publish/Program.cs +++ b/src/dotnet/commands/dotnet-publish/Program.cs @@ -1,12 +1,10 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Collections.Generic; using Microsoft.DotNet.Cli; -using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; -using System.Collections.Generic; -using System.Diagnostics; namespace Microsoft.DotNet.Tools.Publish { @@ -21,100 +19,19 @@ namespace Microsoft.DotNet.Tools.Publish { DebugHelper.HandleDebugSwitch(ref args); - CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false); - app.Name = "dotnet publish"; - app.FullName = LocalizableStrings.AppFullName; - app.Description = LocalizableStrings.AppDescription; - app.HandleRemainingArguments = true; - app.ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText; - app.HelpOption("-h|--help"); + var msbuildArgs = new List(); - CommandArgument projectArgument = app.Argument($"<{LocalizableStrings.ProjectArgument}>", - LocalizableStrings.ProjectArgDescription); + var parser = Parser.Instance; - CommandOption frameworkOption = app.Option( - $"-f|--framework <{LocalizableStrings.FrameworkOption}>", LocalizableStrings.FrameworkOptionDescription, - CommandOptionType.SingleValue); + var result = parser.ParseFrom("dotnet publish", args); - CommandOption runtimeOption = app.Option( - $"-r|--runtime <{LocalizableStrings.RuntimeOption}>", LocalizableStrings.RuntimeOptionDescription, - CommandOptionType.SingleValue); + msbuildArgs.Add("/t:Publish"); - CommandOption outputOption = app.Option( - $"-o|--output <{LocalizableStrings.OutputOption}>", LocalizableStrings.OutputOptionDescription, - CommandOptionType.SingleValue); + var appliedPublishOption = result.AppliedOptions["publish"]; - CommandOption configurationOption = app.Option( - $"-c|--configuration <{LocalizableStrings.ConfigurationOption}>", LocalizableStrings.ConfigurationOptionDescription, - CommandOptionType.SingleValue); + msbuildArgs.AddRange(appliedPublishOption.Arguments); - CommandOption versionSuffixOption = app.Option( - $"--version-suffix <{LocalizableStrings.VersionSuffixOption}>", LocalizableStrings.VersionSuffixOptionDescription, - CommandOptionType.SingleValue); - - CommandOption filterProjOption = app.Option( - $"--filter <{LocalizableStrings.FilterProjOption}>", LocalizableStrings.FilterProjOptionDescription, - CommandOptionType.SingleValue); - - CommandOption verbosityOption = AddVerbosityOption(app); - - List msbuildArgs = null; - app.OnExecute(() => - { - msbuildArgs = new List(); - - msbuildArgs.Add("/t:Publish"); - - if (!string.IsNullOrEmpty(projectArgument.Value)) - { - msbuildArgs.Add(projectArgument.Value); - } - - if (!string.IsNullOrEmpty(frameworkOption.Value())) - { - msbuildArgs.Add($"/p:TargetFramework={frameworkOption.Value()}"); - } - - if (!string.IsNullOrEmpty(runtimeOption.Value())) - { - msbuildArgs.Add($"/p:RuntimeIdentifier={runtimeOption.Value()}"); - } - - if (!string.IsNullOrEmpty(outputOption.Value())) - { - msbuildArgs.Add($"/p:PublishDir={outputOption.Value()}"); - } - - if (!string.IsNullOrEmpty(configurationOption.Value())) - { - msbuildArgs.Add($"/p:Configuration={configurationOption.Value()}"); - } - - if (!string.IsNullOrEmpty(versionSuffixOption.Value())) - { - msbuildArgs.Add($"/p:VersionSuffix={versionSuffixOption.Value()}"); - } - - if (!string.IsNullOrEmpty(filterProjOption.Value())) - { - msbuildArgs.Add($"/p:FilterProjectFiles={filterProjOption.Value()}"); - } - - if (!string.IsNullOrEmpty(verbosityOption.Value())) - { - msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}"); - } - - msbuildArgs.AddRange(app.RemainingArguments); - - return 0; - }); - - int exitCode = app.Execute(args); - if (msbuildArgs == null) - { - throw new CommandCreationException(exitCode); - } + msbuildArgs.AddRange(appliedPublishOption.ArgsToBeForwarded()); return new PublishCommand(msbuildArgs, msbuildPath); } @@ -136,4 +53,4 @@ namespace Microsoft.DotNet.Tools.Publish return cmd.Execute(); } } -} +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs index a9ede850d..1526659fa 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs @@ -10,27 +10,36 @@ namespace Microsoft.DotNet.Cli public static Command Publish() => Create.Command("publish", ".NET Publisher", - Accept.ExactlyOneArgument, + Accept.ZeroOrMoreArguments, CommonOptions.HelpOption(), Create.Option("-f|--framework", "Target framework to publish for. The target framework has to be specified in the project file.", Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) - .With(name: "FRAMEWORK")), + .With(name: "FRAMEWORK") + .ForwardAs("/p:TargetFramework={0}")), Create.Option("-r|--runtime", "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.", Accept.AnyOneOf(Suggest.RunTimesFromProjectFile) - .With(name: "RUNTIME_IDENTIFIER")), + .With(name: "RUNTIME_IDENTIFIER") + .ForwardAs("/p:RuntimeIdentifier={0}")), Create.Option("-o|--output", "Output directory in which to place the published artifacts.", Accept.ExactlyOneArgument - .With(name: "OUTPUT_DIR")), + .With(name: "OUTPUT_DIR") + .ForwardAs("/p:PublishDir={0}")), Create.Option("-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", Accept.ExactlyOneArgument .With(name: "CONFIGURATION") - .WithSuggestionsFrom("DEBUG", "RELEASE")), + .WithSuggestionsFrom("DEBUG", "RELEASE") + .ForwardAs("/p:Configuration={0}")), Create.Option("--version-suffix", "Defines the value for the $(VersionSuffix) property in the project.", Accept.ExactlyOneArgument - .With(name: "VERSION_SUFFIX")), + .With(name: "VERSION_SUFFIX") + .ForwardAs("/p:VersionSuffix={0}")), + Create.Option("--filter", "The XML file that contains the list of packages to be excluded from publish step.", + Accept.ExactlyOneArgument + .With(name: "PROFILE_XML") + .ForwardAs("/p:FilterProjectFiles={0}")), CommonOptions.VerbosityOption()); } } \ No newline at end of file From 0b94c979db7a92db1bf8d058cb5abf0b56178cf8 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Thu, 9 Mar 2017 07:35:06 -0800 Subject: [PATCH 015/149] publish using new parser, rename ArgsToBeForwarded --- src/dotnet/ArgumentForwardingExtensions.cs | 2 +- src/dotnet/CommonOptions.cs | 3 +- src/dotnet/Parser.cs | 1 - src/dotnet/Program.cs | 6 ++ src/dotnet/commands/dotnet-publish/Program.cs | 8 +-- .../dotnet-publish/PublishCommandParser.cs | 4 +- src/dotnet/commands/dotnet-restore/Program.cs | 8 ++- .../GivenDotnetPublishInvocation.cs | 55 ++++++++++++++++--- .../ArgumentForwardingExtensionsTests.cs | 4 +- 9 files changed, 70 insertions(+), 21 deletions(-) diff --git a/src/dotnet/ArgumentForwardingExtensions.cs b/src/dotnet/ArgumentForwardingExtensions.cs index 6a559a798..fd47ea8e9 100644 --- a/src/dotnet/ArgumentForwardingExtensions.cs +++ b/src/dotnet/ArgumentForwardingExtensions.cs @@ -19,7 +19,7 @@ namespace Microsoft.DotNet.Cli rule.MaterializeAs(o => new ForwardedArgument(format(o))); - public static IEnumerable ArgsToBeForwarded( + public static IEnumerable OptionValuesToBeForwarded( this AppliedOption command) => command.AppliedOptions .Select(o => o.Value()) diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index 0337bb8aa..a39027bc1 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -17,7 +17,8 @@ namespace Microsoft.DotNet.Cli Create.Option( "-v|--verbosity", "Set the verbosity level of the command. Allowed values are q[uiet],m[inimal],n[ormal],d[etailed], anddiag[nostic]", - Accept.AnyOneOf("q", "quiet", + Accept.AnyOneOf( + "q", "quiet", "m", "minimal", "n", "normal", "d", "detailed") diff --git a/src/dotnet/Parser.cs b/src/dotnet/Parser.cs index ec1b8b76b..4b53bfa45 100644 --- a/src/dotnet/Parser.cs +++ b/src/dotnet/Parser.cs @@ -32,7 +32,6 @@ namespace Microsoft.DotNet.Cli CompleteCommandParser.Complete(), CommonOptions.HelpOption(), Create.Option("--info", ""), - CommonOptions.VerbosityOption(), Create.Option("-d", ""))); } } \ No newline at end of file diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index d463dea58..b3e912daf 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -84,6 +84,12 @@ namespace Microsoft.DotNet.Cli return 1; } + catch (Exception e) when (!e.ShouldBeDisplayedAsError()) + { + Reporter.Output.WriteLine(e.ToString().Red().Bold()); + + return 1; + } finally { if (PerfTrace.Enabled) diff --git a/src/dotnet/commands/dotnet-publish/Program.cs b/src/dotnet/commands/dotnet-publish/Program.cs index 081a5c1e5..8d8c12a20 100644 --- a/src/dotnet/commands/dotnet-publish/Program.cs +++ b/src/dotnet/commands/dotnet-publish/Program.cs @@ -8,7 +8,7 @@ using Microsoft.DotNet.Tools.MSBuild; namespace Microsoft.DotNet.Tools.Publish { - public partial class PublishCommand : MSBuildForwardingApp + public class PublishCommand : MSBuildForwardingApp { private PublishCommand(IEnumerable msbuildArgs, string msbuildPath = null) : base(msbuildArgs, msbuildPath) @@ -27,12 +27,12 @@ namespace Microsoft.DotNet.Tools.Publish msbuildArgs.Add("/t:Publish"); - var appliedPublishOption = result.AppliedOptions["publish"]; + var appliedPublishOption = result["dotnet"]["publish"]; + + msbuildArgs.AddRange(appliedPublishOption.OptionValuesToBeForwarded()); msbuildArgs.AddRange(appliedPublishOption.Arguments); - msbuildArgs.AddRange(appliedPublishOption.ArgsToBeForwarded()); - return new PublishCommand(msbuildArgs, msbuildPath); } diff --git a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs index 1526659fa..2d8cac21b 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs @@ -14,12 +14,12 @@ namespace Microsoft.DotNet.Cli CommonOptions.HelpOption(), Create.Option("-f|--framework", "Target framework to publish for. The target framework has to be specified in the project file.", - Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) + Accept.WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile()) .With(name: "FRAMEWORK") .ForwardAs("/p:TargetFramework={0}")), Create.Option("-r|--runtime", "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.", - Accept.AnyOneOf(Suggest.RunTimesFromProjectFile) + Accept.WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile()) .With(name: "RUNTIME_IDENTIFIER") .ForwardAs("/p:RuntimeIdentifier={0}")), Create.Option("-o|--output", diff --git a/src/dotnet/commands/dotnet-restore/Program.cs b/src/dotnet/commands/dotnet-restore/Program.cs index 39d42a87f..f31291dc4 100644 --- a/src/dotnet/commands/dotnet-restore/Program.cs +++ b/src/dotnet/commands/dotnet-restore/Program.cs @@ -23,13 +23,15 @@ namespace Microsoft.DotNet.Tools.Restore { DebugHelper.HandleDebugSwitch(ref args); + Reporter.Output.WriteLine(string.Join(" ", args)); + var parser = Parser.Instance; var result = parser.ParseFrom("dotnet restore", args); - Reporter.Verbose.WriteLine(result.Diagram()); + Reporter.Output.WriteLine(result.Diagram()); - var restore = result["restore"]; + var restore = result["dotnet"]["restore"]; var msbuildArgs = new List { @@ -38,7 +40,7 @@ namespace Microsoft.DotNet.Tools.Restore "/ConsoleLoggerParameters:Verbosity=Minimal" }; - msbuildArgs.AddRange(restore.ArgsToBeForwarded()); + msbuildArgs.AddRange(restore.OptionValuesToBeForwarded()); msbuildArgs.AddRange(restore.Arguments); diff --git a/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs index 7e0599526..547ecb10e 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs @@ -1,16 +1,25 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.DotNet.Tools.Publish; -using FluentAssertions; -using Xunit; using System; +using FluentAssertions; using System.Linq; +using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Tools.Publish; +using Xunit; +using Xunit.Abstractions; namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetPublishInvocation { + private readonly ITestOutputHelper output; + + public GivenDotnetPublishInvocation(ITestOutputHelper output) + { + this.output = output; + } + const string ExpectedPrefix = "exec /m /v:m /t:Publish"; [Theory] @@ -25,8 +34,8 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [InlineData(new string[] { "--configuration", "" }, "/p:Configuration=")] [InlineData(new string[] { "--version-suffix", "" }, "/p:VersionSuffix=")] [InlineData(new string[] { "--filter", "" }, "/p:FilterProjectFiles=")] - [InlineData(new string[] { "-v", "" }, "/verbosity:")] - [InlineData(new string[] { "--verbosity", "" }, "/verbosity:")] + [InlineData(new string[] { "-v", "minimal" }, "/verbosity:minimal")] + [InlineData(new string[] { "--verbosity", "minimal" }, "/verbosity:minimal")] [InlineData(new string[] { "" }, "")] [InlineData(new string[] { "", "" }, " ")] public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs) @@ -35,7 +44,39 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests var msbuildPath = ""; PublishCommand.FromArgs(args, msbuildPath) - .GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs}"); + .GetProcessStartInfo() + .Arguments.Should() + .Be($"{ExpectedPrefix}{expectedAdditionalArgs}"); + } + + [Theory] + [InlineData(new string[] { }, "")] + [InlineData(new string[] { "-f", "" }, "/p:TargetFramework=")] + [InlineData(new string[] { "--framework", "" }, "/p:TargetFramework=")] + [InlineData(new string[] { "-r", "" }, "/p:RuntimeIdentifier=")] + [InlineData(new string[] { "--runtime", "" }, "/p:RuntimeIdentifier=")] + [InlineData(new string[] { "-o", "" }, "/p:PublishDir=")] + [InlineData(new string[] { "--output", "" }, "/p:PublishDir=")] + [InlineData(new string[] { "-c", "" }, "/p:Configuration=")] + [InlineData(new string[] { "--configuration", "" }, "/p:Configuration=")] + [InlineData(new string[] { "--version-suffix", "" }, "/p:VersionSuffix=")] + [InlineData(new string[] { "--filter", "" }, "/p:FilterProjectFiles=")] + [InlineData(new string[] { "-v", "minimal" }, "/verbosity:minimal")] + [InlineData(new string[] { "--verbosity", "minimal" }, "/verbosity:minimal")] + public void OptionForwardingIsCorrect(string[] args, string expectedAdditionalArgs) + { + var expectedArgs = expectedAdditionalArgs.Split(' ', StringSplitOptions.RemoveEmptyEntries); + + var parser = Parser.Instance; + + var result = parser.ParseFrom("dotnet publish", args); + + output.WriteLine(result.Diagram()); + + result["dotnet"]["publish"] + .OptionValuesToBeForwarded() + .Should() + .BeEquivalentTo(expectedArgs); } } -} +} \ No newline at end of file diff --git a/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs b/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs index 627d9eea6..8763f4c20 100644 --- a/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs +++ b/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs @@ -24,7 +24,7 @@ namespace Microsoft.DotNet.Tests.ParserTests var result = command.Parse("the-command -t argument-two-value -o 123"); result["the-command"] - .ArgsToBeForwarded() + .OptionValuesToBeForwarded() .Should() .BeEquivalentTo("/i:123", "/s:argument-two-value"); } @@ -39,7 +39,7 @@ namespace Microsoft.DotNet.Tests.ParserTests var result = command.Parse("the-command -x one -x two"); result["the-command"] - .ArgsToBeForwarded() + .OptionValuesToBeForwarded() .Should() .BeEquivalentTo("/x:one&two"); } From 4284c4e3639959d86986318e7e4127d43351741d Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Thu, 9 Mar 2017 09:14:55 -0800 Subject: [PATCH 016/149] small change to arg forwarding methods, test fixes --- src/dotnet/ArgumentForwardingExtensions.cs | 7 +- src/dotnet/CommonOptions.cs | 3 +- .../dotnet-build/BuildCommandParser.cs | 13 ++-- .../dotnet-complete/CompleteCommand.cs | 2 +- .../dotnet-complete/CompleteCommandParser.cs | 3 +- .../dotnet-publish/PublishCommandParser.cs | 68 ++++++++++--------- .../dotnet-restore/RestoreCommandParser.cs | 5 +- .../GivenDotnetRestoreInvocation.cs | 4 +- .../ArgumentForwardingExtensionsTests.cs | 38 ++++++++--- .../ParserTests/RestoreParserTests.cs | 12 ++-- 10 files changed, 91 insertions(+), 64 deletions(-) diff --git a/src/dotnet/ArgumentForwardingExtensions.cs b/src/dotnet/ArgumentForwardingExtensions.cs index fd47ea8e9..5e49a4c99 100644 --- a/src/dotnet/ArgumentForwardingExtensions.cs +++ b/src/dotnet/ArgumentForwardingExtensions.cs @@ -7,11 +7,14 @@ namespace Microsoft.DotNet.Cli { public static class ArgumentForwardingExtensions { + public static ArgumentsRule Forward( + this ArgumentsRule rule) => + rule.MaterializeAs(o => new ForwardedArgument(o.Arguments.SingleOrDefault())); + public static ArgumentsRule ForwardAs( this ArgumentsRule rule, string template) => - rule.MaterializeAs(o => - new ForwardedArgument(string.Format(template, o.Arguments.Single()))); + rule.MaterializeAs(o => new ForwardedArgument(template)); public static ArgumentsRule ForwardAs( this ArgumentsRule rule, diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index a39027bc1..c0e6d08d7 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -1,4 +1,5 @@ using System.IO; +using System.Linq; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Tools.Common; @@ -22,7 +23,7 @@ namespace Microsoft.DotNet.Cli "m", "minimal", "n", "normal", "d", "detailed") - .ForwardAs("/verbosity:{0}")); + .ForwardAs(o => $"/verbosity:{o.Arguments.Single()}")); public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory())); diff --git a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs index 9e9a27c1a..77f393a41 100644 --- a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs +++ b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Linq; using Microsoft.DotNet.Cli.CommandLine; namespace Microsoft.DotNet.Cli @@ -12,37 +13,37 @@ namespace Microsoft.DotNet.Cli "build", ".NET Builder", Accept.ZeroOrOneArgument - .ForwardAs("{0}"), + .Forward(), CommonOptions.HelpOption(), Create.Option( "-o|--output", "Output directory in which to place built artifacts.", Accept.ExactlyOneArgument .With(name: "OUTPUT_DIR") - .ForwardAs("/p:OutputPath={0}")), + .ForwardAs(o => $"/p:OutputPath={o.Arguments.Single()}")), Create.Option( "-f|--framework", "Target framework to build for. The target framework has to be specified in the project file.", Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) - .ForwardAs("/p:TargetFramework={0}")), + .ForwardAs(o => $"/p:TargetFramework={o.Arguments.Single()}")), Create.Option( "-r|--runtime", "Target runtime to build for. The default is to build a portable application.", Accept.AnyOneOf(Suggest.RunTimesFromProjectFile) - .ForwardAs("/p:RuntimeIdentifier={0}")), + .ForwardAs(o => $"/p:RuntimeIdentifier={o.Arguments.Single()}")), Create.Option( "-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", Accept.ExactlyOneArgument .With(name: "CONFIGURATION") .WithSuggestionsFrom("DEBUG", "RELEASE") - .ForwardAs("/p:Configuration={0}")), + .ForwardAs(o => $"/p:Configuration={o.Arguments.Single()}")), Create.Option( "--version-suffix", "Defines the value for the $(VersionSuffix) property in the project", Accept.ExactlyOneArgument .With(name: "VERSION_SUFFIX") - .ForwardAs("/p:VersionSuffix={0}")), + .ForwardAs(o => $"/p:VersionSuffix={o.Arguments.Single()}")), Create.Option( "--no-incremental", "Disables incremental build."), diff --git a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs index 444ecfe08..a8375687a 100644 --- a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs +++ b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs @@ -24,7 +24,7 @@ namespace Microsoft.DotNet.Cli // parse the arguments var result = parser.ParseFrom("dotnet complete", args); - var complete = result["complete"]; + var complete = result["dotnet"]["complete"]; var suggestions = Suggestions(complete); diff --git a/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs b/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs index c42db5fc1..e79951fcb 100644 --- a/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs +++ b/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs @@ -15,7 +15,6 @@ namespace Microsoft.DotNet.Cli .With(name: "path"), Create.Option("--position", "", Accept.ExactlyOneArgument - .With(name: "command") - .MaterializeAs(o => int.Parse(o.Arguments.Single())))); + .With(name: "command"))); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs index 2d8cac21b..01ae347c0 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Linq; using Microsoft.DotNet.Cli.CommandLine; namespace Microsoft.DotNet.Cli @@ -8,38 +9,39 @@ namespace Microsoft.DotNet.Cli internal static class PublishCommandParser { public static Command Publish() => - Create.Command("publish", - ".NET Publisher", - Accept.ZeroOrMoreArguments, - CommonOptions.HelpOption(), - Create.Option("-f|--framework", - "Target framework to publish for. The target framework has to be specified in the project file.", - Accept.WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile()) - .With(name: "FRAMEWORK") - .ForwardAs("/p:TargetFramework={0}")), - Create.Option("-r|--runtime", - "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.", - Accept.WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile()) - .With(name: "RUNTIME_IDENTIFIER") - .ForwardAs("/p:RuntimeIdentifier={0}")), - Create.Option("-o|--output", - "Output directory in which to place the published artifacts.", - Accept.ExactlyOneArgument - .With(name: "OUTPUT_DIR") - .ForwardAs("/p:PublishDir={0}")), - Create.Option("-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", - Accept.ExactlyOneArgument - .With(name: "CONFIGURATION") - .WithSuggestionsFrom("DEBUG", "RELEASE") - .ForwardAs("/p:Configuration={0}")), - Create.Option("--version-suffix", "Defines the value for the $(VersionSuffix) property in the project.", - Accept.ExactlyOneArgument - .With(name: "VERSION_SUFFIX") - .ForwardAs("/p:VersionSuffix={0}")), - Create.Option("--filter", "The XML file that contains the list of packages to be excluded from publish step.", - Accept.ExactlyOneArgument - .With(name: "PROFILE_XML") - .ForwardAs("/p:FilterProjectFiles={0}")), - CommonOptions.VerbosityOption()); + Create.Command( + "publish", + ".NET Publisher", + Accept.ZeroOrMoreArguments, + CommonOptions.HelpOption(), + Create.Option("-f|--framework", + "Target framework to publish for. The target framework has to be specified in the project file.", + Accept.WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile()) + .With(name: "FRAMEWORK") + .ForwardAs(o => $"/p:TargetFramework={o.Arguments.Single()}")), + Create.Option("-r|--runtime", + "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.", + Accept.WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile()) + .With(name: "RUNTIME_IDENTIFIER") + .ForwardAs(o => $"/p:RuntimeIdentifier={o.Arguments.Single()}")), + Create.Option("-o|--output", + "Output directory in which to place the published artifacts.", + Accept.ExactlyOneArgument + .With(name: "OUTPUT_DIR") + .ForwardAs(o => $"/p:PublishDir={o.Arguments.Single()}")), + Create.Option("-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", + Accept.ExactlyOneArgument + .With(name: "CONFIGURATION") + .WithSuggestionsFrom("DEBUG", "RELEASE") + .ForwardAs(o => $"/p:Configuration={o.Arguments.Single()}")), + Create.Option("--version-suffix", "Defines the value for the $(VersionSuffix) property in the project.", + Accept.ExactlyOneArgument + .With(name: "VERSION_SUFFIX") + .ForwardAs(o => $"/p:VersionSuffix={o.Arguments.Single()}")), + Create.Option("--filter", "The XML file that contains the list of packages to be excluded from publish step.", + Accept.ExactlyOneArgument + .With(name: "PROFILE_XML") + .ForwardAs(o => $"/p:FilterProjectFiles={o.Arguments.Single()}")), + CommonOptions.VerbosityOption()); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs b/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs index 62ab2f870..39ae995cb 100644 --- a/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs +++ b/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Linq; using Microsoft.DotNet.Cli.CommandLine; namespace Microsoft.DotNet.Cli @@ -31,7 +32,7 @@ namespace Microsoft.DotNet.Cli "Directory to install packages in.", Accept.ExactlyOneArgument .With(name: "PACKAGES_DIRECTORY") - .ForwardAs("/p:RestorePackagesPath={0}")), + .ForwardAs(o => $"/p:RestorePackagesPath={o.Arguments.Single()}")), Create.Option( "--disable-parallel", "Disables restoring multiple projects in parallel.", @@ -42,7 +43,7 @@ namespace Microsoft.DotNet.Cli "The NuGet configuration file to use.", Accept.ExactlyOneArgument .With(name: "FILE") - .ForwardAs("/p:RestoreConfigFile={0}")), + .ForwardAs(o => $"/p:RestoreConfigFile={o.Arguments.Single()}")), Create.Option( "--no-cache", "Do not cache packages and http requests.", diff --git a/test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs index 282549125..c900a6d48 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs @@ -26,8 +26,8 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [InlineData(new string[] { "--no-cache" }, "/p:RestoreNoCache=true")] [InlineData(new string[] { "--ignore-failed-sources" }, "/p:RestoreIgnoreFailedSources=true")] [InlineData(new string[] { "--no-dependencies" }, "/p:RestoreRecursive=false")] - [InlineData(new string[] { "-v", "" }, @"/verbosity:")] - [InlineData(new string[] { "--verbosity", "" }, @"/verbosity:")] + [InlineData(new string[] { "-v", "minimal" }, @"/verbosity:minimal")] + [InlineData(new string[] { "--verbosity", "minimal" }, @"/verbosity:minimal")] public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs) { expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}"); diff --git a/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs b/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs index 8763f4c20..c40b07888 100644 --- a/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs +++ b/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using FluentAssertions; +using System.Linq; using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.CommandLine; using Xunit; @@ -13,28 +14,31 @@ namespace Microsoft.DotNet.Tests.ParserTests public class ArgumentForwardingExtensionsTests { [Fact] - public void An_outgoing_command_line_can_be_generated_based_on_a_parse_result() + public void AnOutgoingCommandLineCanBeGeneratedBasedOnAParseResult() { var command = Command("the-command", "", - Option("-o|--one", "", - ZeroOrOneArgument.ForwardAs("/i:{0}")), - Option("-t|--two", "", - ZeroOrOneArgument.ForwardAs("/s:{0}"))); + Option("-o|--one", "", + ZeroOrOneArgument + .ForwardAs(o => $"/i:{o.Arguments.Single()}")), + Option("-t|--two", "", + NoArguments + .ForwardAs("/s:true"))); - var result = command.Parse("the-command -t argument-two-value -o 123"); + var result = command.Parse("the-command -t -o 123"); result["the-command"] .OptionValuesToBeForwarded() .Should() - .BeEquivalentTo("/i:123", "/s:argument-two-value"); + .BeEquivalentTo("/i:123", "/s:true"); } [Fact] public void MultipleArgumentsCanBeJoinedWhenForwarding() { var command = Command("the-command", "", - Option("-x", "", - ZeroOrMoreArguments.ForwardAs(o => $"/x:{string.Join("&", o.Arguments)}"))); + Option("-x", "", + ZeroOrMoreArguments + .ForwardAs(o => $"/x:{string.Join("&", o.Arguments)}"))); var result = command.Parse("the-command -x one -x two"); @@ -43,5 +47,21 @@ namespace Microsoft.DotNet.Tests.ParserTests .Should() .BeEquivalentTo("/x:one&two"); } + + [Fact] + public void AnArgumentCanBeForwardedAsIs() + { + var command = Command("the-command", "", + Option("-x", "", + ZeroOrMoreArguments + .Forward())); + + var result = command.Parse("the-command -x one"); + + result["the-command"] + .OptionValuesToBeForwarded() + .Should() + .BeEquivalentTo("one"); + } } } \ No newline at end of file diff --git a/test/dotnet.Tests/ParserTests/RestoreParserTests.cs b/test/dotnet.Tests/ParserTests/RestoreParserTests.cs index 44733f907..cb3128cc0 100644 --- a/test/dotnet.Tests/ParserTests/RestoreParserTests.cs +++ b/test/dotnet.Tests/ParserTests/RestoreParserTests.cs @@ -22,13 +22,13 @@ namespace Microsoft.DotNet.Tests.ParserTests [Fact] public void RestoreCapturesArgumentsToForwardToMSBuildWhenTargetIsSpecified() { - var parser = Parser.Instance["dotnet"]["restore"]; + var parser = Parser.Instance; - var result = parser.Parse(@".\some.csproj --packages c:\.nuget\packages /p:SkipInvalidConfigurations=true"); + var result = parser.Parse(@"dotnet restore .\some.csproj --packages c:\.nuget\packages /p:SkipInvalidConfigurations=true"); output.WriteLine(result.Diagram()); - result["restore"] + result["dotnet"]["restore"] .Arguments .Should() .BeEquivalentTo(@".\some.csproj", @"/p:SkipInvalidConfigurations=true"); @@ -37,13 +37,13 @@ namespace Microsoft.DotNet.Tests.ParserTests [Fact] public void RestoreCapturesArgumentsToForwardToMSBuildWhenTargetIsNotSpecified() { - var parser = Parser.Instance["dotnet"]["restore"]; + var parser = Parser.Instance; - var result = parser.Parse(@"--packages c:\.nuget\packages /p:SkipInvalidConfigurations=true"); + var result = parser.Parse(@"dotnet restore --packages c:\.nuget\packages /p:SkipInvalidConfigurations=true"); output.WriteLine(result.Diagram()); - result["restore"] + result["dotnet"]["restore"] .Arguments .Should() .BeEquivalentTo(@"/p:SkipInvalidConfigurations=true"); From 998ac9c3eb3d287e06c69cfaefbcfab21b4b3926 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Thu, 9 Mar 2017 10:53:17 -0800 Subject: [PATCH 017/149] ParseCommand --- src/dotnet/Program.cs | 1 + .../commands/dotnet-complete/ParseCommand.cs | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/dotnet/commands/dotnet-complete/ParseCommand.cs diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index b3e912daf..57210c2e2 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -54,6 +54,7 @@ namespace Microsoft.DotNet.Cli ["test"] = TestCommand.Run, ["vstest"] = VSTestCommand.Run, ["complete"] = CompleteCommand.Run, + ["parse"] = ParseCommand.Run, }; public static int Main(string[] args) diff --git a/src/dotnet/commands/dotnet-complete/ParseCommand.cs b/src/dotnet/commands/dotnet-complete/ParseCommand.cs new file mode 100644 index 000000000..c5fc76d6c --- /dev/null +++ b/src/dotnet/commands/dotnet-complete/ParseCommand.cs @@ -0,0 +1,23 @@ +using System; +using System.Linq; +using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Cli.Utils; + +namespace Microsoft.DotNet.Cli +{ + public class ParseCommand + { + public static int Run(string[] args) + { + DebugHelper.HandleDebugSwitch(ref args); + + var resultOfParsingArg = + Parser.Instance.Parse( + args.Single()); + + Console.WriteLine(resultOfParsingArg.Diagram()); + + return 0; + } + } +} \ No newline at end of file From ea308e9b59a5b37aee135f4c965369037d292f88 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Thu, 9 Mar 2017 12:19:27 -0800 Subject: [PATCH 018/149] temporarily skip extra args help text tests --- test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs b/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs index af871c2ae..41622c72f 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs @@ -60,7 +60,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests .HaveStdOutContaining("You want me to say 'GreatScott'"); } - [Theory] + [Theory(Skip="New parser feature needed")] [InlineData("build")] [InlineData("clean")] [InlineData("pack")] From 46b799af013f5b23675c95b603b650181a5a57a2 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Thu, 9 Mar 2017 12:31:34 -0800 Subject: [PATCH 019/149] trigger help display using HelpException --- src/dotnet/HelpException.cs | 23 +++++++++++++++++++ src/dotnet/ParseResultExtensions.cs | 20 ++++++++-------- src/dotnet/ParserExtensions.cs | 14 +++++++++++ src/dotnet/Program.cs | 5 ++++ src/dotnet/commands/dotnet-publish/Program.cs | 2 ++ src/dotnet/commands/dotnet-restore/Program.cs | 4 +++- 6 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 src/dotnet/HelpException.cs create mode 100644 src/dotnet/ParserExtensions.cs diff --git a/src/dotnet/HelpException.cs b/src/dotnet/HelpException.cs new file mode 100644 index 000000000..be6427f06 --- /dev/null +++ b/src/dotnet/HelpException.cs @@ -0,0 +1,23 @@ +using System; +using Microsoft.DotNet.Cli.Utils; + +namespace Microsoft.DotNet.Cli +{ + /// + /// Allows control flow to be interrupted in order to display help in the console. + /// + [Obsolete("This is intended to facilitate refactoring during parser replacement and should not be used after that work is done.")] + public class HelpException : Exception + { + public HelpException( + string message, + bool isError = false) : base(message) + { + IsError = isError; + + Data.Add(ExceptionExtensions.CLI_User_Displayed_Exception, true); + } + + public bool IsError { get; } + } +} \ No newline at end of file diff --git a/src/dotnet/ParseResultExtensions.cs b/src/dotnet/ParseResultExtensions.cs index 894f494fb..f4ae8866a 100644 --- a/src/dotnet/ParseResultExtensions.cs +++ b/src/dotnet/ParseResultExtensions.cs @@ -7,18 +7,20 @@ using Microsoft.DotNet.Cli.CommandLine; namespace Microsoft.DotNet.Cli { - public static class ParserExtensions - { - public static ParseResult ParseFrom( - this CommandLine.Parser parser, - string context, - string[] args) => - parser.Parse(context.Split(' ').Concat(args).ToArray()); - } - public static class ParseResultExtensions { public static void ShowHelp(this ParseResult parseResult) => Console.WriteLine(parseResult.Command().HelpView()); + + public static void ShowHelpIfRequested(this ParseResult parseResult) + { + if (parseResult.HasOption("help")) + { + + // NOTE: this is a temporary stage in refactoring toward the ClicCommandLineParser being used at the CLI entry point. + + throw new HelpException(parseResult.Command().HelpView()); + } + } } } \ No newline at end of file diff --git a/src/dotnet/ParserExtensions.cs b/src/dotnet/ParserExtensions.cs new file mode 100644 index 000000000..fd378f0f3 --- /dev/null +++ b/src/dotnet/ParserExtensions.cs @@ -0,0 +1,14 @@ +using System.Linq; +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + public static class ParserExtensions + { + public static ParseResult ParseFrom( + this CommandLine.Parser parser, + string context, + string[] args) => + parser.Parse(context.Split(' ').Concat(args).ToArray()); + } +} \ No newline at end of file diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 57210c2e2..b47943ce8 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -77,6 +77,11 @@ namespace Microsoft.DotNet.Cli return ProcessArgs(args); } } + catch (HelpException e) + { + Reporter.Output.Write(e.Message); + return e.IsError ? 1 : 0; + } catch (Exception e) when (e.ShouldBeDisplayedAsError()) { Reporter.Error.WriteLine(CommandContext.IsVerbose() ? diff --git a/src/dotnet/commands/dotnet-publish/Program.cs b/src/dotnet/commands/dotnet-publish/Program.cs index 8d8c12a20..c04364f82 100644 --- a/src/dotnet/commands/dotnet-publish/Program.cs +++ b/src/dotnet/commands/dotnet-publish/Program.cs @@ -25,6 +25,8 @@ namespace Microsoft.DotNet.Tools.Publish var result = parser.ParseFrom("dotnet publish", args); + result.ShowHelpIfRequested(); + msbuildArgs.Add("/t:Publish"); var appliedPublishOption = result["dotnet"]["publish"]; diff --git a/src/dotnet/commands/dotnet-restore/Program.cs b/src/dotnet/commands/dotnet-restore/Program.cs index f31291dc4..178648938 100644 --- a/src/dotnet/commands/dotnet-restore/Program.cs +++ b/src/dotnet/commands/dotnet-restore/Program.cs @@ -29,6 +29,8 @@ namespace Microsoft.DotNet.Tools.Restore var result = parser.ParseFrom("dotnet restore", args); + result.ShowHelpIfRequested(); + Reporter.Output.WriteLine(result.Diagram()); var restore = result["dotnet"]["restore"]; @@ -60,7 +62,7 @@ namespace Microsoft.DotNet.Tools.Restore { return e.ExitCode; } - + return cmd.Execute(); } } From ea899f236e3c6d9428aa52f499c3d439a07d19de Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Thu, 9 Mar 2017 13:19:46 -0800 Subject: [PATCH 020/149] fix publish parser args validation --- src/dotnet/commands/dotnet-publish/PublishCommandParser.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs index 01ae347c0..4aae155ce 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs @@ -16,12 +16,14 @@ namespace Microsoft.DotNet.Cli CommonOptions.HelpOption(), Create.Option("-f|--framework", "Target framework to publish for. The target framework has to be specified in the project file.", - Accept.WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile()) + Accept.ExactlyOneArgument + .WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile()) .With(name: "FRAMEWORK") .ForwardAs(o => $"/p:TargetFramework={o.Arguments.Single()}")), Create.Option("-r|--runtime", "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.", - Accept.WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile()) + Accept.ExactlyOneArgument + .WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile()) .With(name: "RUNTIME_IDENTIFIER") .ForwardAs(o => $"/p:RuntimeIdentifier={o.Arguments.Single()}")), Create.Option("-o|--output", From ee2b8f2efac1b028c52c75ac31e00c8fe925b4e2 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Thu, 9 Mar 2017 13:57:37 -0800 Subject: [PATCH 021/149] add diag to VerbosityOption --- src/dotnet/CommonOptions.cs | 3 ++- src/dotnet/commands/dotnet-publish/Program.cs | 4 ++++ src/dotnet/commands/dotnet-restore/Program.cs | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index c0e6d08d7..8667b5f76 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -22,7 +22,8 @@ namespace Microsoft.DotNet.Cli "q", "quiet", "m", "minimal", "n", "normal", - "d", "detailed") + "d", "detailed", + "diag", "diagnostic") .ForwardAs(o => $"/verbosity:{o.Arguments.Single()}")); public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => diff --git a/src/dotnet/commands/dotnet-publish/Program.cs b/src/dotnet/commands/dotnet-publish/Program.cs index c04364f82..6ba893605 100644 --- a/src/dotnet/commands/dotnet-publish/Program.cs +++ b/src/dotnet/commands/dotnet-publish/Program.cs @@ -3,8 +3,10 @@ using System.Collections.Generic; using Microsoft.DotNet.Cli; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; +using Parser = Microsoft.DotNet.Cli.Parser; namespace Microsoft.DotNet.Tools.Publish { @@ -25,6 +27,8 @@ namespace Microsoft.DotNet.Tools.Publish var result = parser.ParseFrom("dotnet publish", args); + Reporter.Output.WriteLine(result.Diagram()); + result.ShowHelpIfRequested(); msbuildArgs.Add("/t:Publish"); diff --git a/src/dotnet/commands/dotnet-restore/Program.cs b/src/dotnet/commands/dotnet-restore/Program.cs index 178648938..537f9a0c9 100644 --- a/src/dotnet/commands/dotnet-restore/Program.cs +++ b/src/dotnet/commands/dotnet-restore/Program.cs @@ -29,10 +29,10 @@ namespace Microsoft.DotNet.Tools.Restore var result = parser.ParseFrom("dotnet restore", args); - result.ShowHelpIfRequested(); - Reporter.Output.WriteLine(result.Diagram()); + result.ShowHelpIfRequested(); + var restore = result["dotnet"]["restore"]; var msbuildArgs = new List From ae152503aaade34e261b76a31aedfcbcfdfa22f8 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Thu, 9 Mar 2017 14:30:45 -0800 Subject: [PATCH 022/149] port build command --- src/dotnet/commands/dotnet-build/Program.cs | 107 +++++--------------- 1 file changed, 23 insertions(+), 84 deletions(-) diff --git a/src/dotnet/commands/dotnet-build/Program.cs b/src/dotnet/commands/dotnet-build/Program.cs index 1bf412224..c3e9d8a0f 100644 --- a/src/dotnet/commands/dotnet-build/Program.cs +++ b/src/dotnet/commands/dotnet-build/Program.cs @@ -8,6 +8,7 @@ using Microsoft.DotNet.Tools.MSBuild; using System.Diagnostics; using System; using Microsoft.DotNet.Cli; +using Parser = Microsoft.DotNet.Cli.Parser; namespace Microsoft.DotNet.Tools.Build { @@ -20,96 +21,34 @@ namespace Microsoft.DotNet.Tools.Build public static BuildCommand FromArgs(string[] args, string msbuildPath = null) { - CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false); - app.Name = "dotnet build"; - app.FullName = LocalizableStrings.AppFullName; - app.Description = LocalizableStrings.AppDescription; - app.ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText; - app.HandleRemainingArguments = true; - app.HelpOption("-h|--help"); + DebugHelper.HandleDebugSwitch(ref args); - CommandArgument projectArgument = app.Argument($"<{LocalizableStrings.ProjectArgumentValueName}>", LocalizableStrings.ProjectArgumentDescription); + var msbuildArgs = new List(); - CommandOption outputOption = app.Option($"-o|--output <{LocalizableStrings.OutputOptionName}>", LocalizableStrings.OutputOptionDescription, CommandOptionType.SingleValue); - CommandOption frameworkOption = app.Option($"-f|--framework <{LocalizableStrings.FrameworkOptionName}>", LocalizableStrings.FrameworkOptionDescription, CommandOptionType.SingleValue); - CommandOption runtimeOption = app.Option( - $"-r|--runtime <{LocalizableStrings.RuntimeOptionName}>", LocalizableStrings.RuntimeOptionDescription, - CommandOptionType.SingleValue); - CommandOption configurationOption = app.Option($"-c|--configuration <{LocalizableStrings.ConfigurationOptionName}>", LocalizableStrings.ConfigurationOptionDescription, CommandOptionType.SingleValue); - CommandOption versionSuffixOption = app.Option($"--version-suffix <{LocalizableStrings.VersionSuffixOptionName}>", LocalizableStrings.VersionSuffixOptionDescription, CommandOptionType.SingleValue); + var parser = Parser.Instance; - CommandOption noIncrementalOption = app.Option("--no-incremental", LocalizableStrings.NoIncrementialOptionDescription, CommandOptionType.NoValue); - CommandOption noDependenciesOption = app.Option("--no-dependencies", LocalizableStrings.NoDependenciesOptionDescription, CommandOptionType.NoValue); - CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app); + var result = parser.ParseFrom("dotnet build", args); - List msbuildArgs = null; - app.OnExecute(() => + Reporter.Output.WriteLine(result.Diagram()); + + result.ShowHelpIfRequested(); + + var appliedBuildOptions = result["dotnet"]["build"]; + + if (result.HasOption("--no-incremental")) { - // this delayed initialization is here intentionally - // this code will not get run in some cases (i.e. --help) - msbuildArgs = new List(); - - if (!string.IsNullOrEmpty(projectArgument.Value)) - { - msbuildArgs.Add(projectArgument.Value); - } - - if (noIncrementalOption.HasValue()) - { - msbuildArgs.Add("/t:Rebuild"); - } - else - { - msbuildArgs.Add("/t:Build"); - } - - if (outputOption.HasValue()) - { - msbuildArgs.Add($"/p:OutputPath={outputOption.Value()}"); - } - - if (frameworkOption.HasValue()) - { - msbuildArgs.Add($"/p:TargetFramework={frameworkOption.Value()}"); - } - - if (runtimeOption.HasValue()) - { - msbuildArgs.Add($"/p:RuntimeIdentifier={runtimeOption.Value()}"); - } - - if (configurationOption.HasValue()) - { - msbuildArgs.Add($"/p:Configuration={configurationOption.Value()}"); - } - - if (versionSuffixOption.HasValue()) - { - msbuildArgs.Add($"/p:VersionSuffix={versionSuffixOption.Value()}"); - } - - if (noDependenciesOption.HasValue()) - { - msbuildArgs.Add("/p:BuildProjectReferences=false"); - } - - if (verbosityOption.HasValue()) - { - msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}"); - } - - msbuildArgs.Add($"/clp:Summary"); - - msbuildArgs.AddRange(app.RemainingArguments); - - return 0; - }); - - int exitCode = app.Execute(args); - if (msbuildArgs == null) - { - throw new CommandCreationException(exitCode); + msbuildArgs.Add("/t:Rebuild"); } + else + { + msbuildArgs.Add("/t:Build"); + } + + msbuildArgs.Add($"/clp:Summary"); + + msbuildArgs.AddRange(appliedBuildOptions.OptionValuesToBeForwarded()); + + msbuildArgs.AddRange(appliedBuildOptions.Arguments); return new BuildCommand(msbuildArgs, msbuildPath); } From 30e856a36573e0635d36393ba42307183a79bfbb Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Thu, 9 Mar 2017 14:47:02 -0800 Subject: [PATCH 023/149] zeroormore --- src/dotnet/commands/dotnet-build/BuildCommandParser.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs index 77f393a41..e00ed76eb 100644 --- a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs +++ b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs @@ -12,8 +12,7 @@ namespace Microsoft.DotNet.Cli Create.Command( "build", ".NET Builder", - Accept.ZeroOrOneArgument - .Forward(), + Accept.ZeroOrMoreArguments, CommonOptions.HelpOption(), Create.Option( "-o|--output", From 3ebdf2909d46a1c2b25d5d5461e314292976c7a6 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Thu, 9 Mar 2017 16:11:58 -0800 Subject: [PATCH 024/149] TFM, RID, Config as CommonOptions --- src/dotnet/CommonOptions.cs | 29 ++++++++++++++++++- .../dotnet-build/BuildCommandParser.cs | 20 ++----------- .../dotnet-publish/PublishCommandParser.cs | 20 ++----------- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index 8667b5f76..cfc1c1c70 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -17,7 +17,7 @@ namespace Microsoft.DotNet.Cli public static Option VerbosityOption() => Create.Option( "-v|--verbosity", - "Set the verbosity level of the command. Allowed values are q[uiet],m[inimal],n[ormal],d[etailed], anddiag[nostic]", + "Set the verbosity level of the command. Allowed values are q[uiet],�m[inimal],�n[ormal],�d[etailed], and�diag[nostic]", Accept.AnyOneOf( "q", "quiet", "m", "minimal", @@ -25,6 +25,33 @@ namespace Microsoft.DotNet.Cli "d", "detailed", "diag", "diagnostic") .ForwardAs(o => $"/verbosity:{o.Arguments.Single()}")); + + public static Option FrameworkOption() => + Create.Option( + "-f|--framework", + "Target framework to publish for. The target framework has to be specified in the project file.", + Accept.ExactlyOneArgument + .WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile()) + .With(name: "FRAMEWORK") + .ForwardAs(o => $"/p:TargetFramework={o.Arguments.Single()}")); + + public static Option RuntimeOption() => + Create.Option( + "-r|--runtime", + "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.", + Accept.ExactlyOneArgument + .WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile()) + .With(name: "RUNTIME_IDENTIFIER") + .ForwardAs(o => $"/p:RuntimeIdentifier={o.Arguments.Single()}")); + + public static Option ConfigurationOption() => + Create.Option( + "-c|--configuration", + "Configuration to use for building the project. Default for most projects is \"Debug\".", + Accept.ExactlyOneArgument + .With(name: "CONFIGURATION") + .WithSuggestionsFrom("DEBUG", "RELEASE") + .ForwardAs(o => $"/p:Configuration={o.Arguments.Single()}")), public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory())); diff --git a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs index e00ed76eb..8394ce441 100644 --- a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs +++ b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs @@ -20,23 +20,9 @@ namespace Microsoft.DotNet.Cli Accept.ExactlyOneArgument .With(name: "OUTPUT_DIR") .ForwardAs(o => $"/p:OutputPath={o.Arguments.Single()}")), - Create.Option( - "-f|--framework", - "Target framework to build for. The target framework has to be specified in the project file.", - Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) - .ForwardAs(o => $"/p:TargetFramework={o.Arguments.Single()}")), - Create.Option( - "-r|--runtime", - "Target runtime to build for. The default is to build a portable application.", - Accept.AnyOneOf(Suggest.RunTimesFromProjectFile) - .ForwardAs(o => $"/p:RuntimeIdentifier={o.Arguments.Single()}")), - Create.Option( - "-c|--configuration", - "Configuration to use for building the project. Default for most projects is \"Debug\".", - Accept.ExactlyOneArgument - .With(name: "CONFIGURATION") - .WithSuggestionsFrom("DEBUG", "RELEASE") - .ForwardAs(o => $"/p:Configuration={o.Arguments.Single()}")), + CommonOptions.FrameworkOption(), + CommonOptions.RuntimeOption(), + CommonOptions.ConfigurationOption(), Create.Option( "--version-suffix", "Defines the value for the $(VersionSuffix) property in the project", diff --git a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs index 4aae155ce..895ea919b 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs @@ -14,28 +14,14 @@ namespace Microsoft.DotNet.Cli ".NET Publisher", Accept.ZeroOrMoreArguments, CommonOptions.HelpOption(), - Create.Option("-f|--framework", - "Target framework to publish for. The target framework has to be specified in the project file.", - Accept.ExactlyOneArgument - .WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile()) - .With(name: "FRAMEWORK") - .ForwardAs(o => $"/p:TargetFramework={o.Arguments.Single()}")), - Create.Option("-r|--runtime", - "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.", - Accept.ExactlyOneArgument - .WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile()) - .With(name: "RUNTIME_IDENTIFIER") - .ForwardAs(o => $"/p:RuntimeIdentifier={o.Arguments.Single()}")), + CommonOptions.FrameworkOption(), + CommonOptions.RuntimeOption(), Create.Option("-o|--output", "Output directory in which to place the published artifacts.", Accept.ExactlyOneArgument .With(name: "OUTPUT_DIR") .ForwardAs(o => $"/p:PublishDir={o.Arguments.Single()}")), - Create.Option("-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", - Accept.ExactlyOneArgument - .With(name: "CONFIGURATION") - .WithSuggestionsFrom("DEBUG", "RELEASE") - .ForwardAs(o => $"/p:Configuration={o.Arguments.Single()}")), + CommonOptions.ConfigurationOption(), Create.Option("--version-suffix", "Defines the value for the $(VersionSuffix) property in the project.", Accept.ExactlyOneArgument .With(name: "VERSION_SUFFIX") From e0da3090e6cfb261d104e937aa4a242e52eaee73 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Thu, 9 Mar 2017 16:12:08 -0800 Subject: [PATCH 025/149] Initial Cache parser --- src/dotnet/Parser.cs | 1 + .../dotnet-cache/CacheCommandParser.cs | 57 +++++++++ .../dotnet-cache/LocalizableStrings.cs | 2 +- src/dotnet/commands/dotnet-cache/Program.cs | 114 +++--------------- 4 files changed, 75 insertions(+), 99 deletions(-) create mode 100644 src/dotnet/commands/dotnet-cache/CacheCommandParser.cs diff --git a/src/dotnet/Parser.cs b/src/dotnet/Parser.cs index 4b53bfa45..0c208cfa5 100644 --- a/src/dotnet/Parser.cs +++ b/src/dotnet/Parser.cs @@ -27,6 +27,7 @@ namespace Microsoft.DotNet.Cli RemoveCommandParser.Remove(), ListCommandParser.List(), NuGetCommandParser.NuGet(), + CacheCommandParser.Cache(), Create.Command("msbuild", ""), Create.Command("vstest", ""), CompleteCommandParser.Complete(), diff --git a/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs b/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs new file mode 100644 index 000000000..580f0fb48 --- /dev/null +++ b/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs @@ -0,0 +1,57 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Linq; +using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Tools.Cache; + +namespace Microsoft.DotNet.Cli +{ + internal static class CacheCommandParser + { + public static Command Cache() => + Create.Command( + LocalizableStrings.AppFullName, + LocalizableStrings.AppDescription, + Accept.ZeroOrMoreArguments, + CommonOptions.HelpOption(), + Create.Option( + "-e|--entries", + LocalizableStrings.ProjectEntryDescription, + Accept.ExactlyOneArgument + .With(name: LocalizableStrings.ProjectEntries) + .Forward()), + CommonOptions.FrameworkOption(), + Create.Option( + "--framework-version", + LocalizableStrings.FrameworkVersionOptionDescription, + Accept.ExactlyOneArgument + .With(name: LocalizableStrings.FrameworkVersionOption) + .ForwardAs(o => $"/p:FX_Version={o.Arguments.Single()}")), + CommonOptions.RuntimeOption(), + CommonOptions.ConfigurationOption(), + Create.Option( + "-o|--output", + LocalizableStrings.OutputOptionDescription, + Accept.ExactlyOneArgument + .With(name: LocalizableStrings.OutputOption) + .ForwardAs(o => $"/p:ComposeDir={o.Arguments.Single()}")), + Create.Option( + "-w |--working-dir", + LocalizableStrings.IntermediateWorkingDirOptionDescription, + Accept.ExactlyOneArgument + .With(name: LocalizableStrings.IntermediateWorkingDirOption) + .ForwardAs(o => $"/p:ComposeWorkingDir={o.Arguments.Single()}")), + Create.Option( + "--preserve-working-dir", + LocalizableStrings.PreserveIntermediateWorkingDirOptionDescription, + Accept.NoArguments + .ForwardAs(o => $"/p:PreserveComposeWorkingDir=true")), + Create.Option( + "--skip-optimization", + LocalizableStrings.SkipOptimizationOptionDescription, + Accept.NoArguments + .ForwardAs("/p:SkipOptimization=true")), + CommonOptions.VerbosityOption()); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-cache/LocalizableStrings.cs b/src/dotnet/commands/dotnet-cache/LocalizableStrings.cs index 677ae5618..9596af025 100644 --- a/src/dotnet/commands/dotnet-cache/LocalizableStrings.cs +++ b/src/dotnet/commands/dotnet-cache/LocalizableStrings.cs @@ -9,7 +9,7 @@ namespace Microsoft.DotNet.Tools.Cache public const string AppDescription = "Caches the specified assemblies for the .NET Platform. By default, these will be optimized for the target runtime and framework."; - public const string ProjectEntries = "ProjectEntries"; + public const string ProjectEntries = "PROJECT_ENTRIES"; public const string ProjectEntryDescription = "The XML file that contains the list of packages to be cached."; diff --git a/src/dotnet/commands/dotnet-cache/Program.cs b/src/dotnet/commands/dotnet-cache/Program.cs index 2e995ea42..d4325ab1a 100644 --- a/src/dotnet/commands/dotnet-cache/Program.cs +++ b/src/dotnet/commands/dotnet-cache/Program.cs @@ -23,113 +23,31 @@ namespace Microsoft.DotNet.Tools.Cache { DebugHelper.HandleDebugSwitch(ref args); - var app = new CommandLineApplication(throwOnUnexpectedArg: false); - app.Name = "dotnet cache"; - app.FullName = LocalizableStrings.AppFullName; - app.Description = LocalizableStrings.AppDescription; - app.AllowArgumentSeparator = true; - app.ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText; - app.HelpOption("-h|--help"); + var msbuildArgs = new List(); - CommandOption projectArgument = app.Option( - $"-e|--entries <{LocalizableStrings.ProjectEntries}>", LocalizableStrings.ProjectEntryDescription, - CommandOptionType.SingleValue); + var parser = Parser.Instance; - CommandOption frameworkOption = app.Option( - $"-f|--framework <{LocalizableStrings.FrameworkOption}>", LocalizableStrings.FrameworkOptionDescription, - CommandOptionType.SingleValue); + var result = parser.ParseFrom("dotnet cache", args); - CommandOption runtimeOption = app.Option( - $"-r|--runtime <{LocalizableStrings.RuntimeOption}>", LocalizableStrings.RuntimeOptionDescription, - CommandOptionType.SingleValue); + Reporter.Output.WriteLine(result.Diagram()); - CommandOption outputOption = app.Option( - $"-o|--output <{LocalizableStrings.OutputOption}>", LocalizableStrings.OutputOptionDescription, - CommandOptionType.SingleValue); + result.ShowHelpIfRequested(); - CommandOption fxOption = app.Option( - $"--framework-version <{LocalizableStrings.FrameworkVersionOption}>", LocalizableStrings.FrameworkVersionOptionDescription, - CommandOptionType.SingleValue); + var appliedBuildOptions = result["dotnet"]["cache"]; - CommandOption skipOptimizationOption = app.Option( - $"--skip-optimization", LocalizableStrings.SkipOptimizationOptionDescription, - CommandOptionType.NoValue); - - CommandOption workingDir = app.Option( - $"-w |--working-dir <{LocalizableStrings.IntermediateWorkingDirOption}>", LocalizableStrings.IntermediateWorkingDirOptionDescription, - CommandOptionType.SingleValue); - - CommandOption preserveWorkingDir = app.Option( - $"--preserve-working-dir", LocalizableStrings.PreserveIntermediateWorkingDirOptionDescription, - CommandOptionType.NoValue); - - CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(app); - - List msbuildArgs = null; - app.OnExecute(() => + if (!result.HasOption("-e")) { - msbuildArgs = new List(); - - if (string.IsNullOrEmpty(projectArgument.Value())) - { - throw new InvalidOperationException(LocalizableStrings.SpecifyEntries); - } - - msbuildArgs.Add("/t:ComposeCache"); - msbuildArgs.Add(projectArgument.Value()); - - if (!string.IsNullOrEmpty(frameworkOption.Value())) - { - msbuildArgs.Add($"/p:TargetFramework={frameworkOption.Value()}"); - } - - if (!string.IsNullOrEmpty(runtimeOption.Value())) - { - msbuildArgs.Add($"/p:RuntimeIdentifier={runtimeOption.Value()}"); - } - - if (!string.IsNullOrEmpty(outputOption.Value())) - { - var outputPath = Path.GetFullPath(outputOption.Value()); - msbuildArgs.Add($"/p:ComposeDir={outputPath}"); - } - - if (!string.IsNullOrEmpty(fxOption.Value())) - { - msbuildArgs.Add($"/p:FX_Version={fxOption.Value()}"); - } - - if (!string.IsNullOrEmpty(workingDir.Value())) - { - msbuildArgs.Add($"/p:ComposeWorkingDir={workingDir.Value()}"); - } - - if (skipOptimizationOption.HasValue()) - { - msbuildArgs.Add($"/p:SkipOptimization={skipOptimizationOption.HasValue()}"); - } - - if (preserveWorkingDir.HasValue()) - { - msbuildArgs.Add($"/p:PreserveComposeWorkingDir={preserveWorkingDir.HasValue()}"); - } - - if (!string.IsNullOrEmpty(verbosityOption.Value())) - { - msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}"); - } - - msbuildArgs.AddRange(app.RemainingArguments); - - return 0; - }); - - int exitCode = app.Execute(args); - if (msbuildArgs == null) - { - throw new CommandCreationException(exitCode); + throw new InvalidOperationException(LocalizableStrings.SpecifyEntries); } + var msbuildArgs = msbuildArgs = new List(); + + msbuildArgs.Add("/t:ComposeCache"); + + msbuildArgs.AddRange(appliedBuildOptions.OptionValuesToBeForwarded()); + + msbuildArgs.AddRange(appliedBuildOptions.Arguments); + return new CacheCommand(msbuildArgs, msbuildPath); } From 1c25a17e0392e1fffb4f5618f0f691fe8f2406b7 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Thu, 9 Mar 2017 16:13:19 -0800 Subject: [PATCH 026/149] , -> ; --- src/dotnet/CommonOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index cfc1c1c70..5b14f424b 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -51,7 +51,7 @@ namespace Microsoft.DotNet.Cli Accept.ExactlyOneArgument .With(name: "CONFIGURATION") .WithSuggestionsFrom("DEBUG", "RELEASE") - .ForwardAs(o => $"/p:Configuration={o.Arguments.Single()}")), + .ForwardAs(o => $"/p:Configuration={o.Arguments.Single()}")); public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory())); From cb19d357d67124c7e47d23bc187123352e3f67d4 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Thu, 9 Mar 2017 16:17:15 -0800 Subject: [PATCH 027/149] Build issues --- src/dotnet/commands/dotnet-cache/CacheCommandParser.cs | 2 +- src/dotnet/commands/dotnet-cache/Program.cs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs b/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs index 580f0fb48..ef19f3f0a 100644 --- a/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs +++ b/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs @@ -3,7 +3,7 @@ using System.Linq; using Microsoft.DotNet.Cli.CommandLine; -using Microsoft.DotNet.Tools.Cache; +using LocalizableStrings = Microsoft.DotNet.Tools.Cache.LocalizableStrings; namespace Microsoft.DotNet.Cli { diff --git a/src/dotnet/commands/dotnet-cache/Program.cs b/src/dotnet/commands/dotnet-cache/Program.cs index d4325ab1a..1b1f75531 100644 --- a/src/dotnet/commands/dotnet-cache/Program.cs +++ b/src/dotnet/commands/dotnet-cache/Program.cs @@ -9,6 +9,7 @@ using Microsoft.DotNet.Cli; using System.Diagnostics; using System; using System.IO; +using Parser = Microsoft.DotNet.Cli.Parser; namespace Microsoft.DotNet.Tools.Cache { @@ -39,9 +40,7 @@ namespace Microsoft.DotNet.Tools.Cache { throw new InvalidOperationException(LocalizableStrings.SpecifyEntries); } - - var msbuildArgs = msbuildArgs = new List(); - + msbuildArgs.Add("/t:ComposeCache"); msbuildArgs.AddRange(appliedBuildOptions.OptionValuesToBeForwarded()); From 03544ad0cd7160c128ff296ee54ef7e9f8ce648f Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Thu, 9 Mar 2017 16:39:49 -0800 Subject: [PATCH 028/149] Build Unit Tests --- src/dotnet/commands/dotnet-build/Program.cs | 4 ++-- .../GivenDotnetBuildInvocation.cs | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/dotnet/commands/dotnet-build/Program.cs b/src/dotnet/commands/dotnet-build/Program.cs index c3e9d8a0f..77c2f0870 100644 --- a/src/dotnet/commands/dotnet-build/Program.cs +++ b/src/dotnet/commands/dotnet-build/Program.cs @@ -44,12 +44,12 @@ namespace Microsoft.DotNet.Tools.Build msbuildArgs.Add("/t:Build"); } - msbuildArgs.Add($"/clp:Summary"); - msbuildArgs.AddRange(appliedBuildOptions.OptionValuesToBeForwarded()); msbuildArgs.AddRange(appliedBuildOptions.Arguments); + msbuildArgs.Add($"/clp:Summary"); + return new BuildCommand(msbuildArgs, msbuildPath); } diff --git a/test/dotnet-msbuild.Tests/GivenDotnetBuildInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetBuildInvocation.cs index eb3b7256e..687b13f2e 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetBuildInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetBuildInvocation.cs @@ -18,16 +18,16 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [InlineData(new string[] { "--output", "foo" }, "/t:Build /p:OutputPath=foo")] [InlineData(new string[] { "-o", "foo1 foo2" }, "/t:Build \"/p:OutputPath=foo1 foo2\"")] [InlineData(new string[] { "--no-incremental" }, "/t:Rebuild")] - [InlineData(new string[] { "-f", "framework" }, "/t:Build /p:TargetFramework=framework")] - [InlineData(new string[] { "--framework", "framework" }, "/t:Build /p:TargetFramework=framework")] - [InlineData(new string[] { "-r", "runtime" }, "/t:Build /p:RuntimeIdentifier=runtime")] - [InlineData(new string[] { "--runtime", "runtime" }, "/t:Build /p:RuntimeIdentifier=runtime")] - [InlineData(new string[] { "-c", "configuration" }, "/t:Build /p:Configuration=configuration")] - [InlineData(new string[] { "--configuration", "configuration" }, "/t:Build /p:Configuration=configuration")] + [InlineData(new string[] { "-f", "tfm" }, "/t:Build /p:TargetFramework=tfm")] + [InlineData(new string[] { "--framework", "tfm" }, "/t:Build /p:TargetFramework=tfm")] + [InlineData(new string[] { "-r", "rid" }, "/t:Build /p:RuntimeIdentifier=rid")] + [InlineData(new string[] { "--runtime", "rid" }, "/t:Build /p:RuntimeIdentifier=rid")] + [InlineData(new string[] { "-c", "config" }, "/t:Build /p:Configuration=config")] + [InlineData(new string[] { "--configuration", "config" }, "/t:Build /p:Configuration=config")] [InlineData(new string[] { "--version-suffix", "mysuffix" }, "/t:Build /p:VersionSuffix=mysuffix")] [InlineData(new string[] { "--no-dependencies" }, "/t:Build /p:BuildProjectReferences=false")] - [InlineData(new string[] { "-v", "verbosity" }, "/t:Build /verbosity:verbosity")] - [InlineData(new string[] { "--verbosity", "verbosity" }, "/t:Build /verbosity:verbosity")] + [InlineData(new string[] { "-v", "diag" }, "/t:Build /verbosity:diag")] + [InlineData(new string[] { "--verbosity", "diag" }, "/t:Build /verbosity:diag")] [InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, "/t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag")] public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs) { From bbc23af13880bbd050b5dcce9d37625d2deeb211 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Thu, 9 Mar 2017 17:20:00 -0800 Subject: [PATCH 029/149] Fix failing Cache tests --- src/dotnet/commands/dotnet-cache/CacheCommandParser.cs | 4 ++-- src/dotnet/commands/dotnet-cache/Program.cs | 4 ++-- test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs b/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs index ef19f3f0a..ba92ef6fb 100644 --- a/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs +++ b/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs @@ -11,7 +11,7 @@ namespace Microsoft.DotNet.Cli { public static Command Cache() => Create.Command( - LocalizableStrings.AppFullName, + "cache", LocalizableStrings.AppDescription, Accept.ZeroOrMoreArguments, CommonOptions.HelpOption(), @@ -37,7 +37,7 @@ namespace Microsoft.DotNet.Cli .With(name: LocalizableStrings.OutputOption) .ForwardAs(o => $"/p:ComposeDir={o.Arguments.Single()}")), Create.Option( - "-w |--working-dir", + "-w|--working-dir", LocalizableStrings.IntermediateWorkingDirOptionDescription, Accept.ExactlyOneArgument .With(name: LocalizableStrings.IntermediateWorkingDirOption) diff --git a/src/dotnet/commands/dotnet-cache/Program.cs b/src/dotnet/commands/dotnet-cache/Program.cs index 1b1f75531..7994fdb00 100644 --- a/src/dotnet/commands/dotnet-cache/Program.cs +++ b/src/dotnet/commands/dotnet-cache/Program.cs @@ -36,11 +36,11 @@ namespace Microsoft.DotNet.Tools.Cache var appliedBuildOptions = result["dotnet"]["cache"]; - if (!result.HasOption("-e")) + if (!appliedBuildOptions.HasOption("-e")) { throw new InvalidOperationException(LocalizableStrings.SpecifyEntries); } - + msbuildArgs.Add("/t:ComposeCache"); msbuildArgs.AddRange(appliedBuildOptions.OptionValuesToBeForwarded()); diff --git a/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs index 2202ba2cd..d0bb45cbf 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs @@ -27,10 +27,10 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests } [Theory] - [InlineData(new string[] { "-f", "" }, @"/p:TargetFramework=")] - [InlineData(new string[] { "--framework", "" }, @"/p:TargetFramework=")] - [InlineData(new string[] { "-r", "" }, @"/p:RuntimeIdentifier=")] - [InlineData(new string[] { "--runtime", "" }, @"/p:RuntimeIdentifier=")] + [InlineData(new string[] { "-f", "" }, @"/p:TargetFramework=")] + [InlineData(new string[] { "--framework", "" }, @"/p:TargetFramework=")] + [InlineData(new string[] { "-r", "" }, @"/p:RuntimeIdentifier=")] + [InlineData(new string[] { "--runtime", "" }, @"/p:RuntimeIdentifier=")] public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs) { args = ArgsPrefix.Concat(args).ToArray(); From c68aba4f63b23a6dfd69342732b01fa85dd2094e Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Thu, 9 Mar 2017 17:52:17 -0800 Subject: [PATCH 030/149] Test Fix --- src/dotnet/commands/dotnet-build/Program.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/dotnet/commands/dotnet-build/Program.cs b/src/dotnet/commands/dotnet-build/Program.cs index 77c2f0870..1034c70ab 100644 --- a/src/dotnet/commands/dotnet-build/Program.cs +++ b/src/dotnet/commands/dotnet-build/Program.cs @@ -21,8 +21,6 @@ namespace Microsoft.DotNet.Tools.Build public static BuildCommand FromArgs(string[] args, string msbuildPath = null) { - DebugHelper.HandleDebugSwitch(ref args); - var msbuildArgs = new List(); var parser = Parser.Instance; @@ -35,7 +33,7 @@ namespace Microsoft.DotNet.Tools.Build var appliedBuildOptions = result["dotnet"]["build"]; - if (result.HasOption("--no-incremental")) + if (appliedBuildOptions.HasOption("--no-incremental")) { msbuildArgs.Add("/t:Rebuild"); } From ca9268c504401de420bd788826a47ba4aaa0338d Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Thu, 9 Mar 2017 18:16:20 -0800 Subject: [PATCH 031/149] Clean --- .../dotnet-clean/CleanCommandParser.cs | 30 ++++---- src/dotnet/commands/dotnet-clean/Program.cs | 75 +++---------------- 2 files changed, 25 insertions(+), 80 deletions(-) diff --git a/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs b/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs index dfdc5d1ac..6a2fcf2e9 100644 --- a/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs +++ b/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs @@ -1,27 +1,27 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Linq; using Microsoft.DotNet.Cli.CommandLine; +using LocalizableStrings = Microsoft.DotNet.Tools.Clean.LocalizableStrings; namespace Microsoft.DotNet.Cli { internal static class CleanCommandParser { public static Command Clean() => - Create.Command("clean", - ".NET Clean Command", - CommonOptions.HelpOption(), - Create.Option("-o|--output", "Directory in which the build outputs have been placed.", - Accept.ExactlyOneArgument - .With(name: "OUTPUT_DIR")), - Create.Option("-f|--framework", "Clean a specific framework.", - Accept.ExactlyOneArgument - .With(name: "FRAMEWORK") - .WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile())), - Create.Option("-c|--configuration", - "Clean a specific configuration.", - Accept.ExactlyOneArgument - .With(name: "CONFIGURATION") - .WithSuggestionsFrom("DEBUG", "RELEASE"))); + Create.Command( + "clean", + ".NET Clean Command", + Accept.ZeroOrMoreArguments, + CommonOptions.HelpOption(), + Create.Option("-o|--output", + "Directory in which the build outputs have been placed.", + Accept.ExactlyOneArgument + .With(name: "OUTPUT_DIR") + .ForwardAs(o => $"/p:OutputPath={o.Arguments.Single()}")), + CommonOptions.FrameworkOption(), + CommonOptions.ConfigurationOption(), + CommonOptions.VerbosityOption()); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-clean/Program.cs b/src/dotnet/commands/dotnet-clean/Program.cs index f76e25b84..3d9132ad5 100644 --- a/src/dotnet/commands/dotnet-clean/Program.cs +++ b/src/dotnet/commands/dotnet-clean/Program.cs @@ -19,78 +19,23 @@ namespace Microsoft.DotNet.Tools.Clean public static CleanCommand FromArgs(string[] args, string msbuildPath = null) { - DebugHelper.HandleDebugSwitch(ref args); + var msbuildArgs = new List(); - CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false) - { - Name = "dotnet clean", - FullName = LocalizableStrings.AppFullName, - Description = LocalizableStrings.AppDescription, - HandleRemainingArguments = true, - ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText - }; - app.HelpOption("-h|--help"); + var parser = Parser.Instance; - CommandArgument projectArgument = app.Argument( - $"<{LocalizableStrings.CmdArgProject}>", - LocalizableStrings.CmdArgProjDescription); + var result = parser.ParseFrom("dotnet clean", args); - CommandOption outputOption = app.Option( - $"-o|--output <{LocalizableStrings.CmdOutputDir}>", - LocalizableStrings.CmdOutputDirDescription, - CommandOptionType.SingleValue); - CommandOption frameworkOption = app.Option( - $"-f|--framework <{LocalizableStrings.CmdFramework}>", - LocalizableStrings.CmdFrameworkDescription, - CommandOptionType.SingleValue); - CommandOption configurationOption = app.Option( - $"-c|--configuration <{LocalizableStrings.CmdConfiguration}>", - LocalizableStrings.CmdConfigurationDescription, - CommandOptionType.SingleValue); - CommandOption verbosityOption = AddVerbosityOption(app); + Reporter.Output.WriteLine(result.Diagram()); - List msbuildArgs = null; - app.OnExecute(() => - { - msbuildArgs = new List(); + result.ShowHelpIfRequested(); - if (!string.IsNullOrEmpty(projectArgument.Value)) - { - msbuildArgs.Add(projectArgument.Value); - } + var parsedClean = result["dotnet"]["clean"]; + + msbuildArgs.Add("/t:Clean"); - msbuildArgs.Add("/t:Clean"); + msbuildArgs.AddRange(appliedBuildOptions.OptionValuesToBeForwarded()); - if (outputOption.HasValue()) - { - msbuildArgs.Add($"/p:OutputPath={outputOption.Value()}"); - } - - if (frameworkOption.HasValue()) - { - msbuildArgs.Add($"/p:TargetFramework={frameworkOption.Value()}"); - } - - if (configurationOption.HasValue()) - { - msbuildArgs.Add($"/p:Configuration={configurationOption.Value()}"); - } - - if (verbosityOption.HasValue()) - { - msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}"); - } - - msbuildArgs.AddRange(app.RemainingArguments); - - return 0; - }); - - int exitCode = app.Execute(args); - if (msbuildArgs == null) - { - throw new CommandCreationException(exitCode); - } + msbuildArgs.AddRange(parsedClean.Arguments); return new CleanCommand(msbuildArgs, msbuildPath); } From 706e34ad4776cb2742c726fac3bf4a58120a39f8 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Thu, 9 Mar 2017 18:16:26 -0800 Subject: [PATCH 032/149] Cache --- src/dotnet/commands/dotnet-cache/Program.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/dotnet/commands/dotnet-cache/Program.cs b/src/dotnet/commands/dotnet-cache/Program.cs index 7994fdb00..10a8f7a3c 100644 --- a/src/dotnet/commands/dotnet-cache/Program.cs +++ b/src/dotnet/commands/dotnet-cache/Program.cs @@ -22,8 +22,6 @@ namespace Microsoft.DotNet.Tools.Cache public static CacheCommand FromArgs(string[] args, string msbuildPath = null) { - DebugHelper.HandleDebugSwitch(ref args); - var msbuildArgs = new List(); var parser = Parser.Instance; From ba50d619d8181cc1998b3713ec248c304f2b506e Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Thu, 9 Mar 2017 18:44:48 -0800 Subject: [PATCH 033/149] Build fixes for clean & build --- src/dotnet/commands/dotnet-build/Program.cs | 2 -- src/dotnet/commands/dotnet-clean/Program.cs | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/dotnet/commands/dotnet-build/Program.cs b/src/dotnet/commands/dotnet-build/Program.cs index 1034c70ab..d2703cbcc 100644 --- a/src/dotnet/commands/dotnet-build/Program.cs +++ b/src/dotnet/commands/dotnet-build/Program.cs @@ -5,8 +5,6 @@ using System.Collections.Generic; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; -using System.Diagnostics; -using System; using Microsoft.DotNet.Cli; using Parser = Microsoft.DotNet.Cli.Parser; diff --git a/src/dotnet/commands/dotnet-clean/Program.cs b/src/dotnet/commands/dotnet-clean/Program.cs index 3d9132ad5..c1cad7780 100644 --- a/src/dotnet/commands/dotnet-clean/Program.cs +++ b/src/dotnet/commands/dotnet-clean/Program.cs @@ -6,7 +6,7 @@ using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; using Microsoft.DotNet.Cli; -using System.Diagnostics; +using Parser = Microsoft.DotNet.Cli.Parser; namespace Microsoft.DotNet.Tools.Clean { @@ -33,7 +33,7 @@ namespace Microsoft.DotNet.Tools.Clean msbuildArgs.Add("/t:Clean"); - msbuildArgs.AddRange(appliedBuildOptions.OptionValuesToBeForwarded()); + msbuildArgs.AddRange(parsedClean.OptionValuesToBeForwarded()); msbuildArgs.AddRange(parsedClean.Arguments); From fd6d499ba6253e280a6f21b80b8570e5dc4894f3 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Thu, 9 Mar 2017 18:45:11 -0800 Subject: [PATCH 034/149] dotnet-migrate --- src/dotnet/AppliedOptionExtensions.cs | 21 +++++ .../dotnet-migrate/MigrateCommandParser.cs | 53 ++++++++---- src/dotnet/commands/dotnet-migrate/Program.cs | 82 +++++++------------ 3 files changed, 85 insertions(+), 71 deletions(-) create mode 100644 src/dotnet/AppliedOptionExtensions.cs diff --git a/src/dotnet/AppliedOptionExtensions.cs b/src/dotnet/AppliedOptionExtensions.cs new file mode 100644 index 000000000..2aa2ff814 --- /dev/null +++ b/src/dotnet/AppliedOptionExtensions.cs @@ -0,0 +1,21 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Linq; +using Microsoft.DotNet.Cli.CommandLine; + +namespace Microsoft.DotNet.Cli +{ + public static class AppliedOptionExtensions + { + public static T ValueOrDefault(this AppliedOption parseResult, string alias) + { + return parseResult + .AppliedOptions + .Where(o => o.HasAlias(alias)) + .Select(o => o.Value()) + .SingleOrDefault(); + } + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs b/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs index 2f30281af..738a95110 100644 --- a/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs +++ b/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs @@ -1,29 +1,48 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Linq; using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Tools.Migrate; +using LocalizableStrings = Microsoft.DotNet.Tools.Migrate.LocalizableStrings; namespace Microsoft.DotNet.Cli { internal static class MigrateCommandParser { public static Command Migrate() => - Create.Command("migrate", - ".NET Migrate Command", - CommonOptions.HelpOption(), - Create.Option("-t|--template-file", - "Base MSBuild template to use for migrated app. The default is the project included in dotnet new."), - Create.Option("-v|--sdk-package-version", - "The version of the SDK package that will be referenced in the migrated app. The default is the version of the SDK in dotnet new."), - Create.Option("-x|--xproj-file", - "The path to the xproj file to use. Required when there is more than one xproj in a project directory."), - Create.Option("-s|--skip-project-references", - "Skip migrating project references. By default, project references are migrated recursively."), - Create.Option("-r|--report-file", - "Output migration report to the given file in addition to the console."), - Create.Option("--format-report-file-json", - "Output migration report file as json rather than user messages."), - Create.Option("--skip-backup", - "Skip moving project.json, global.json, and *.xproj to a `backup` directory after successful migration.")); + Create.Command( + "migrate", + ".NET Migrate Command", + Accept.ZeroOrOneArgument + .MaterializeAs(o => + { + return new MigrateCommand( + o.ValueOrDefault("--template-file"), + o.Arguments.FirstOrDefault(), + o.ValueOrDefault("--sdk-package-version"), + o.ValueOrDefault("--xproj-file"), + o.ValueOrDefault("--report-file"), + o.ValueOrDefault("--skip-project-references"), + o.ValueOrDefault("--format-report-file-json"), + o.ValueOrDefault("--skip-backup")); + }) + .With(name: LocalizableStrings.CmdProjectArgument, + description: LocalizableStrings.CmdProjectArgumentDescription), + CommonOptions.HelpOption(), + Create.Option("-t|--template-file", + LocalizableStrings.CmdTemplateDescription), + Create.Option("-v|--sdk-package-version", + LocalizableStrings.CmdVersionDescription), + Create.Option("-x|--xproj-file", + LocalizableStrings.CmdXprojFileDescription), + Create.Option("-s|--skip-project-references", + LocalizableStrings.CmdSkipProjectReferencesDescription), + Create.Option("-r|--report-file", + LocalizableStrings.CmdReportFileDescription), + Create.Option("--format-report-file-json", + LocalizableStrings.CmdReportOutputDescription), + Create.Option("--skip-backup", + LocalizableStrings.CmdSkipBackupDescription)); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-migrate/Program.cs b/src/dotnet/commands/dotnet-migrate/Program.cs index 177fb920f..7c0fcb635 100644 --- a/src/dotnet/commands/dotnet-migrate/Program.cs +++ b/src/dotnet/commands/dotnet-migrate/Program.cs @@ -2,13 +2,32 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Collections.Generic; +using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; +using Parser = Microsoft.DotNet.Cli.Parser; namespace Microsoft.DotNet.Tools.Migrate { public partial class MigrateCommand { + public static MigrateCommand FromArgs(string[] args, string msbuildPath = null) + { + var msbuildArgs = new List(); + + var parser = Parser.Instance; + + var result = parser.ParseFrom("dotnet migrate", args); + + Reporter.Output.WriteLine(result.Diagram()); + + result.ShowHelpIfRequested(); + + return result["dotnet"]["migrate"].Value(); + } + + public static int Run(string[] args) { @@ -19,64 +38,19 @@ namespace Microsoft.DotNet.Tools.Migrate DebugHelper.HandleDebugSwitch(ref args); - CommandLineApplication app = new CommandLineApplication(); - app.Name = "dotnet migrate"; - app.FullName = LocalizableStrings.AppFullName; - app.Description = LocalizableStrings.AppDescription; - app.HandleResponseFiles = true; - app.HelpOption("-h|--help"); - - CommandArgument projectArgument = app.Argument( - $"<{LocalizableStrings.CmdProjectArgument}>", - LocalizableStrings.CmdProjectArgumentDescription); - - CommandOption template = app.Option( - "-t|--template-file", - LocalizableStrings.CmdTemplateDescription, - CommandOptionType.SingleValue); - CommandOption sdkVersion = app.Option( - "-v|--sdk-package-version", - LocalizableStrings.CmdVersionDescription, - CommandOptionType.SingleValue); - CommandOption xprojFile = app.Option( - "-x|--xproj-file", - LocalizableStrings.CmdXprojFileDescription, - CommandOptionType.SingleValue); - CommandOption skipProjectReferences = app.Option( - "-s|--skip-project-references", - LocalizableStrings.CmdSkipProjectReferencesDescription, - CommandOptionType.BoolValue); - - CommandOption reportFile = app.Option( - "-r|--report-file", - LocalizableStrings.CmdReportFileDescription, - CommandOptionType.SingleValue); - CommandOption structuredReportOutput = app.Option( - "--format-report-file-json", - LocalizableStrings.CmdReportOutputDescription, - CommandOptionType.BoolValue); - CommandOption skipBackup = app.Option("--skip-backup", - LocalizableStrings.CmdSkipBackupDescription, - CommandOptionType.BoolValue); - - app.OnExecute(() => + MigrateCommand cmd; + try { - MigrateCommand migrateCommand = new MigrateCommand( - template.Value(), - projectArgument.Value, - sdkVersion.Value(), - xprojFile.Value(), - reportFile.Value(), - skipProjectReferences.BoolValue.HasValue ? skipProjectReferences.BoolValue.Value : false, - structuredReportOutput.BoolValue.HasValue ? structuredReportOutput.BoolValue.Value : false, - skipBackup.BoolValue.HasValue ? skipBackup.BoolValue.Value : false); - - return migrateCommand.Execute(); - }); + cmd = FromArgs(args); + } + catch (CommandCreationException e) + { + return e.ExitCode; + } try { - return app.Execute(args); + return cmd.Execute(); } catch (GracefulException e) { From 6429574fff991a9e6bdd9efc578aa41e29f580da Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 01:08:07 -0800 Subject: [PATCH 035/149] Fix verbosity tests --- test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs index 742baf6ba..461dcc16a 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetCleanInvocation.cs @@ -28,8 +28,8 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [InlineData(new string[] { "--framework", "" }, "/p:TargetFramework=")] [InlineData(new string[] { "-c", "" }, "/p:Configuration=")] [InlineData(new string[] { "--configuration", "" }, "/p:Configuration=")] - [InlineData(new string[] { "-v", "" }, "/verbosity:")] - [InlineData(new string[] { "--verbosity", "" }, "/verbosity:")] + [InlineData(new string[] { "-v", "diag" }, "/verbosity:diag")] + [InlineData(new string[] { "--verbosity", "diag" }, "/verbosity:diag")] public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs) { expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}"); From dc72b7ce92173f629668f87df6233a0ccd747198 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 01:08:19 -0800 Subject: [PATCH 036/149] Fix Clean ordering --- src/dotnet/commands/dotnet-clean/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dotnet/commands/dotnet-clean/Program.cs b/src/dotnet/commands/dotnet-clean/Program.cs index c1cad7780..5963d7048 100644 --- a/src/dotnet/commands/dotnet-clean/Program.cs +++ b/src/dotnet/commands/dotnet-clean/Program.cs @@ -30,13 +30,13 @@ namespace Microsoft.DotNet.Tools.Clean result.ShowHelpIfRequested(); var parsedClean = result["dotnet"]["clean"]; + + msbuildArgs.AddRange(parsedClean.Arguments); msbuildArgs.Add("/t:Clean"); msbuildArgs.AddRange(parsedClean.OptionValuesToBeForwarded()); - msbuildArgs.AddRange(parsedClean.Arguments); - return new CleanCommand(msbuildArgs, msbuildPath); } From 92245e4523db4026374bb6dce42757446efdec00 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 01:10:23 -0800 Subject: [PATCH 037/149] Centralize VersionSuffixOption --- src/dotnet/CommonOptions.cs | 8 ++++++++ src/dotnet/commands/dotnet-build/BuildCommandParser.cs | 7 +------ .../commands/dotnet-publish/PublishCommandParser.cs | 5 +---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index 5b14f424b..7b7fcf792 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -53,6 +53,14 @@ namespace Microsoft.DotNet.Cli .WithSuggestionsFrom("DEBUG", "RELEASE") .ForwardAs(o => $"/p:Configuration={o.Arguments.Single()}")); + public static Option VersionSuffixOption() => + Create.Option( + "--version-suffix", + "Defines the value for the $(VersionSuffix) property in the project.", + Accept.ExactlyOneArgument + .With(name: "VERSION_SUFFIX") + .ForwardAs(o => $"/p:VersionSuffix={o.Arguments.Single()}")); + public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory())); } diff --git a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs index 8394ce441..ab4fb3804 100644 --- a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs +++ b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs @@ -23,12 +23,7 @@ namespace Microsoft.DotNet.Cli CommonOptions.FrameworkOption(), CommonOptions.RuntimeOption(), CommonOptions.ConfigurationOption(), - Create.Option( - "--version-suffix", - "Defines the value for the $(VersionSuffix) property in the project", - Accept.ExactlyOneArgument - .With(name: "VERSION_SUFFIX") - .ForwardAs(o => $"/p:VersionSuffix={o.Arguments.Single()}")), + CommonOptions.VersionSuffixOption(), Create.Option( "--no-incremental", "Disables incremental build."), diff --git a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs index 895ea919b..87896968b 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs @@ -22,10 +22,7 @@ namespace Microsoft.DotNet.Cli .With(name: "OUTPUT_DIR") .ForwardAs(o => $"/p:PublishDir={o.Arguments.Single()}")), CommonOptions.ConfigurationOption(), - Create.Option("--version-suffix", "Defines the value for the $(VersionSuffix) property in the project.", - Accept.ExactlyOneArgument - .With(name: "VERSION_SUFFIX") - .ForwardAs(o => $"/p:VersionSuffix={o.Arguments.Single()}")), + CommonOptions.VersionSuffixOption(), Create.Option("--filter", "The XML file that contains the list of packages to be excluded from publish step.", Accept.ExactlyOneArgument .With(name: "PROFILE_XML") From 4912e4aa6ce3743d100ccd1c9474f3c8b7d25b14 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 01:11:07 -0800 Subject: [PATCH 038/149] Fix naming of BuildCommand.cs --- src/dotnet/commands/dotnet-build/{Program.cs => BuildCommand.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/dotnet/commands/dotnet-build/{Program.cs => BuildCommand.cs} (100%) diff --git a/src/dotnet/commands/dotnet-build/Program.cs b/src/dotnet/commands/dotnet-build/BuildCommand.cs similarity index 100% rename from src/dotnet/commands/dotnet-build/Program.cs rename to src/dotnet/commands/dotnet-build/BuildCommand.cs From 120d28a78dc66f770c4d798b82905cc3a37397c2 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 01:11:16 -0800 Subject: [PATCH 039/149] Migrate dotnet-pack --- .../commands/dotnet-pack/PackCommand.cs | 116 +++--------------- .../commands/dotnet-pack/PackCommandParser.cs | 54 ++++---- 2 files changed, 43 insertions(+), 127 deletions(-) diff --git a/src/dotnet/commands/dotnet-pack/PackCommand.cs b/src/dotnet/commands/dotnet-pack/PackCommand.cs index 31de05df5..2f09762e4 100644 --- a/src/dotnet/commands/dotnet-pack/PackCommand.cs +++ b/src/dotnet/commands/dotnet-pack/PackCommand.cs @@ -19,112 +19,26 @@ namespace Microsoft.DotNet.Tools.Pack public static PackCommand FromArgs(string[] args, string msbuildPath = null) { - DebugHelper.HandleDebugSwitch(ref args); + var msbuildArgs = new List(); - CommandLineApplication cmd = new CommandLineApplication(throwOnUnexpectedArg: false) + var parser = Parser.Instance; + + var result = parser.ParseFrom("dotnet pack", args); + + Reporter.Output.WriteLine(result.Diagram()); + + result.ShowHelpIfRequested(); + + var parsedPack = result["dotnet"]["pack"]; + + var msbuildArgs = new List() { - Name = "pack", - FullName = LocalizableStrings.AppFullName, - Description = LocalizableStrings.AppDescription, - HandleRemainingArguments = true, - ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText + "/t:pack" }; - cmd.HelpOption("-h|--help"); + msbuildArgs.AddRange(parsedPack.OptionValuesToBeForwarded()); - var output = cmd.Option( - $"-o|--output <{LocalizableStrings.CmdOutputDir}>", - LocalizableStrings.CmdOutputDirDescription, - CommandOptionType.SingleValue); - var noBuild = cmd.Option( - "--no-build", - LocalizableStrings.CmdNoBuildOptionDescription, - CommandOptionType.NoValue); - var includeSymbols = cmd.Option( - "--include-symbols", - LocalizableStrings.CmdIncludeSymbolsDescription, - CommandOptionType.NoValue); - var includeSource = cmd.Option( - "--include-source", - LocalizableStrings.CmdIncludeSourceDescription, - CommandOptionType.NoValue); - var configuration = cmd.Option( - $"-c|--configuration <{LocalizableStrings.CmdConfig}>", - LocalizableStrings.CmdConfigDescription, - CommandOptionType.SingleValue); - var versionSuffix = cmd.Option( - $"--version-suffix <{LocalizableStrings.CmdVersionSuffix}>", - LocalizableStrings.CmdVersionSuffixDescription, - CommandOptionType.SingleValue); - var serviceable = cmd.Option( - "-s|--serviceable", - LocalizableStrings.CmdServiceableDescription, - CommandOptionType.NoValue); - var argRoot = cmd.Argument( - $"<{LocalizableStrings.CmdArgumentProject}>", - LocalizableStrings.CmdArgumentDescription, - multipleValues:true); - CommandOption verbosityOption = AddVerbosityOption(cmd); - - List msbuildArgs = null; - cmd.OnExecute(() => - { - msbuildArgs = new List() - { - "/t:pack" - }; - - if (noBuild.HasValue()) - { - msbuildArgs.Add($"/p:NoBuild=true"); - } - - if (includeSymbols.HasValue()) - { - msbuildArgs.Add($"/p:IncludeSymbols=true"); - } - - if (includeSource.HasValue()) - { - msbuildArgs.Add($"/p:IncludeSource=true"); - } - - if (output.HasValue()) - { - msbuildArgs.Add($"/p:PackageOutputPath={output.Value()}"); - } - - if (configuration.HasValue()) - { - msbuildArgs.Add($"/p:Configuration={configuration.Value()}"); - } - - if (versionSuffix.HasValue()) - { - msbuildArgs.Add($"/p:VersionSuffix={versionSuffix.Value()}"); - } - - if (serviceable.HasValue()) - { - msbuildArgs.Add($"/p:Serviceable=true"); - } - - if (verbosityOption.HasValue()) - { - msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}"); - } - - msbuildArgs.AddRange(argRoot.Values); - - msbuildArgs.AddRange(cmd.RemainingArguments); - return 0; - }); - - int exitCode = cmd.Execute(args); - if (msbuildArgs == null) - { - throw new CommandCreationException(exitCode); - } + msbuildArgs.AddRange(parsedPack.Arguments); return new PackCommand(msbuildArgs, msbuildPath); } diff --git a/src/dotnet/commands/dotnet-pack/PackCommandParser.cs b/src/dotnet/commands/dotnet-pack/PackCommandParser.cs index 1f36cd9a3..ec210cb24 100644 --- a/src/dotnet/commands/dotnet-pack/PackCommandParser.cs +++ b/src/dotnet/commands/dotnet-pack/PackCommandParser.cs @@ -1,38 +1,40 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Linq; using Microsoft.DotNet.Cli.CommandLine; +using LocalizableStrings = Microsoft.DotNet.Tools.Pack.LocalizableStrings; namespace Microsoft.DotNet.Cli { internal static class PackCommandParser { public static Command Pack() => - Create.Command("pack", - ".NET Core NuGet Package Packer", - CommonOptions.HelpOption(), - Create.Option("-o|--output", - "Directory in which to place built packages.", - Accept.ExactlyOneArgument - .With(name: "OUTPUT_DIR")), - Create.Option("--no-build", - "Skip building the project prior to packing. By default, the project will be built."), - Create.Option("--include-symbols", - "Include packages with symbols in addition to regular packages in output directory."), - Create.Option("--include-source", - "Include PDBs and source files. Source files go into the src folder in the resulting nuget package"), - Create.Option("-c|--configuration", - "Configuration to use for building the project. Default for most projects is \"Debug\".", - Accept.ExactlyOneArgument - .With(name: "CONFIGURATION") - .WithSuggestionsFrom("DEBUG", - "RELEASE")), - Create.Option("--version-suffix", - "Defines the value for the $(VersionSuffix) property in the project.", - Accept.ExactlyOneArgument - .With(name: "VERSION_SUFFIX")), - Create.Option("-s|--serviceable", - "Set the serviceable flag in the package. For more information, please see https://aka.ms/nupkgservicing."), - CommonOptions.VerbosityOption()); + Create.Command( + "pack", + LocalizableStrings.AppDescription, + Accept.ZeroOrMoreArguments, + CommonOptions.HelpOption(), + Create.Option( + "-o|--output", + LocalizableStrings.CmdOutputDirDescription, + Accept.ExactlyOneArgument + .With(name: LocalizableStrings.CmdOutputDir) + .ForwardAs(o => $"/p:PackageOutputPath={o.Arguments.Single()}")), + Create.Option("--no-build", + LocalizableStrings.CmdNoBuildOptionDescription, + Accept.NoArguments.ForwardAs("/p:NoBuild=true")), + Create.Option("--include-symbols", + LocalizableStrings.CmdIncludeSymbolsDescription, + Accept.NoArguments.ForwardAs("/p:IncludeSymbols=true")), + Create.Option("--include-source", + LocalizableStrings.CmdIncludeSourceDescription, + Accept.NoArguments.ForwardAs("/p:IncludeSource=true")), + CommonOptions.ConfigurationOption(), + CommonOptions.VersionSuffixOption(), + Create.Option("-s|--serviceable", + LocalizableStrings.CmdServiceableDescription, + Accept.NoArguments.ForwardAs("/p:Serviceable=true")), + CommonOptions.VerbosityOption()); } } \ No newline at end of file From 4149150accb5aa126479d4b3595971f9e8fcb50e Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 01:13:13 -0800 Subject: [PATCH 040/149] Resolve Parser ambiguity --- src/dotnet/commands/dotnet-pack/PackCommand.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/dotnet/commands/dotnet-pack/PackCommand.cs b/src/dotnet/commands/dotnet-pack/PackCommand.cs index 2f09762e4..00b8e2d68 100644 --- a/src/dotnet/commands/dotnet-pack/PackCommand.cs +++ b/src/dotnet/commands/dotnet-pack/PackCommand.cs @@ -7,6 +7,7 @@ using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; using Microsoft.DotNet.Cli; using System.Diagnostics; +using Parser = Microsoft.DotNet.Cli.Parser; namespace Microsoft.DotNet.Tools.Pack { @@ -19,8 +20,6 @@ namespace Microsoft.DotNet.Tools.Pack public static PackCommand FromArgs(string[] args, string msbuildPath = null) { - var msbuildArgs = new List(); - var parser = Parser.Instance; var result = parser.ParseFrom("dotnet pack", args); From 071f4dc697b5c090ed32ec924232271c14dcb26d Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 09:08:01 -0800 Subject: [PATCH 041/149] Convert Run --- .../commands/dotnet-build/BuildCommand.cs | 1 + src/dotnet/commands/dotnet-run/Program.cs | 55 +++++++++---------- .../commands/dotnet-run/RunCommandParser.cs | 37 ++++++++----- 3 files changed, 50 insertions(+), 43 deletions(-) diff --git a/src/dotnet/commands/dotnet-build/BuildCommand.cs b/src/dotnet/commands/dotnet-build/BuildCommand.cs index d2703cbcc..3ecd6eeba 100644 --- a/src/dotnet/commands/dotnet-build/BuildCommand.cs +++ b/src/dotnet/commands/dotnet-build/BuildCommand.cs @@ -54,6 +54,7 @@ namespace Microsoft.DotNet.Tools.Build DebugHelper.HandleDebugSwitch(ref args); BuildCommand cmd; + try { cmd = FromArgs(args); diff --git a/src/dotnet/commands/dotnet-run/Program.cs b/src/dotnet/commands/dotnet-run/Program.cs index f608695eb..a795b455b 100644 --- a/src/dotnet/commands/dotnet-run/Program.cs +++ b/src/dotnet/commands/dotnet-run/Program.cs @@ -4,47 +4,42 @@ using System; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.Cli; +using Parser = Microsoft.DotNet.Cli.Parser; namespace Microsoft.DotNet.Tools.Run { public partial class RunCommand { + public static RunCommand FromArgs(string[] args, string msbuildPath = null) + { + var parser = Parser.Instance; + + var result = parser.ParseFrom("dotnet run", args); + + Reporter.Output.WriteLine(result.Diagram()); + + result.ShowHelpIfRequested(); + + return result["dotnet"]["run"].Value(); + } + public static int Run(string[] args) { DebugHelper.HandleDebugSwitch(ref args); - CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false); - app.Name = "dotnet run"; - app.FullName = LocalizableStrings.AppFullName; - app.Description = LocalizableStrings.AppDescription; - app.HandleResponseFiles = true; - app.AllowArgumentSeparator = true; - app.ArgumentSeparatorHelpText = LocalizableStrings.RunCommandAdditionalArgsHelpText; - app.HelpOption("-h|--help"); - - CommandOption configuration = app.Option( - "-c|--configuration", LocalizableStrings.CommandOptionConfigurationDescription, - CommandOptionType.SingleValue); - CommandOption framework = app.Option( - $"-f|--framework <{LocalizableStrings.CommandOptionFramework}>", LocalizableStrings.CommandOptionFrameworkDescription, - CommandOptionType.SingleValue); - CommandOption project = app.Option( - "-p|--project", LocalizableStrings.CommandOptionProjectDescription, - CommandOptionType.SingleValue); - - app.OnExecute(() => + RunCommand cmd; + + try { - RunCommand runCmd = new RunCommand(); + cmd = FromArgs(args); + } + catch (CommandCreationException e) + { + return e.ExitCode; + } - runCmd.Configuration = configuration.Value(); - runCmd.Framework = framework.Value(); - runCmd.Project = project.Value(); - runCmd.Args = app.RemainingArguments; - - return runCmd.Start(); - }); - - return app.Execute(args); + return cmd.Start(); } } } diff --git a/src/dotnet/commands/dotnet-run/RunCommandParser.cs b/src/dotnet/commands/dotnet-run/RunCommandParser.cs index dba6ec68a..2569579ab 100644 --- a/src/dotnet/commands/dotnet-run/RunCommandParser.cs +++ b/src/dotnet/commands/dotnet-run/RunCommandParser.cs @@ -1,25 +1,36 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Collections.Generic; using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Tools.Run; +using LocalizableStrings = Microsoft.DotNet.Tools.Run.LocalizableStrings; namespace Microsoft.DotNet.Cli { internal static class RunCommandParser { public static Command Run() => - Create.Command("run", - ".NET Run Command", - CommonOptions.HelpOption(), - Create.Option("-c|--configuration", - @"Configuration to use for building the project. Default for most projects is ""Debug"".", - Accept.ExactlyOneArgument - .WithSuggestionsFrom("DEBUG", "RELEASE")), - Create.Option("-f|--framework", - "Build and run the app using the specified framework. The framework has to be specified in the project file.", - Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile)), - Create.Option("-p|--project", - "The path to the project file to run (defaults to the current directory if there is only one project).", - Accept.ZeroOrOneArgument)); + Create.Command( + "run", + ".NET Run Command", + Accept.ZeroOrMoreArguments + .MaterializeAs(o => + { + return new RunCommand() + { + Configuration = o.ValueOrDefault("--configuration"), + Framework = o.ValueOrDefault("--framework"), + Project = o.ValueOrDefault("--project"), + Args = (IReadOnlyList)o.Arguments + }; + }), + CommonOptions.HelpOption(), + CommonOptions.ConfigurationOption(), + CommonOptions.FrameworkOption(), + Create.Option( + "-p|--project", + LocalizableStrings.CommandOptionProjectDescription, + Accept.ExactlyOneArgument)); } } \ No newline at end of file From 9a1483d3b61aa63775f514ff0d5f39d8420e4ff7 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 09:08:25 -0800 Subject: [PATCH 042/149] Fix tests --- .../GivenDotnetPackInvocation.cs | 14 +++---- .../GivenDotnetPublishInvocation.cs | 38 +++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs index 34624df92..4f452abb5 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs @@ -15,18 +15,18 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [Theory] [InlineData(new string[] { }, "")] - [InlineData(new string[] { "-o", "" }, "/p:PackageOutputPath=")] - [InlineData(new string[] { "--output", "" }, "/p:PackageOutputPath=")] + [InlineData(new string[] { "-o", "" }, "/p:PackageOutputPath=")] + [InlineData(new string[] { "--output", "" }, "/p:PackageOutputPath=")] [InlineData(new string[] { "--no-build" }, "/p:NoBuild=true")] [InlineData(new string[] { "--include-symbols" }, "/p:IncludeSymbols=true")] [InlineData(new string[] { "--include-source" }, "/p:IncludeSource=true")] - [InlineData(new string[] { "-c", "" }, "/p:Configuration=")] - [InlineData(new string[] { "--configuration", "" }, "/p:Configuration=")] - [InlineData(new string[] { "--version-suffix", "" }, "/p:VersionSuffix=")] + [InlineData(new string[] { "-c", "" }, "/p:Configuration=")] + [InlineData(new string[] { "--configuration", "" }, "/p:Configuration=")] + [InlineData(new string[] { "--version-suffix", "" }, "/p:VersionSuffix=")] [InlineData(new string[] { "-s" }, "/p:Serviceable=true")] [InlineData(new string[] { "--serviceable" }, "/p:Serviceable=true")] - [InlineData(new string[] { "-v", "" }, @"/verbosity:")] - [InlineData(new string[] { "--verbosity", "" }, @"/verbosity:")] + [InlineData(new string[] { "-v", "" }, "/verbosity:")] + [InlineData(new string[] { "--verbosity", "" }, "/verbosity:")] [InlineData(new string[] { "" }, "")] public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs) { diff --git a/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs index 547ecb10e..c48a21c08 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs @@ -24,16 +24,16 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [Theory] [InlineData(new string[] { }, "")] - [InlineData(new string[] { "-f", "" }, "/p:TargetFramework=")] - [InlineData(new string[] { "--framework", "" }, "/p:TargetFramework=")] - [InlineData(new string[] { "-r", "" }, "/p:RuntimeIdentifier=")] - [InlineData(new string[] { "--runtime", "" }, "/p:RuntimeIdentifier=")] - [InlineData(new string[] { "-o", "" }, "/p:PublishDir=")] - [InlineData(new string[] { "--output", "" }, "/p:PublishDir=")] - [InlineData(new string[] { "-c", "" }, "/p:Configuration=")] - [InlineData(new string[] { "--configuration", "" }, "/p:Configuration=")] - [InlineData(new string[] { "--version-suffix", "" }, "/p:VersionSuffix=")] - [InlineData(new string[] { "--filter", "" }, "/p:FilterProjectFiles=")] + [InlineData(new string[] { "-f", "" }, "/p:TargetFramework=")] + [InlineData(new string[] { "--framework", "" }, "/p:TargetFramework=")] + [InlineData(new string[] { "-r", "" }, "/p:RuntimeIdentifier=")] + [InlineData(new string[] { "--runtime", "" }, "/p:RuntimeIdentifier=")] + [InlineData(new string[] { "-o", "" }, "/p:PublishDir=")] + [InlineData(new string[] { "--output", "" }, "/p:PublishDir=")] + [InlineData(new string[] { "-c", "" }, "/p:Configuration=")] + [InlineData(new string[] { "--configuration", "" }, "/p:Configuration=")] + [InlineData(new string[] { "--version-suffix", "" }, "/p:VersionSuffix=")] + [InlineData(new string[] { "--filter", "" }, "/p:FilterProjectFiles=")] [InlineData(new string[] { "-v", "minimal" }, "/verbosity:minimal")] [InlineData(new string[] { "--verbosity", "minimal" }, "/verbosity:minimal")] [InlineData(new string[] { "" }, "")] @@ -51,15 +51,15 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [Theory] [InlineData(new string[] { }, "")] - [InlineData(new string[] { "-f", "" }, "/p:TargetFramework=")] - [InlineData(new string[] { "--framework", "" }, "/p:TargetFramework=")] - [InlineData(new string[] { "-r", "" }, "/p:RuntimeIdentifier=")] - [InlineData(new string[] { "--runtime", "" }, "/p:RuntimeIdentifier=")] - [InlineData(new string[] { "-o", "" }, "/p:PublishDir=")] - [InlineData(new string[] { "--output", "" }, "/p:PublishDir=")] - [InlineData(new string[] { "-c", "" }, "/p:Configuration=")] - [InlineData(new string[] { "--configuration", "" }, "/p:Configuration=")] - [InlineData(new string[] { "--version-suffix", "" }, "/p:VersionSuffix=")] + [InlineData(new string[] { "-f", "" }, "/p:TargetFramework=")] + [InlineData(new string[] { "--framework", "" }, "/p:TargetFramework=")] + [InlineData(new string[] { "-r", "" }, "/p:RuntimeIdentifier=")] + [InlineData(new string[] { "--runtime", "" }, "/p:RuntimeIdentifier=")] + [InlineData(new string[] { "-o", "" }, "/p:PublishDir=")] + [InlineData(new string[] { "--output", "" }, "/p:PublishDir=")] + [InlineData(new string[] { "-c", "" }, "/p:Configuration=")] + [InlineData(new string[] { "--configuration", "" }, "/p:Configuration=")] + [InlineData(new string[] { "--version-suffix", "" }, "/p:VersionSuffix=")] [InlineData(new string[] { "--filter", "" }, "/p:FilterProjectFiles=")] [InlineData(new string[] { "-v", "minimal" }, "/verbosity:minimal")] [InlineData(new string[] { "--verbosity", "minimal" }, "/verbosity:minimal")] From a751673172b894b554db5da3f38e7732836eade9 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 10:12:37 -0800 Subject: [PATCH 043/149] Fix test bugs --- test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs | 4 ++-- test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs index 4f452abb5..aba1b15a6 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetPackInvocation.cs @@ -25,8 +25,8 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [InlineData(new string[] { "--version-suffix", "" }, "/p:VersionSuffix=")] [InlineData(new string[] { "-s" }, "/p:Serviceable=true")] [InlineData(new string[] { "--serviceable" }, "/p:Serviceable=true")] - [InlineData(new string[] { "-v", "" }, "/verbosity:")] - [InlineData(new string[] { "--verbosity", "" }, "/verbosity:")] + [InlineData(new string[] { "-v", "diag" }, "/verbosity:diag")] + [InlineData(new string[] { "--verbosity", "diag" }, "/verbosity:diag")] [InlineData(new string[] { "" }, "")] public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs) { diff --git a/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs index c48a21c08..f577f827f 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs @@ -28,7 +28,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [InlineData(new string[] { "--framework", "" }, "/p:TargetFramework=")] [InlineData(new string[] { "-r", "" }, "/p:RuntimeIdentifier=")] [InlineData(new string[] { "--runtime", "" }, "/p:RuntimeIdentifier=")] - [InlineData(new string[] { "-o", "" }, "/p:PublishDir=")] + [InlineData(new string[] { "-o", "" }, "/p:PublishDir=")] [InlineData(new string[] { "--output", "" }, "/p:PublishDir=")] [InlineData(new string[] { "-c", "" }, "/p:Configuration=")] [InlineData(new string[] { "--configuration", "" }, "/p:Configuration=")] @@ -60,7 +60,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [InlineData(new string[] { "-c", "" }, "/p:Configuration=")] [InlineData(new string[] { "--configuration", "" }, "/p:Configuration=")] [InlineData(new string[] { "--version-suffix", "" }, "/p:VersionSuffix=")] - [InlineData(new string[] { "--filter", "" }, "/p:FilterProjectFiles=")] + [InlineData(new string[] { "--filter", "" }, "/p:FilterProjectFiles=")] [InlineData(new string[] { "-v", "minimal" }, "/verbosity:minimal")] [InlineData(new string[] { "--verbosity", "minimal" }, "/verbosity:minimal")] public void OptionForwardingIsCorrect(string[] args, string expectedAdditionalArgs) From 940dd6863a07487c8a56d4a0b824ae8e66395dfe Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 10:13:11 -0800 Subject: [PATCH 044/149] move `dotnet-run` --- src/dotnet/AppliedOptionExtensions.cs | 11 ++++++++++- src/dotnet/ArgumentForwardingExtensions.cs | 9 +++++++-- .../commands/dotnet-run/RunCommandParser.cs | 18 +++++++++--------- .../ArgumentForwardingExtensionsTests.cs | 2 +- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/dotnet/AppliedOptionExtensions.cs b/src/dotnet/AppliedOptionExtensions.cs index 2aa2ff814..8158c0f83 100644 --- a/src/dotnet/AppliedOptionExtensions.cs +++ b/src/dotnet/AppliedOptionExtensions.cs @@ -17,5 +17,14 @@ namespace Microsoft.DotNet.Cli .Select(o => o.Value()) .SingleOrDefault(); } + + public static string SingleArgumentOrDefault(this AppliedOption parseResult, string alias) + { + return parseResult + .AppliedOptions + .Where(o => o.HasAlias(alias)) + .Select(o => o.Arguments.Single()) + .SingleOrDefault(); + } } -} \ No newline at end of file +} diff --git a/src/dotnet/ArgumentForwardingExtensions.cs b/src/dotnet/ArgumentForwardingExtensions.cs index 5e49a4c99..ac8aa9c4a 100644 --- a/src/dotnet/ArgumentForwardingExtensions.cs +++ b/src/dotnet/ArgumentForwardingExtensions.cs @@ -38,7 +38,12 @@ namespace Microsoft.DotNet.Cli _value = value; } - public override string ToString() => _value; + public override string ToString() => _value; + + public static explicit operator string(ForwardedArgument argument) + { + return argument.ToString(); + } } } -} \ No newline at end of file +} diff --git a/src/dotnet/commands/dotnet-run/RunCommandParser.cs b/src/dotnet/commands/dotnet-run/RunCommandParser.cs index 2569579ab..9ba56f953 100644 --- a/src/dotnet/commands/dotnet-run/RunCommandParser.cs +++ b/src/dotnet/commands/dotnet-run/RunCommandParser.cs @@ -15,16 +15,16 @@ namespace Microsoft.DotNet.Cli "run", ".NET Run Command", Accept.ZeroOrMoreArguments - .MaterializeAs(o => - { - return new RunCommand() + .MaterializeAs(o => { - Configuration = o.ValueOrDefault("--configuration"), - Framework = o.ValueOrDefault("--framework"), - Project = o.ValueOrDefault("--project"), - Args = (IReadOnlyList)o.Arguments - }; - }), + return new RunCommand() + { + Configuration = o.SingleArgumentOrDefault("--configuration"), + Framework = o.SingleArgumentOrDefault("--framework"), + Project = o.SingleArgumentOrDefault("--project"), + Args = (IReadOnlyList)o.Arguments + }; + }), CommonOptions.HelpOption(), CommonOptions.ConfigurationOption(), CommonOptions.FrameworkOption(), diff --git a/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs b/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs index c40b07888..943a04360 100644 --- a/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs +++ b/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs @@ -64,4 +64,4 @@ namespace Microsoft.DotNet.Tests.ParserTests .BeEquivalentTo("one"); } } -} \ No newline at end of file +} From 1f5be51955ec072978d8922438dc0873874d37b8 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 10:17:10 -0800 Subject: [PATCH 045/149] relocate suggest.cs --- src/dotnet/{ => commands}/dotnet-complete/Suggest.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/dotnet/{ => commands}/dotnet-complete/Suggest.cs (100%) diff --git a/src/dotnet/dotnet-complete/Suggest.cs b/src/dotnet/commands/dotnet-complete/Suggest.cs similarity index 100% rename from src/dotnet/dotnet-complete/Suggest.cs rename to src/dotnet/commands/dotnet-complete/Suggest.cs From d3319adb59e3dc869b7da8c6864cae68c06705f6 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Fri, 10 Mar 2017 10:34:25 -0800 Subject: [PATCH 046/149] fix merge error --- src/dotnet/commands/dotnet-publish/Program.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/dotnet/commands/dotnet-publish/Program.cs b/src/dotnet/commands/dotnet-publish/Program.cs index 36ed70db3..6ba893605 100644 --- a/src/dotnet/commands/dotnet-publish/Program.cs +++ b/src/dotnet/commands/dotnet-publish/Program.cs @@ -35,9 +35,6 @@ namespace Microsoft.DotNet.Tools.Publish var appliedPublishOption = result["dotnet"]["publish"]; - CommandOption filterProjOption = app.Option( - $"--filter <{LocalizableStrings.FilterProjOption}>", LocalizableStrings.FilterProjOptionDescription, - CommandOptionType.MultipleValue); msbuildArgs.AddRange(appliedPublishOption.OptionValuesToBeForwarded()); msbuildArgs.AddRange(appliedPublishOption.Arguments); From 482f1b555bbf5ecb9fa1ef0c0bfa57bbc5ef3435 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 10:43:01 -0800 Subject: [PATCH 047/149] missing peren --- src/dotnet/commands/dotnet-cache/CacheCommandParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs b/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs index 9f71278f7..b314e6c37 100644 --- a/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs +++ b/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs @@ -29,7 +29,7 @@ namespace Microsoft.DotNet.Cli var additionalProjects = string.Join("%3B", o.Arguments.Skip(1)); return $"{materializedString} /p:AdditionalProjects={additionalProjects}"; - }), + })), CommonOptions.FrameworkOption(), Create.Option( "--framework-version", From 18a2b95dec042c95c7c3f90627d492490ac929be Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 13:18:14 -0800 Subject: [PATCH 048/149] Initial port of dotnet test --- .../dotnet-test/LocalizableStrings.cs | 2 + src/dotnet/commands/dotnet-test/Program.cs | 311 +++--------------- .../commands/dotnet-test/TestCommandParser.cs | 127 ++++--- 3 files changed, 136 insertions(+), 304 deletions(-) diff --git a/src/dotnet/commands/dotnet-test/LocalizableStrings.cs b/src/dotnet/commands/dotnet-test/LocalizableStrings.cs index def80ab0a..04b4402ab 100644 --- a/src/dotnet/commands/dotnet-test/LocalizableStrings.cs +++ b/src/dotnet/commands/dotnet-test/LocalizableStrings.cs @@ -32,6 +32,8 @@ namespace Microsoft.DotNet.Tools.Test public const string CmdTestAdapterPathDescription = @"Use custom adapters from the given path in the test run. Example: --test-adapter-path "; + public const string CmdTestAdapterPath = "PATH_TO_ADAPTER"; + public const string CmdLoggerOption = "LoggerUri/FriendlyName"; public const string CmdLoggerDescription = @"Specify a logger for test results. diff --git a/src/dotnet/commands/dotnet-test/Program.cs b/src/dotnet/commands/dotnet-test/Program.cs index 89d0c3595..8796495f8 100644 --- a/src/dotnet/commands/dotnet-test/Program.cs +++ b/src/dotnet/commands/dotnet-test/Program.cs @@ -2,283 +2,74 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; using System.Collections.Generic; +using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; -using System.IO; -using System.Text.RegularExpressions; +using Parser = Microsoft.DotNet.Cli.Parser; namespace Microsoft.DotNet.Tools.Test { - public class TestCommand + public class TestCommand : MSBuildForwardingApp { + public TestCommand(IEnumerable msbuildArgs, string msbuildPath = null) + : base(msbuildArgs, msbuildPath) + { + } + + public static TestCommand FromArgs(string[] args, string msbuildPath=null) + { + var msbuildArgs = new List() + { + "/t:VSTest", + "/v:quiet", + "/nologo" + }; + + var parser = Parser.Instance; + + var result = parser.ParseFrom("dotnet test", args); + + Reporter.Output.WriteLine(result.Diagram()); + + result.ShowHelpIfRequested(); + + var parsedTest = result["dotnet"]["test"]; + + var runSettingsOptions = + result.UnparsedTokens + .Select(t => GetSemiColonEsacpedstring(t)); + + if (runSettingsOptions.Any()) + { + var runSettingsArg = string.Join(";", runSettingsOptions); + + msbuildArgs.Add($"/p:VSTestCLIRunSettings=\"{runSettingsArg}\""); + } + + return new TestCommand(msbuildArgs, msbuildPath); + } + public static int Run(string[] args) { DebugHelper.HandleDebugSwitch(ref args); - var cmd = new CommandLineApplication(throwOnUnexpectedArg: false) + TestCommand cmd; + + try { - Name = "dotnet test", - FullName = LocalizableStrings.AppFullName, - Description = LocalizableStrings.AppDescription, - HandleRemainingArguments = true, - ArgumentSeparatorHelpText = LocalizableStrings.RunSettingsArgsHelpText - }; - - cmd.HelpOption("-h|--help"); - - var argRoot = cmd.Argument( - $"<{LocalizableStrings.CmdArgProject}>", - LocalizableStrings.CmdArgDescription, - multipleValues: false); - - var settingOption = cmd.Option( - $"-s|--settings <{LocalizableStrings.CmdSettingsFile}>", - LocalizableStrings.CmdSettingsDescription, - CommandOptionType.SingleValue); - - var listTestsOption = cmd.Option( - "-t|--list-tests", - LocalizableStrings.CmdListTestsDescription, - CommandOptionType.NoValue); - - var testCaseFilterOption = cmd.Option( - $"--filter <{LocalizableStrings.CmdTestCaseFilterExpression}>", - LocalizableStrings.CmdTestCaseFilterDescription, - CommandOptionType.SingleValue); - - var testAdapterPathOption = cmd.Option( - "-a|--test-adapter-path", - LocalizableStrings.CmdTestAdapterPathDescription, - CommandOptionType.SingleValue); - - var loggerOption = cmd.Option( - $"-l|--logger <{LocalizableStrings.CmdLoggerOption}>", - LocalizableStrings.CmdLoggerDescription, - CommandOptionType.SingleValue); - - var configurationOption = cmd.Option( - $"-c|--configuration <{LocalizableStrings.CmdConfiguration}>", - LocalizableStrings.CmdConfigDescription, - CommandOptionType.SingleValue); - - var frameworkOption = cmd.Option( - $"-f|--framework <{LocalizableStrings.CmdFramework}>", - LocalizableStrings.CmdFrameworkDescription, - CommandOptionType.SingleValue); - - var outputOption = cmd.Option( - $"-o|--output <{LocalizableStrings.CmdOutputDir}>", - LocalizableStrings.CmdOutputDescription, - CommandOptionType.SingleValue); - - var diagOption = cmd.Option( - $"-d|--diag <{LocalizableStrings.CmdPathToLogFile}>", - LocalizableStrings.CmdPathTologFileDescription, - CommandOptionType.SingleValue); - - var noBuildtOption = cmd.Option( - "--no-build", - LocalizableStrings.CmdNoBuildDescription, - CommandOptionType.NoValue); - - CommandOption verbosityOption = MSBuildForwardingApp.AddVerbosityOption(cmd); - - cmd.OnExecute(() => - { - var msbuildArgs = new List() - { - "/t:VSTest" - }; - - msbuildArgs.Add("/nologo"); - - if (settingOption.HasValue()) - { - msbuildArgs.Add($"/p:VSTestSetting={settingOption.Value()}"); - } - - if (listTestsOption.HasValue()) - { - msbuildArgs.Add($"/p:VSTestListTests=true"); - } - - if (testCaseFilterOption.HasValue()) - { - msbuildArgs.Add($"/p:VSTestTestCaseFilter={testCaseFilterOption.Value()}"); - } - - if (testAdapterPathOption.HasValue()) - { - msbuildArgs.Add($"/p:VSTestTestAdapterPath={testAdapterPathOption.Value()}"); - } - - if (loggerOption.HasValue()) - { - msbuildArgs.Add($"/p:VSTestLogger={string.Join(";", GetSemiColonEscapedArgs(loggerOption.Values))}"); - } - - if (configurationOption.HasValue()) - { - msbuildArgs.Add($"/p:Configuration={configurationOption.Value()}"); - } - - if (frameworkOption.HasValue()) - { - msbuildArgs.Add($"/p:TargetFramework={frameworkOption.Value()}"); - } - - if (outputOption.HasValue()) - { - msbuildArgs.Add($"/p:OutputPath={outputOption.Value()}"); - } - - if (diagOption.HasValue()) - { - msbuildArgs.Add($"/p:VSTestDiag={diagOption.Value()}"); - } - - if (noBuildtOption.HasValue()) - { - msbuildArgs.Add($"/p:VSTestNoBuild=true"); - } - - if (verbosityOption.HasValue()) - { - msbuildArgs.Add($"/verbosity:{verbosityOption.Value()}"); - } - else - { - msbuildArgs.Add("/verbosity:quiet"); - } - - string defaultproject = GetSingleTestProjectToRunTestIfNotProvided(argRoot.Value, cmd.RemainingArguments); - - if (!string.IsNullOrEmpty(defaultproject)) - { - msbuildArgs.Add(defaultproject); - } - - if (!string.IsNullOrEmpty(argRoot.Value)) - { - msbuildArgs.Add(argRoot.Value); - } - - // Get runsetings options specified after -- - if (cmd.RemainingArguments != null && cmd.RemainingArguments.Count > 0) - { - var runSettingsOptions = GetRunSettingsOptions(cmd.RemainingArguments); - msbuildArgs.Add(string.Format("/p:VSTestCLIRunSettings=\"{0}\"", string.Join(";", runSettingsOptions))); - } - - // Add remaining arguments that the parser did not understand, - msbuildArgs.AddRange(cmd.RemainingArguments); - - return new MSBuildForwardingApp(msbuildArgs).Execute(); - }); - - return cmd.Execute(args); - } - - private static string GetSingleTestProjectToRunTestIfNotProvided(string args, List remainingArguments) - { - string result = string.Empty; - int projectFound = NumberOfTestProjectInRemainingArgs(remainingArguments) + NumberOfTestProjectInArgsRoot(args); - - if (projectFound > 1) - { - throw new GracefulException( - $"Specify a single project file to run tests from."); + cmd = FromArgs(args); } - else if (projectFound == 0) + catch (CommandCreationException e) { - result = GetDefaultTestProject(); + return e.ExitCode; } - return result; - } - - private static int NumberOfTestProjectInArgsRoot(string args) - { - Regex pattern = new Regex(@"^.*\..*proj$"); - - if (!string.IsNullOrEmpty(args)) - { - return pattern.IsMatch(args) ? 1 : 0; - } - - return 0; - } - - private static int NumberOfTestProjectInRemainingArgs(List remainingArguments) - { - int count = 0; - if (remainingArguments.Count != 0) - { - Regex pattern = new Regex(@"^.*\..*proj$"); - - foreach (var x in remainingArguments) - { - if (pattern.IsMatch(x)) - { - count++; - } - } - } - - return count; - } - - private static string GetDefaultTestProject() - { - string directory = Directory.GetCurrentDirectory(); - string[] projectFiles = Directory.GetFiles(directory, "*.*proj"); - - if (projectFiles.Length == 0) - { - throw new GracefulException( - $"Couldn't find a project to run test from. Ensure a project exists in {directory}." + Environment.NewLine + - "Or pass the path to the project"); - } - else if (projectFiles.Length > 1) - { - throw new GracefulException( - $"Specify which project file to use because this '{directory}' contains more than one project file."); - } - - return projectFiles[0]; - } - - private static string[] GetRunSettingsOptions(List remainingArgs) - { - List runsettingsArgs = new List(); - List argsToRemove = new List(); - - bool readRunSettings = false; - foreach (string arg in remainingArgs) - { - if (!readRunSettings) - { - if (arg.Equals("--")) - { - readRunSettings = true; - argsToRemove.Add(arg); - } - - continue; - } - - runsettingsArgs.Add(GetSemiColonEsacpedstring(arg)); - argsToRemove.Add(arg); - } - - foreach (string arg in argsToRemove) - { - remainingArgs.Remove(arg); - } - - return runsettingsArgs.ToArray(); + return cmd.Execute(); } private static string GetSemiColonEsacpedstring(string arg) diff --git a/src/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/dotnet/commands/dotnet-test/TestCommandParser.cs index 2340ee4b3..dd2d14690 100644 --- a/src/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -1,54 +1,93 @@ +using System.Collections.Generic; using System.Linq; using Microsoft.DotNet.Cli.CommandLine; +using LocalizableStrings = Microsoft.DotNet.Tools.Test.LocalizableStrings; namespace Microsoft.DotNet.Cli { internal static class TestCommandParser { public static Command Test() => - Create.Command("test", - ".NET Test Driver", - Create.Option("-h|--help", - "Show help information"), - Create.Option("-s|--settings", - "Settings to use when running tests.", - Accept.ExactlyOneArgument - .With(name: "SETTINGS_FILE")), - Create.Option("-t|--list-tests", - "Lists discovered tests"), - Create.Option("--filter", - @"Run tests that match the given expression. - Examples: - Run tests with priority set to 1: --filter ""Priority = 1"" - Run a test with the specified full name: --filter ""FullyQualifiedName=Namespace.ClassName.MethodName"" - Run tests that contain the specified name: --filter ""FullyQualifiedName~Namespace.Class"" - More info on filtering support: https://aka.ms/vstest-filtering", - Accept.ExactlyOneArgument - .With(name: "EXPRESSION")), - Create.Option("-a|--test-adapter-path", - "Use custom adapters from the given path in the test run.\r\n Example: --test-adapter-path "), - Create.Option("-l|--logger", - "Specify a logger for test results.\r\n Example: --logger \"trx[;LogFileName=]\"", - Accept.ExactlyOneArgument - .With(name: "LoggerUri/FriendlyName")), - Create.Option("-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", - Accept.ExactlyOneArgument - .With(name: "CONFIGURATION") - .WithSuggestionsFrom("DEBUG", "RELEASE")), - Create.Option("-f|--framework", - "Looks for test binaries for a specific framework", - Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) - .With(name: "FRAMEWORK")), - Create.Option("-o|--output", - "Directory in which to find the binaries to be run", - Accept.ExactlyOneArgument - .With(name: "OUTPUT_DIR")), - Create.Option("-d|--diag", - "Enable verbose logs for test platform.\r\n Logs are written to the provided file.", - Accept.ExactlyOneArgument - .With(name: "PATH_TO_FILE")), - Create.Option("--no-build", - "Do not build project before testing."), - CommonOptions.VerbosityOption()); + Create.Command( + "test", + ".NET Test Driver", + CommonOptions.HelpOption(), + Create.Option( + "-s|--settings", + LocalizableStrings.CmdSettingsDescription, + Accept.ExactlyOneArgument + .With(name: LocalizableStrings.CmdSettingsFile) + .ForwardAs(o => $"/p:VSTestSetting={o.Arguments.Single()}")), + Create.Option( + "-t|--list-tests", + LocalizableStrings.CmdListTestsDescription, + Accept.NoArguments + .ForwardAs(o => "/p:VSTestListTests=true")), + Create.Option( + "--filter", + LocalizableStrings.CmdTestCaseFilterDescription, + Accept.ExactlyOneArgument + .With(name: LocalizableStrings.CmdTestCaseFilterExpression) + .ForwardAs(o => $"/p:VSTestTestCaseFilter={o.Arguments.Single()}")), + Create.Option( + "-a|--test-adapter-path", + LocalizableStrings.CmdTestAdapterPathDescription, + Accept.ExactlyOneArgument + .With(name: LocalizableStrings.CmdTestAdapterPath) + .ForwardAs(o => $"/p:VSTestTestAdapterPath={o.Arguments.Single()}")), + Create.Option( + "-l|--logger", + LocalizableStrings.CmdLoggerDescription, + Accept.ExactlyOneArgument + .With(name: LocalizableStrings.CmdLoggerOption) + .ForwardAs(o => + { + var loggersString = string.Join(";", GetSemiColonEscapedArgs(o.Arguments)); + + return $"/p:VSTestLogger={loggersString}"; + })), + CommonOptions.ConfigurationOption(), + CommonOptions.FrameworkOption(), + Create.Option( + "-o|--output", + LocalizableStrings.CmdOutputDescription, + Accept.ExactlyOneArgument + .With(name: LocalizableStrings.CmdOutputDir) + .ForwardAs(o => $"/p:OutputPath={o.Arguments.Single()}")), + Create.Option( + "-d|--diag", + LocalizableStrings.CmdPathTologFileDescription, + Accept.ExactlyOneArgument + .With(name: LocalizableStrings.CmdPathToLogFile) + .ForwardAs(o => $"/p:VSTestDiag={o.Arguments.Single()}")), + Create.Option( + "--no-build", + LocalizableStrings.CmdNoBuildDescription, + Accept.NoArguments + .ForwardAs(o => "/p:VSTestNoBuild=true")), + CommonOptions.VerbosityOption()); + + private static string GetSemiColonEsacpedstring(string arg) + { + if (arg.IndexOf(";") != -1) + { + return arg.Replace(";", "%3b"); + } + + return arg; + } + + private static string[] GetSemiColonEscapedArgs(IReadOnlyCollection args) + { + int counter = 0; + string[] array = new string[args.Count]; + + foreach (string arg in args) + { + array[counter++] = GetSemiColonEsacpedstring(arg); + } + + return array; + } } } \ No newline at end of file From e1568bbc1ee8af6d98dae0a1d52230ba87ba3a60 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 13:36:18 -0800 Subject: [PATCH 049/149] Re-enable localizable strings --- .../dotnet-build/BuildCommandParser.cs | 11 ++++---- .../dotnet-build/LocalizableStrings.cs | 21 --------------- .../dotnet-cache/LocalizableStrings.cs | 8 ------ .../dotnet-clean/CleanCommandParser.cs | 6 ++--- .../dotnet-clean/LocalizableStrings.cs | 12 --------- .../dotnet-pack/LocalizableStrings.cs | 8 ------ .../dotnet-publish/LocalizableStrings.cs | 16 ----------- .../dotnet-publish/PublishCommandParser.cs | 24 ++++++++++------- .../dotnet-restore/RestoreCommandParser.cs | 27 ++++++++++--------- .../commands/dotnet-run/LocalizableStrings.cs | 6 ----- .../commands/dotnet-run/RunCommandParser.cs | 2 +- 11 files changed, 38 insertions(+), 103 deletions(-) diff --git a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs index ab4fb3804..2b072c9bc 100644 --- a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs +++ b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs @@ -3,6 +3,7 @@ using System.Linq; using Microsoft.DotNet.Cli.CommandLine; +using LocalizableStrings = Microsoft.DotNet.Tools.Build.LocalizableStrings; namespace Microsoft.DotNet.Cli { @@ -11,14 +12,14 @@ namespace Microsoft.DotNet.Cli public static Command Build() => Create.Command( "build", - ".NET Builder", + LocalizableStrings.AppFullName, Accept.ZeroOrMoreArguments, CommonOptions.HelpOption(), Create.Option( "-o|--output", - "Output directory in which to place built artifacts.", + LocalizableStrings.OutputOptionDescription, Accept.ExactlyOneArgument - .With(name: "OUTPUT_DIR") + .With(name: LocalizableStrings.OutputOptionName) .ForwardAs(o => $"/p:OutputPath={o.Arguments.Single()}")), CommonOptions.FrameworkOption(), CommonOptions.RuntimeOption(), @@ -26,10 +27,10 @@ namespace Microsoft.DotNet.Cli CommonOptions.VersionSuffixOption(), Create.Option( "--no-incremental", - "Disables incremental build."), + LocalizableStrings.NoIncrementialOptionDescription), Create.Option( "--no-dependencies", - "Set this flag to ignore project-to-project references and only build the root project", + LocalizableStrings.NoDependenciesOptionDescription, Accept.NoArguments .ForwardAs("/p:BuildProjectReferences=false")), CommonOptions.VerbosityOption()); diff --git a/src/dotnet/commands/dotnet-build/LocalizableStrings.cs b/src/dotnet/commands/dotnet-build/LocalizableStrings.cs index d1f1537e5..61fe7574c 100644 --- a/src/dotnet/commands/dotnet-build/LocalizableStrings.cs +++ b/src/dotnet/commands/dotnet-build/LocalizableStrings.cs @@ -9,14 +9,6 @@ namespace Microsoft.DotNet.Tools.Build public const string AppFullName = ".NET Builder"; - public const string ConfigurationOptionDescription = "Configuration to use for building the project. Default for most projects is \"Debug\"."; - - public const string ConfigurationOptionName = "CONFIGURATION"; - - public const string FrameworkOptionDescription = "Target framework to build for. The target framework has to be specified in the project file."; - - public const string FrameworkOptionName = "FRAMEWORK"; - public const string NoDependenciesOptionDescription = "Set this flag to ignore project-to-project references and only build the root project"; public const string NoIncrementialOptionDescription = "Disables incremental build."; @@ -24,18 +16,5 @@ namespace Microsoft.DotNet.Tools.Build public const string OutputOptionDescription = "Output directory in which to place built artifacts."; public const string OutputOptionName = "OUTPUT_DIR"; - - public const string ProjectArgumentDescription = "The MSBuild project file to build. If a project file is not specified, MSBuild searches the current working directory for a file that has a file extension that ends in `proj` and uses that file."; - - public const string ProjectArgumentValueName = "PROJECT"; - - public const string RuntimeOptionDescription = "Target runtime to build for. The default is to build a portable application."; - - public const string RuntimeOptionName = "RUNTIME_IDENTIFIER"; - - public const string VersionSuffixOptionDescription = "Defines the value for the $(VersionSuffix) property in the project"; - - public const string VersionSuffixOptionName = "VERSION_SUFFIX"; - } } diff --git a/src/dotnet/commands/dotnet-cache/LocalizableStrings.cs b/src/dotnet/commands/dotnet-cache/LocalizableStrings.cs index 9596af025..156440ca6 100644 --- a/src/dotnet/commands/dotnet-cache/LocalizableStrings.cs +++ b/src/dotnet/commands/dotnet-cache/LocalizableStrings.cs @@ -13,14 +13,6 @@ namespace Microsoft.DotNet.Tools.Cache public const string ProjectEntryDescription = "The XML file that contains the list of packages to be cached."; - public const string FrameworkOption = "FRAMEWORK"; - - public const string FrameworkOptionDescription = "Target framework for which to cache for."; - - public const string RuntimeOption = "RUNTIME_IDENTIFIER"; - - public const string RuntimeOptionDescription = "Target runtime to cache for."; - public const string OutputOption = "OUTPUT_DIR"; public const string OutputOptionDescription = "Output directory in which to cache the given assemblies."; diff --git a/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs b/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs index 6a2fcf2e9..fdbf7d9df 100644 --- a/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs +++ b/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs @@ -12,13 +12,13 @@ namespace Microsoft.DotNet.Cli public static Command Clean() => Create.Command( "clean", - ".NET Clean Command", + LocalizableStrings.AppFullName, Accept.ZeroOrMoreArguments, CommonOptions.HelpOption(), Create.Option("-o|--output", - "Directory in which the build outputs have been placed.", + LocalizableStrings.CmdOutputDirDescription, Accept.ExactlyOneArgument - .With(name: "OUTPUT_DIR") + .With(name: LocalizableStrings.CmdOutputDir) .ForwardAs(o => $"/p:OutputPath={o.Arguments.Single()}")), CommonOptions.FrameworkOption(), CommonOptions.ConfigurationOption(), diff --git a/src/dotnet/commands/dotnet-clean/LocalizableStrings.cs b/src/dotnet/commands/dotnet-clean/LocalizableStrings.cs index 0d5a95f84..8cd76c8a9 100644 --- a/src/dotnet/commands/dotnet-clean/LocalizableStrings.cs +++ b/src/dotnet/commands/dotnet-clean/LocalizableStrings.cs @@ -9,20 +9,8 @@ namespace Microsoft.DotNet.Tools.Clean public const string AppDescription = "Command to clean previously generated build outputs."; - public const string CmdArgProject = "PROJECT"; - - public const string CmdArgProjDescription= "The MSBuild project file to build. If a project file is not specified, MSBuild searches the current working directory for a file that has a file extension that ends in `proj` and uses that file."; - public const string CmdOutputDir = "OUTPUT_DIR"; public const string CmdOutputDirDescription = "Directory in which the build outputs have been placed."; - - public const string CmdFramework = "FRAMEWORK"; - - public const string CmdFrameworkDescription = "Clean a specific framework."; - - public const string CmdConfiguration = "CONFIGURATION"; - - public const string CmdConfigurationDescription = "Clean a specific configuration."; } } diff --git a/src/dotnet/commands/dotnet-pack/LocalizableStrings.cs b/src/dotnet/commands/dotnet-pack/LocalizableStrings.cs index 542fc129b..28d37315d 100644 --- a/src/dotnet/commands/dotnet-pack/LocalizableStrings.cs +++ b/src/dotnet/commands/dotnet-pack/LocalizableStrings.cs @@ -19,14 +19,6 @@ namespace Microsoft.DotNet.Tools.Pack public const string CmdIncludeSourceDescription = "Include PDBs and source files. Source files go into the src folder in the resulting nuget package"; - public const string CmdConfig = "CONFIGURATION"; - - public const string CmdConfigDescription = "Configuration to use for building the project. Default for most projects is \"Debug\"."; - - public const string CmdVersionSuffix = "VERSION_SUFFIX"; - - public const string CmdVersionSuffixDescription = "Defines the value for the $(VersionSuffix) property in the project."; - public const string CmdServiceableDescription = "Set the serviceable flag in the package. For more information, please see https://aka.ms/nupkgservicing."; public const string CmdArgumentProject = "PROJECT"; diff --git a/src/dotnet/commands/dotnet-publish/LocalizableStrings.cs b/src/dotnet/commands/dotnet-publish/LocalizableStrings.cs index 6b47683bb..2a119fb04 100644 --- a/src/dotnet/commands/dotnet-publish/LocalizableStrings.cs +++ b/src/dotnet/commands/dotnet-publish/LocalizableStrings.cs @@ -9,30 +9,14 @@ namespace Microsoft.DotNet.Tools.Publish public const string AppDescription = "Publisher for the .NET Platform"; - public const string ProjectArgument = "PROJECT"; - - public const string ProjectArgDescription = "The MSBuild project file to publish. If a project file is not specified, MSBuild searches the current working directory for a file that has a file extension that ends in `proj` and uses that file."; - public const string FrameworkOption = "FRAMEWORK"; public const string FrameworkOptionDescription = "Target framework to publish for. The target framework has to be specified in the project file."; - public const string RuntimeOption = "RUNTIME_IDENTIFIER"; - - public const string RuntimeOptionDescription = "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app."; - public const string OutputOption = "OUTPUT_DIR"; public const string OutputOptionDescription = "Output directory in which to place the published artifacts."; - public const string ConfigurationOption = "CONFIGURATION"; - - public const string ConfigurationOptionDescription = "Configuration to use for building the project. Default for most projects is \"Debug\"."; - - public const string VersionSuffixOption = "VERSION_SUFFIX"; - - public const string VersionSuffixOptionDescription = "Defines the value for the $(VersionSuffix) property in the project."; - public const string FilterProjOption = "profile.xml"; public const string FilterProjOptionDescription = "The XML file that contains the list of packages to be excluded from publish step."; diff --git a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs index 87896968b..ae44f327e 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs @@ -3,6 +3,7 @@ using System.Linq; using Microsoft.DotNet.Cli.CommandLine; +using LocalizableStrings = Microsoft.DotNet.Tools.Publish.LocalizableStrings; namespace Microsoft.DotNet.Cli { @@ -11,22 +12,25 @@ namespace Microsoft.DotNet.Cli public static Command Publish() => Create.Command( "publish", - ".NET Publisher", + LocalizableStrings.AppFullName, Accept.ZeroOrMoreArguments, CommonOptions.HelpOption(), CommonOptions.FrameworkOption(), CommonOptions.RuntimeOption(), - Create.Option("-o|--output", - "Output directory in which to place the published artifacts.", - Accept.ExactlyOneArgument - .With(name: "OUTPUT_DIR") - .ForwardAs(o => $"/p:PublishDir={o.Arguments.Single()}")), + Create.Option( + "-o|--output", + LocalizableStrings.OutputOptionDescription, + Accept.ExactlyOneArgument + .With(name: LocalizableStrings.OutputOption) + .ForwardAs(o => $"/p:PublishDir={o.Arguments.Single()}")), CommonOptions.ConfigurationOption(), CommonOptions.VersionSuffixOption(), - Create.Option("--filter", "The XML file that contains the list of packages to be excluded from publish step.", - Accept.ExactlyOneArgument - .With(name: "PROFILE_XML") - .ForwardAs(o => $"/p:FilterProjectFiles={o.Arguments.Single()}")), + Create.Option( + "--filter", + LocalizableStrings.FilterProjOptionDescription, + Accept.ExactlyOneArgument + .With(name: LocalizableStrings.FilterProjOption) + .ForwardAs(o => $"/p:FilterProjectFiles={o.Arguments.Single()}")), CommonOptions.VerbosityOption()); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs b/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs index 39ae995cb..130ac0aaf 100644 --- a/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs +++ b/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs @@ -3,6 +3,7 @@ using System.Linq; using Microsoft.DotNet.Cli.CommandLine; +using LocalizableStrings = Microsoft.DotNet.Tools.Restore.LocalizableStrings; namespace Microsoft.DotNet.Cli { @@ -11,52 +12,52 @@ namespace Microsoft.DotNet.Cli public static Command Restore() => Create.Command( "restore", - ".NET dependency restorer", + LocalizableStrings.AppFullName, Accept.ZeroOrMoreArguments, CommonOptions.HelpOption(), Create.Option( "-s|--source", - "Specifies a NuGet package source to use during the restore.", + LocalizableStrings.CmdSourceOptionDescription, Accept.OneOrMoreArguments - .With(name: "SOURCE") + .With(name: LocalizableStrings.CmdSourceOption) .ForwardAs(o => $"/p:RestoreSources={string.Join("%3B", o.Arguments)}")), Create.Option( "-r|--runtime", - "Target runtime to restore packages for.", + LocalizableStrings.CmdRuntimeOptionDescription, Accept.OneOrMoreArguments .WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile()) - .With(name: "RUNTIME_IDENTIFIER") + .With(name: LocalizableStrings.CmdRuntimeOption) .ForwardAs(o => $"/p:RuntimeIdentifiers={string.Join("%3B", o.Arguments)}")), Create.Option( "--packages", - "Directory to install packages in.", + LocalizableStrings.CmdPackagesOptionDescription, Accept.ExactlyOneArgument - .With(name: "PACKAGES_DIRECTORY") + .With(name: LocalizableStrings.CmdPackagesOption) .ForwardAs(o => $"/p:RestorePackagesPath={o.Arguments.Single()}")), Create.Option( "--disable-parallel", - "Disables restoring multiple projects in parallel.", + LocalizableStrings.CmdDisableParallelOptionDescription, Accept.NoArguments .ForwardAs("/p:RestoreDisableParallel=true")), Create.Option( "--configfile", - "The NuGet configuration file to use.", + LocalizableStrings.CmdConfigFileOptionDescription, Accept.ExactlyOneArgument - .With(name: "FILE") + .With(name: LocalizableStrings.CmdConfigFileOption) .ForwardAs(o => $"/p:RestoreConfigFile={o.Arguments.Single()}")), Create.Option( "--no-cache", - "Do not cache packages and http requests.", + LocalizableStrings.CmdNoCacheOptionDescription, Accept.NoArguments .ForwardAs("/p:RestoreNoCache=true")), Create.Option( "--ignore-failed-sources", - "Treat package source failures as warnings.", + LocalizableStrings.CmdIgnoreFailedSourcesOptionDescription, Accept.NoArguments .ForwardAs("/p:RestoreIgnoreFailedSources=true")), Create.Option( "--no-dependencies", - "Set this flag to ignore project to project references and only restore the root project", + LocalizableStrings.CmdNoDependenciesOptionDescription, Accept.NoArguments .ForwardAs("/p:RestoreRecursive=false")), CommonOptions.VerbosityOption()); diff --git a/src/dotnet/commands/dotnet-run/LocalizableStrings.cs b/src/dotnet/commands/dotnet-run/LocalizableStrings.cs index 6ecf87779..9c5d8e022 100644 --- a/src/dotnet/commands/dotnet-run/LocalizableStrings.cs +++ b/src/dotnet/commands/dotnet-run/LocalizableStrings.cs @@ -9,12 +9,6 @@ namespace Microsoft.DotNet.Tools.Run public const string AppDescription = "Command used to run .NET apps"; - public const string CommandOptionConfigurationDescription = "Configuration to use for building the project. Default for most projects is \"Debug\"."; - - public const string CommandOptionFramework = "FRAMEWORK"; - - public const string CommandOptionFrameworkDescription = "Build and run the app using the specified framework. The framework has to be specified in the project file. "; - public const string CommandOptionProjectDescription = "The path to the project file to run (defaults to the current directory if there is only one project)."; public const string RunCommandException = "The build failed. Please fix the build errors and run again."; diff --git a/src/dotnet/commands/dotnet-run/RunCommandParser.cs b/src/dotnet/commands/dotnet-run/RunCommandParser.cs index 9ba56f953..fdb848468 100644 --- a/src/dotnet/commands/dotnet-run/RunCommandParser.cs +++ b/src/dotnet/commands/dotnet-run/RunCommandParser.cs @@ -13,7 +13,7 @@ namespace Microsoft.DotNet.Cli public static Command Run() => Create.Command( "run", - ".NET Run Command", + LocalizableStrings.AppFullName, Accept.ZeroOrMoreArguments .MaterializeAs(o => { From df3c08b6454b2cf5c766e5aed94eba8c038fb375 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 13:49:49 -0800 Subject: [PATCH 050/149] Pass through test options to msbuild --- build/Test.targets | 1 - src/dotnet/commands/dotnet-restore/Program.cs | 6 +++--- src/dotnet/commands/dotnet-test/Program.cs | 6 +++++- src/dotnet/commands/dotnet-test/TestCommandParser.cs | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/build/Test.targets b/build/Test.targets index 9eca40552..4fadf70e4 100644 --- a/build/Test.targets +++ b/build/Test.targets @@ -13,7 +13,6 @@ - diff --git a/src/dotnet/commands/dotnet-restore/Program.cs b/src/dotnet/commands/dotnet-restore/Program.cs index 537f9a0c9..1d34a40e1 100644 --- a/src/dotnet/commands/dotnet-restore/Program.cs +++ b/src/dotnet/commands/dotnet-restore/Program.cs @@ -33,7 +33,7 @@ namespace Microsoft.DotNet.Tools.Restore result.ShowHelpIfRequested(); - var restore = result["dotnet"]["restore"]; + var parsedRestore = result["dotnet"]["restore"]; var msbuildArgs = new List { @@ -42,9 +42,9 @@ namespace Microsoft.DotNet.Tools.Restore "/ConsoleLoggerParameters:Verbosity=Minimal" }; - msbuildArgs.AddRange(restore.OptionValuesToBeForwarded()); + msbuildArgs.AddRange(parsedRestore.OptionValuesToBeForwarded()); - msbuildArgs.AddRange(restore.Arguments); + msbuildArgs.AddRange(parsedRestore.Arguments); return new RestoreCommand(msbuildArgs, msbuildPath); } diff --git a/src/dotnet/commands/dotnet-test/Program.cs b/src/dotnet/commands/dotnet-test/Program.cs index 8796495f8..7c0bff1b7 100644 --- a/src/dotnet/commands/dotnet-test/Program.cs +++ b/src/dotnet/commands/dotnet-test/Program.cs @@ -2,10 +2,10 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; -using System.Collections.Generic; using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; @@ -40,6 +40,10 @@ namespace Microsoft.DotNet.Tools.Test var parsedTest = result["dotnet"]["test"]; + msbuildArgs.AddRange(parsedTest.OptionValuesToBeForwarded()); + + msbuildArgs.AddRange(parsedTest.Arguments); + var runSettingsOptions = result.UnparsedTokens .Select(t => GetSemiColonEsacpedstring(t)); diff --git a/src/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/dotnet/commands/dotnet-test/TestCommandParser.cs index dd2d14690..3ba133a82 100644 --- a/src/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -10,7 +10,8 @@ namespace Microsoft.DotNet.Cli public static Command Test() => Create.Command( "test", - ".NET Test Driver", + LocalizableStrings.AppFullName, + Accept.ZeroOrMoreArguments, CommonOptions.HelpOption(), Create.Option( "-s|--settings", From 659744d83d131ed314da735ea900d580a6c3ade9 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 14:00:26 -0800 Subject: [PATCH 051/149] Fix build --- build_projects/dotnet-cli-build/DotNetTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_projects/dotnet-cli-build/DotNetTest.cs b/build_projects/dotnet-cli-build/DotNetTest.cs index 6ed55055c..735356771 100644 --- a/build_projects/dotnet-cli-build/DotNetTest.cs +++ b/build_projects/dotnet-cli-build/DotNetTest.cs @@ -37,7 +37,7 @@ namespace Microsoft.DotNet.Cli.Build { if (!string.IsNullOrEmpty(Logger)) { - return $"--logger:{Logger}"; + return $"--logger {Logger}"; } return null; From a3f536c2488eea7161bf496c9691a13bdd498885 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Fri, 10 Mar 2017 16:43:44 -0800 Subject: [PATCH 052/149] move subcommands to new parser --- src/Microsoft.DotNet.Cli.Utils/PathUtility.cs | 7 +- src/dotnet/CommandBase.cs | 10 ++ src/dotnet/DotNetSubCommandBase.cs | 16 --- src/dotnet/DotNetTopLevelCommandBase.cs | 51 ++----- src/dotnet/ParseResultExtensions.cs | 4 +- src/dotnet/Program.cs | 2 +- .../commands/dotnet-add/AddCommandParser.cs | 71 +++++----- src/dotnet/commands/dotnet-add/Program.cs | 23 +++- .../dotnet-add/dotnet-add-package/Program.cs | 127 +++++------------- .../dotnet-add-reference/Program.cs | 78 +++++------ .../dotnet-complete/CompleteCommandParser.cs | 3 +- src/dotnet/commands/dotnet-list/Program.cs | 10 +- .../dotnet-list-reference/Program.cs | 34 ++--- src/dotnet/commands/dotnet-remove/Program.cs | 12 +- .../dotnet-remove-package/Program.cs | 58 ++++---- .../dotnet-remove-reference/Program.cs | 48 +++---- src/dotnet/commands/dotnet-sln/Program.cs | 14 +- src/dotnet/commands/dotnet-sln/add/Program.cs | 49 +++---- .../commands/dotnet-sln/list/Program.cs | 29 ++-- .../commands/dotnet-sln/remove/Program.cs | 56 ++++---- 20 files changed, 307 insertions(+), 395 deletions(-) create mode 100644 src/dotnet/CommandBase.cs delete mode 100644 src/dotnet/DotNetSubCommandBase.cs diff --git a/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs b/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs index 6e970a835..74d418ffa 100644 --- a/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs +++ b/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs @@ -313,9 +313,12 @@ namespace Microsoft.DotNet.Tools.Common return Path.GetFullPath(path); } - public static void EnsureAllPathsExist(List paths, string pathDoesNotExistLocalizedFormatString) + public static void EnsureAllPathsExist( + IReadOnlyCollection paths, + string pathDoesNotExistLocalizedFormatString) { var notExisting = new List(); + foreach (var p in paths) { if (!File.Exists(p)) @@ -329,7 +332,7 @@ namespace Microsoft.DotNet.Tools.Common throw new GracefulException( string.Join( Environment.NewLine, - notExisting.Select((p) => string.Format(pathDoesNotExistLocalizedFormatString, p)))); + notExisting.Select(p => string.Format(pathDoesNotExistLocalizedFormatString, p)))); } } } diff --git a/src/dotnet/CommandBase.cs b/src/dotnet/CommandBase.cs new file mode 100644 index 000000000..ce9bb13e3 --- /dev/null +++ b/src/dotnet/CommandBase.cs @@ -0,0 +1,10 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.DotNet.Cli +{ + public abstract class CommandBase + { + public abstract int Execute(); + } +} \ No newline at end of file diff --git a/src/dotnet/DotNetSubCommandBase.cs b/src/dotnet/DotNetSubCommandBase.cs deleted file mode 100644 index 82d28ab6a..000000000 --- a/src/dotnet/DotNetSubCommandBase.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using Microsoft.DotNet.Cli.CommandLine; - -namespace Microsoft.DotNet.Cli -{ - internal abstract class DotNetSubCommandBase : CommandLineApplication - { - internal DotNetSubCommandBase() : base(throwOnUnexpectedArg: false) - { - } - - public abstract int Run(string fileOrDirectory); - } -} diff --git a/src/dotnet/DotNetTopLevelCommandBase.cs b/src/dotnet/DotNetTopLevelCommandBase.cs index 640d8dccc..319c66523 100644 --- a/src/dotnet/DotNetTopLevelCommandBase.cs +++ b/src/dotnet/DotNetTopLevelCommandBase.cs @@ -3,12 +3,9 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.Tools; -using Microsoft.DotNet.Tools.Common; namespace Microsoft.DotNet.Cli { @@ -18,60 +15,34 @@ namespace Microsoft.DotNet.Cli protected abstract string FullCommandNameLocalized { get; } protected abstract string ArgumentName { get; } protected abstract string ArgumentDescriptionLocalized { get; } - internal abstract List> SubCommands { get; } + internal abstract Dictionary> SubCommands { get; } public int RunCommand(string[] args) { DebugHelper.HandleDebugSwitch(ref args); - CommandLineApplication command = new CommandLineApplication(throwOnUnexpectedArg: true) - { - Name = $"dotnet {CommandName}", - FullName = FullCommandNameLocalized, - }; + var parser = Parser.Instance; - command.HelpOption("-h|--help"); + var result = parser.ParseFrom($"dotnet {CommandName}", args); - command.Argument(ArgumentName, ArgumentDescriptionLocalized); + Reporter.Output.WriteLine(result.Diagram()); - foreach (var subCommandCreator in SubCommands) - { - var subCommand = subCommandCreator(); - command.AddCommand(subCommand); + result.ShowHelpIfRequested(); - subCommand.OnExecute(() => { - try - { - if (!command.Arguments.Any()) - { - throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, ArgumentDescriptionLocalized); - } + var subcommandName = result.Command().Name; - var projectOrDirectory = command.Arguments.First().Value; - if (string.IsNullOrEmpty(projectOrDirectory)) - { - projectOrDirectory = PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory()); - } + var create = SubCommands[subcommandName]; - return subCommand.Run(projectOrDirectory); - } - catch (GracefulException e) - { - Reporter.Error.WriteLine(e.Message.Red()); - subCommand.ShowHelp(); - return 1; - } - }); - } + var command = create(result["dotnet"][CommandName]); try { - return command.Execute(args); + return command.Execute(); } catch (GracefulException e) { Reporter.Error.WriteLine(e.Message.Red()); - command.ShowHelp(); + result.ShowHelp(); return 1; } catch (CommandParsingException e) @@ -81,4 +52,4 @@ namespace Microsoft.DotNet.Cli } } } -} +} \ No newline at end of file diff --git a/src/dotnet/ParseResultExtensions.cs b/src/dotnet/ParseResultExtensions.cs index f4ae8866a..eda1a5590 100644 --- a/src/dotnet/ParseResultExtensions.cs +++ b/src/dotnet/ParseResultExtensions.cs @@ -14,11 +14,9 @@ namespace Microsoft.DotNet.Cli public static void ShowHelpIfRequested(this ParseResult parseResult) { - if (parseResult.HasOption("help")) + if (parseResult.AppliedOptions.Any(o => o.HasOption("help"))) { - // NOTE: this is a temporary stage in refactoring toward the ClicCommandLineParser being used at the CLI entry point. - throw new HelpException(parseResult.Command().HelpView()); } } diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index b47943ce8..8cf7f58a2 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -54,7 +54,7 @@ namespace Microsoft.DotNet.Cli ["test"] = TestCommand.Run, ["vstest"] = VSTestCommand.Run, ["complete"] = CompleteCommand.Run, - ["parse"] = ParseCommand.Run, + ["parse"] = ParseCommand.Run }; public static int Main(string[] args) diff --git a/src/dotnet/commands/dotnet-add/AddCommandParser.cs b/src/dotnet/commands/dotnet-add/AddCommandParser.cs index 6e4a1881f..a3fc0f102 100644 --- a/src/dotnet/commands/dotnet-add/AddCommandParser.cs +++ b/src/dotnet/commands/dotnet-add/AddCommandParser.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net.Http; using System.Threading; using Microsoft.DotNet.Cli.CommandLine; @@ -13,36 +14,46 @@ namespace Microsoft.DotNet.Cli internal static class AddCommandParser { public static Command Add() => - Create.Command("add", - ".NET Add Command", - Accept.ExactlyOneArgument.DefaultToCurrentDirectory(), - Create.Command("package", - ".NET Add Package reference Command", - Accept.ExactlyOneArgument - .WithSuggestionsFrom(QueryNuGet), CommonOptions.HelpOption(), - Create.Option("-v|--version", - "Version for the package to be added.", - Accept.ExactlyOneArgument - .With(name: "VERSION")), - Create.Option("-f|--framework", - "Add reference only when targetting a specific framework", - Accept.ExactlyOneArgument - .With(name: "FRAMEWORK")), - Create.Option("-n|--no-restore ", - "Add reference without performing restore preview and compatibility check."), - Create.Option("-s|--source", - "Use specific NuGet package sources to use during the restore."), - Create.Option("--package-directory", - "Restore the packages to this Directory .", - Accept.ExactlyOneArgument - .With(name: "PACKAGE_DIRECTORY"))), - Create.Command("reference", - "Command to add project to project reference", - Accept.OneOrMoreArguments, CommonOptions.HelpOption(), - Create.Option("-f|--framework", - "Add reference only when targetting a specific framework", - Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) - .With(name: "FRAMEWORK"))), CommonOptions.HelpOption()); + Create.Command( + "add", + ".NET Add Command", + Accept.ExactlyOneArgument + .DefaultToCurrentDirectory(), + Create.Command( + "package", + ".NET Add Package reference Command", + Accept.ExactlyOneArgument + .WithSuggestionsFrom(QueryNuGet), CommonOptions.HelpOption(), + Create.Option("-v|--version", + "Version for the package to be added.", + Accept.ExactlyOneArgument + .With(name: "VERSION") + .ForwardAs(o => $"--version {o.Arguments.Single()}")), + Create.Option("-f|--framework", + "Add reference only when targetting a specific framework", + Accept.ExactlyOneArgument + .With(name: "FRAMEWORK") + .ForwardAs(o => $"--framework {o.Arguments.Single()}")), + Create.Option("-n|--no-restore ", + "Add reference without performing restore preview and compatibility check."), + Create.Option("-s|--source", + "Use specific NuGet package sources to use during the restore.", + Accept.ExactlyOneArgument + .With(name: "SOURCE") + .ForwardAs(o => $"--source {o.Arguments.Single()}")), + Create.Option("--package-directory", + "Restore the packages to this Directory .", + Accept.ExactlyOneArgument + .With(name: "PACKAGE_DIRECTORY") + .ForwardAs(o => $"--package-directory {o.Arguments.Single()}"))), + Create.Command( + "reference", + "Command to add project to project reference", + Accept.OneOrMoreArguments, CommonOptions.HelpOption(), + Create.Option("-f|--framework", + "Add reference only when targetting a specific framework", + Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) + .With(name: "FRAMEWORK"))), CommonOptions.HelpOption()); public static IEnumerable QueryNuGet(string match) { diff --git a/src/dotnet/commands/dotnet-add/Program.cs b/src/dotnet/commands/dotnet-add/Program.cs index 09de6a9f9..25fe203ea 100644 --- a/src/dotnet/commands/dotnet-add/Program.cs +++ b/src/dotnet/commands/dotnet-add/Program.cs @@ -3,7 +3,9 @@ using System; using System.Collections.Generic; +using System.Linq; using Microsoft.DotNet.Cli; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.Add.PackageReference; using Microsoft.DotNet.Tools.Add.ProjectToProjectReference; @@ -16,11 +18,22 @@ namespace Microsoft.DotNet.Tools.Add protected override string FullCommandNameLocalized => LocalizableStrings.NetAddCommand; protected override string ArgumentName => Constants.ProjectArgumentName; protected override string ArgumentDescriptionLocalized => CommonLocalizableStrings.ArgumentsProjectDescription; - internal override List> SubCommands => - new List> + + internal override Dictionary> SubCommands => + new Dictionary> { - AddProjectToProjectReferenceCommand.Create, - AddPackageReferenceCommand.Create, + { + "reference", + add => new AddProjectToProjectReferenceCommand( + add["reference"], + add.Value()) + }, + { + "package", + add => new AddPackageReferenceCommand( + add["package"], + add.Value()) + } }; public static int Run(string[] args) @@ -29,4 +42,4 @@ namespace Microsoft.DotNet.Tools.Add return command.RunCommand(args); } } -} +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs b/src/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs index c5a1fa054..a5ccd858b 100644 --- a/src/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs +++ b/src/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs @@ -1,105 +1,65 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Build.Evaluation; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.Tools.Common; using Microsoft.DotNet.Tools.MSBuild; using Microsoft.DotNet.Tools.NuGet; -using NuGet.Frameworks; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Text; namespace Microsoft.DotNet.Tools.Add.PackageReference { - internal class AddPackageReferenceCommand : DotNetSubCommandBase + internal class AddPackageReferenceCommand : CommandBase { - private CommandOption _versionOption; - private CommandOption _frameworkOption; - private CommandOption _noRestoreOption; - private CommandOption _sourceOption; - private CommandOption _packageDirectoryOption; - private CommandArgument _packageNameArgument; + private readonly AppliedOption _appliedCommand; - public static DotNetSubCommandBase Create() + private readonly string _packageId; + private readonly string _fileOrDirectory; + + public AddPackageReferenceCommand(AppliedOption appliedCommand, string fileOrDirectory) { - var command = new AddPackageReferenceCommand - { - Name = "package", - FullName = LocalizableStrings.AppFullName, - Description = LocalizableStrings.AppDescription, - HandleRemainingArguments = false - }; + _appliedCommand = appliedCommand; + _fileOrDirectory = fileOrDirectory; + _packageId = appliedCommand.Value(); - command.HelpOption("-h|--help"); - - command._packageNameArgument = command.Argument( - $"<{LocalizableStrings.CmdPackage}>", - LocalizableStrings.CmdPackageDescription, - multipleValues: false); - - command._versionOption = command.Option( - $"-v|--version <{LocalizableStrings.CmdVersion}>", - description: LocalizableStrings.CmdVersionDescription, - optionType: CommandOptionType.SingleValue); - - command._frameworkOption = command.Option( - $"-f|--framework <{LocalizableStrings.CmdFramework}>", - LocalizableStrings.CmdFrameworkDescription, - CommandOptionType.SingleValue); - - command._noRestoreOption = command.Option( - "-n|--no-restore ", - LocalizableStrings.CmdNoRestoreDescription, - CommandOptionType.NoValue); - - command._sourceOption = command.Option( - $"-s|--source <{LocalizableStrings.CmdSource}>", - LocalizableStrings.CmdSourceDescription, - CommandOptionType.SingleValue); - - command._packageDirectoryOption = command.Option( - $"--package-directory <{LocalizableStrings.CmdPackageDirectory}>", - LocalizableStrings.CmdPackageDirectoryDescription, - CommandOptionType.SingleValue); - - return command; + + if ( string.IsNullOrWhiteSpace(_packageId) || _appliedCommand.Arguments.Count > 1) + { + throw new GracefulException(LocalizableStrings.SpecifyExactlyOnePackageReference); + } } - public override int Run(string fileOrDirectory) + public override int Execute() { - if (_packageNameArgument.Values.Count != 1 || string.IsNullOrWhiteSpace(_packageNameArgument.Value) || RemainingArguments.Count > 0) - { - throw new GracefulException(LocalizableStrings.SpecifyExactlyOnePackageReference); - } - var projectFilePath = string.Empty; - if (!File.Exists(fileOrDirectory)) + if (!File.Exists(_fileOrDirectory)) { - projectFilePath = MsbuildProject.GetProjectFileFromDirectory(fileOrDirectory).FullName; + projectFilePath = MsbuildProject.GetProjectFileFromDirectory(_fileOrDirectory).FullName; } else { - projectFilePath = fileOrDirectory; + projectFilePath = _fileOrDirectory; } var tempDgFilePath = string.Empty; - if (!_noRestoreOption.HasValue()) + if (!_appliedCommand.HasOption("no-restore")) { // Create a Dependency Graph file for the project tempDgFilePath = Path.GetTempFileName(); GetProjectDependencyGraph(projectFilePath, tempDgFilePath); } - var result = NuGetCommand.Run(TransformArgs(_packageNameArgument.Value, tempDgFilePath, projectFilePath)); + var result = NuGetCommand.Run( + TransformArgs( + _packageId, + tempDgFilePath, + projectFilePath)); DisposeTemporaryFile(tempDgFilePath); return result; @@ -136,7 +96,8 @@ namespace Microsoft.DotNet.Tools.Add.PackageReference private string[] TransformArgs(string packageId, string tempDgFilePath, string projectFilePath) { - var args = new List(){ + var args = new List + { "package", "add", "--package", @@ -145,27 +106,11 @@ namespace Microsoft.DotNet.Tools.Add.PackageReference projectFilePath }; - if (_versionOption.HasValue()) - { - args.Add("--version"); - args.Add(_versionOption.Value()); - } - if (_sourceOption.HasValue()) - { - args.Add("--source"); - args.Add(_sourceOption.Value()); - } - if (_frameworkOption.HasValue()) - { - args.Add("--framework"); - args.Add(_frameworkOption.Value()); - } - if (_packageDirectoryOption.HasValue()) - { - args.Add("--package-directory"); - args.Add(_packageDirectoryOption.Value()); - } - if (_noRestoreOption.HasValue()) + args.AddRange(_appliedCommand + .OptionValuesToBeForwarded() + .SelectMany(a => a.Split(' '))); + + if (_appliedCommand.HasOption("no-restore")) { args.Add("--no-restore"); } @@ -178,4 +123,4 @@ namespace Microsoft.DotNet.Tools.Add.PackageReference return args.ToArray(); } } -} +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs b/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs index aef1d216d..a1159ed23 100644 --- a/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs +++ b/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs @@ -1,59 +1,46 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; using Microsoft.Build.Evaluation; using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.Common; using NuGet.Frameworks; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference { - internal class AddProjectToProjectReferenceCommand : DotNetSubCommandBase + internal class AddProjectToProjectReferenceCommand : CommandBase { - private CommandOption _frameworkOption; + private readonly AppliedOption _appliedCommand; + private readonly string _fileOrDirectory; - public static DotNetSubCommandBase Create() + public AddProjectToProjectReferenceCommand(AppliedOption appliedCommand, string fileOrDirectory) { - var command = new AddProjectToProjectReferenceCommand() + if (appliedCommand == null) { - Name = "reference", - FullName = LocalizableStrings.AppFullName, - Description = LocalizableStrings.AppDescription, - HandleRemainingArguments = true, - ArgumentSeparatorHelpText = LocalizableStrings.AppHelpText, - }; - - command.HelpOption("-h|--help"); - - command._frameworkOption = command.Option( - $"-f|--framework <{CommonLocalizableStrings.CmdFramework}>", - LocalizableStrings.CmdFrameworkDescription, - CommandOptionType.SingleValue); - - return command; + throw new ArgumentNullException(nameof(appliedCommand)); + } + _appliedCommand = appliedCommand; + _fileOrDirectory = fileOrDirectory; } - public override int Run(string fileOrDirectory) + public override int Execute() { var projects = new ProjectCollection(); - MsbuildProject msbuildProj = MsbuildProject.FromFileOrDirectory(projects, fileOrDirectory); + MsbuildProject msbuildProj = MsbuildProject.FromFileOrDirectory(projects, _fileOrDirectory); - if (RemainingArguments.Count == 0) - { - throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneReferenceToAdd); - } + var frameworkString = _appliedCommand["framework"].Value(); - string frameworkString = _frameworkOption.Value(); - PathUtility.EnsureAllPathsExist(RemainingArguments, CommonLocalizableStrings.ReferenceDoesNotExist); - List refs = RemainingArguments - .Select((r) => MsbuildProject.FromFile(projects, r)) - .ToList(); + PathUtility.EnsureAllPathsExist(_appliedCommand.Arguments, CommonLocalizableStrings.ReferenceDoesNotExist); + List refs = _appliedCommand.Arguments + .Select((r) => MsbuildProject.FromFile(projects, r)) + .ToList(); if (frameworkString == null) { @@ -64,8 +51,8 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference if (!@ref.CanWorkOnFramework(tfm)) { Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString( - @ref, - msbuildProj.GetTargetFrameworks().Select((fx) => fx.GetShortFolderName()))); + @ref, + msbuildProj.GetTargetFrameworks().Select((fx) => fx.GetShortFolderName()))); return 1; } } @@ -77,9 +64,9 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference if (!msbuildProj.IsTargetingFramework(framework)) { Reporter.Error.WriteLine(string.Format( - CommonLocalizableStrings.ProjectDoesNotTargetFramework, - msbuildProj.ProjectRootElement.FullPath, - frameworkString)); + CommonLocalizableStrings.ProjectDoesNotTargetFramework, + msbuildProj.ProjectRootElement.FullPath, + frameworkString)); return 1; } @@ -88,18 +75,19 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference if (!@ref.CanWorkOnFramework(framework)) { Reporter.Error.Write(GetProjectNotCompatibleWithFrameworksDisplayString( - @ref, - new string[] { frameworkString })); + @ref, + new string[] { frameworkString })); return 1; } } } - var relativePathReferences = RemainingArguments.Select((r) => - PathUtility.GetRelativePath(msbuildProj.ProjectDirectory, Path.GetFullPath(r))).ToList(); + var relativePathReferences = _appliedCommand.Arguments.Select((r) => + PathUtility.GetRelativePath(msbuildProj.ProjectDirectory, Path.GetFullPath(r))) + .ToList(); int numberOfAddedReferences = msbuildProj.AddProjectToProjectReferences( - _frameworkOption.Value(), + frameworkString, relativePathReferences); if (numberOfAddedReferences != 0) @@ -122,4 +110,4 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference return sb.ToString(); } } -} +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs b/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs index e79951fcb..c42db5fc1 100644 --- a/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs +++ b/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs @@ -15,6 +15,7 @@ namespace Microsoft.DotNet.Cli .With(name: "path"), Create.Option("--position", "", Accept.ExactlyOneArgument - .With(name: "command"))); + .With(name: "command") + .MaterializeAs(o => int.Parse(o.Arguments.Single())))); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-list/Program.cs b/src/dotnet/commands/dotnet-list/Program.cs index 62cdc3bac..016cfebe9 100644 --- a/src/dotnet/commands/dotnet-list/Program.cs +++ b/src/dotnet/commands/dotnet-list/Program.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.DotNet.Cli; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.List.ProjectToProjectReferences; @@ -15,10 +16,11 @@ namespace Microsoft.DotNet.Tools.List protected override string FullCommandNameLocalized => LocalizableStrings.NetListCommand; protected override string ArgumentName => Constants.ProjectArgumentName; protected override string ArgumentDescriptionLocalized => CommonLocalizableStrings.ArgumentsProjectDescription; - internal override List> SubCommands => - new List> + + internal override Dictionary> SubCommands => + new Dictionary> { - ListProjectToProjectReferencesCommand.Create, + { "list", o => new ListProjectToProjectReferencesCommand(o) } }; public static int Run(string[] args) @@ -27,4 +29,4 @@ namespace Microsoft.DotNet.Tools.List return command.RunCommand(args); } } -} +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-reference/Program.cs b/src/dotnet/commands/dotnet-list/dotnet-list-reference/Program.cs index 28a3f29ff..fe33c9a0f 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-reference/Program.cs +++ b/src/dotnet/commands/dotnet-list/dotnet-list-reference/Program.cs @@ -1,40 +1,40 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; +using System.Linq; using Microsoft.Build.Evaluation; using Microsoft.DotNet.Cli; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; -using System.Linq; namespace Microsoft.DotNet.Tools.List.ProjectToProjectReferences { - internal class ListProjectToProjectReferencesCommand : DotNetSubCommandBase + internal class ListProjectToProjectReferencesCommand : CommandBase { - public static DotNetSubCommandBase Create() + private readonly string _fileOrDirectory; + + public ListProjectToProjectReferencesCommand(AppliedOption appliedCommand) { - var command = new ListProjectToProjectReferencesCommand() + if (appliedCommand == null) { - Name = "reference", - FullName = LocalizableStrings.AppFullName, - Description = LocalizableStrings.AppDescription, - }; + throw new ArgumentNullException(nameof(appliedCommand)); + } - command.HelpOption("-h|--help"); - - return command; + _fileOrDirectory = appliedCommand.Arguments.Single(); } - public override int Run(string fileOrDirectory) + public override int Execute() { - var msbuildProj = MsbuildProject.FromFileOrDirectory(new ProjectCollection(), fileOrDirectory); + var msbuildProj = MsbuildProject.FromFileOrDirectory(new ProjectCollection(), _fileOrDirectory); var p2ps = msbuildProj.GetProjectToProjectReferences(); if (!p2ps.Any()) { Reporter.Output.WriteLine(string.Format( - CommonLocalizableStrings.NoReferencesFound, - CommonLocalizableStrings.P2P, - fileOrDirectory)); + CommonLocalizableStrings.NoReferencesFound, + CommonLocalizableStrings.P2P, + _fileOrDirectory)); return 0; } @@ -48,4 +48,4 @@ namespace Microsoft.DotNet.Tools.List.ProjectToProjectReferences return 0; } } -} +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-remove/Program.cs b/src/dotnet/commands/dotnet-remove/Program.cs index 26555a63b..c30791bf5 100644 --- a/src/dotnet/commands/dotnet-remove/Program.cs +++ b/src/dotnet/commands/dotnet-remove/Program.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.DotNet.Cli; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.Remove.PackageReference; using Microsoft.DotNet.Tools.Remove.ProjectToProjectReference; @@ -16,11 +17,12 @@ namespace Microsoft.DotNet.Tools.Remove protected override string FullCommandNameLocalized => LocalizableStrings.NetRemoveCommand; protected override string ArgumentName => Constants.ProjectArgumentName; protected override string ArgumentDescriptionLocalized => CommonLocalizableStrings.ArgumentsProjectDescription; - internal override List> SubCommands => - new List> + + internal override Dictionary> SubCommands => + new Dictionary> { - RemoveProjectToProjectReferenceCommand.Create, - RemovePackageReferenceCommand.Create + { "reference", o => new RemoveProjectToProjectReferenceCommand(o) }, + { "package", o => new RemovePackageReferenceCommand(o) } }; public static int Run(string[] args) @@ -29,4 +31,4 @@ namespace Microsoft.DotNet.Tools.Remove return command.RunCommand(args); } } -} +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs b/src/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs index 85af67e76..082b97ff6 100644 --- a/src/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs +++ b/src/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs @@ -1,61 +1,50 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Microsoft.Build.Evaluation; +using System; +using System.IO; +using System.Linq; using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.Tools.Common; -using Microsoft.DotNet.Tools.MSBuild; using Microsoft.DotNet.Tools.NuGet; -using NuGet.Frameworks; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Text; namespace Microsoft.DotNet.Tools.Remove.PackageReference { - internal class RemovePackageReferenceCommand : DotNetSubCommandBase + internal class RemovePackageReferenceCommand : CommandBase { + private readonly AppliedOption _appliedCommand; + private readonly string _fileOrDirectory; - public static DotNetSubCommandBase Create() + public RemovePackageReferenceCommand(AppliedOption appliedCommand) { - var command = new RemovePackageReferenceCommand + if (appliedCommand == null) { - Name = "package", - FullName = LocalizableStrings.AppFullName, - Description = LocalizableStrings.AppDescription, - HandleRemainingArguments = true, - ArgumentSeparatorHelpText = LocalizableStrings.AppHelpText, - }; - - command.HelpOption("-h|--help"); - - return command; - } - - public override int Run(string fileOrDirectory) - { - if (RemainingArguments.Count != 1) + throw new ArgumentNullException(nameof(appliedCommand)); + } + if (_appliedCommand.Arguments.Count != 1) { throw new GracefulException(LocalizableStrings.SpecifyExactlyOnePackageReference); } + _appliedCommand = appliedCommand; + _fileOrDirectory = appliedCommand.Arguments.Single(); + } + + public override int Execute() + { var projectFilePath = string.Empty; - if (!File.Exists(fileOrDirectory)) + if (!File.Exists(_fileOrDirectory)) { - projectFilePath = MsbuildProject.GetProjectFileFromDirectory(fileOrDirectory).FullName; + projectFilePath = MsbuildProject.GetProjectFileFromDirectory(_fileOrDirectory).FullName; } else { - projectFilePath = fileOrDirectory; + projectFilePath = _fileOrDirectory; } - var packageToRemove = RemainingArguments.First(); + var packageToRemove = _appliedCommand.Arguments.Single(); var result = NuGetCommand.Run(TransformArgs(packageToRemove, projectFilePath)); return result; @@ -63,7 +52,8 @@ namespace Microsoft.DotNet.Tools.Remove.PackageReference private string[] TransformArgs(string packageId, string projectFilePath) { - return new string[]{ + return new string[] + { "package", "remove", "--package", @@ -73,4 +63,4 @@ namespace Microsoft.DotNet.Tools.Remove.PackageReference }; } } -} +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs b/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs index 04d4069f4..55c6b3e2c 100644 --- a/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs +++ b/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; +using System.Linq; using Microsoft.Build.Evaluation; using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.CommandLine; @@ -8,42 +10,34 @@ using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Tools.Remove.ProjectToProjectReference { - internal class RemoveProjectToProjectReferenceCommand : DotNetSubCommandBase + internal class RemoveProjectToProjectReferenceCommand : CommandBase { - private CommandOption _frameworkOption; + private readonly AppliedOption _appliedCommand; + private readonly string _fileOrDirectory; - public static DotNetSubCommandBase Create() + public RemoveProjectToProjectReferenceCommand(AppliedOption appliedCommand) { - var command = new RemoveProjectToProjectReferenceCommand() + if (appliedCommand == null) { - Name = "reference", - FullName = LocalizableStrings.AppFullName, - Description = LocalizableStrings.AppDescription, - HandleRemainingArguments = true, - ArgumentSeparatorHelpText = LocalizableStrings.AppHelpText, - }; + throw new ArgumentNullException(nameof(appliedCommand)); + } - command.HelpOption("-h|--help"); - - command._frameworkOption = command.Option( - $"-f|--framework <{CommonLocalizableStrings.CmdFramework}>", - LocalizableStrings.CmdFrameworkDescription, - CommandOptionType.SingleValue); - - return command; - } - - public override int Run(string fileOrDirectory) - { - var msbuildProj = MsbuildProject.FromFileOrDirectory(new ProjectCollection(), fileOrDirectory); - if (RemainingArguments.Count == 0) + if (_appliedCommand.Arguments.Count == 0) { throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneReferenceToRemove); } + _appliedCommand = appliedCommand; + _fileOrDirectory = appliedCommand.Arguments.Single(); + } + + public override int Execute() + { + var msbuildProj = MsbuildProject.FromFileOrDirectory(new ProjectCollection(), _fileOrDirectory); + int numberOfRemovedReferences = msbuildProj.RemoveProjectToProjectReferences( - _frameworkOption.Value(), - RemainingArguments); + _appliedCommand["framework"].Value(), + _appliedCommand.Arguments); if (numberOfRemovedReferences != 0) { @@ -53,4 +47,4 @@ namespace Microsoft.DotNet.Tools.Remove.ProjectToProjectReference return 0; } } -} +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-sln/Program.cs b/src/dotnet/commands/dotnet-sln/Program.cs index 11e1abe65..484f20aec 100644 --- a/src/dotnet/commands/dotnet-sln/Program.cs +++ b/src/dotnet/commands/dotnet-sln/Program.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using Microsoft.DotNet.Cli; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.Sln.Add; using Microsoft.DotNet.Tools.Sln.List; @@ -17,12 +18,13 @@ namespace Microsoft.DotNet.Tools.Sln protected override string FullCommandNameLocalized => LocalizableStrings.AppFullName; protected override string ArgumentName => Constants.SolutionArgumentName; protected override string ArgumentDescriptionLocalized => CommonLocalizableStrings.ArgumentsSolutionDescription; - internal override List> SubCommands => - new List> + + internal override Dictionary> SubCommands => + new Dictionary> { - AddProjectToSolutionCommand.Create, - ListProjectsInSolutionCommand.Create, - RemoveProjectFromSolutionCommand.Create + { "add", o => new AddProjectToSolutionCommand(o) }, + { "list", o => new ListProjectsInSolutionCommand(o) }, + { "remove", o => new RemoveProjectFromSolutionCommand(o) } }; public static int Run(string[] args) @@ -31,4 +33,4 @@ namespace Microsoft.DotNet.Tools.Sln return command.RunCommand(args); } } -} +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-sln/add/Program.cs b/src/dotnet/commands/dotnet-sln/add/Program.cs index 6b6124a29..c5d23ff84 100644 --- a/src/dotnet/commands/dotnet-sln/add/Program.cs +++ b/src/dotnet/commands/dotnet-sln/add/Program.cs @@ -1,49 +1,50 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; +using System.IO; +using System.Linq; using Microsoft.DotNet.Cli; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Sln.Internal; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.Common; -using Microsoft.DotNet.Tools.Sln; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; namespace Microsoft.DotNet.Tools.Sln.Add { - internal class AddProjectToSolutionCommand : DotNetSubCommandBase + internal class AddProjectToSolutionCommand : CommandBase { - public static DotNetSubCommandBase Create() + private readonly AppliedOption _appliedCommand; + private readonly string _fileOrDirectory; + + public AddProjectToSolutionCommand(AppliedOption appliedCommand) { - var command = new AddProjectToSolutionCommand() + if (appliedCommand == null) { - Name = "add", - FullName = LocalizableStrings.AddAppFullName, - Description = LocalizableStrings.AddSubcommandHelpText, - HandleRemainingArguments = true, - ArgumentSeparatorHelpText = LocalizableStrings.AddSubcommandHelpText, - }; + throw new ArgumentNullException(nameof(appliedCommand)); + } + _appliedCommand = appliedCommand; - command.HelpOption("-h|--help"); - - return command; + _fileOrDirectory = appliedCommand.Arguments.Single(); } - public override int Run(string fileOrDirectory) + public override int Execute() { - SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(fileOrDirectory); + SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(_fileOrDirectory); - if (RemainingArguments.Count == 0) + if (_appliedCommand.Arguments.Count == 0) { throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneProjectToAdd); } - PathUtility.EnsureAllPathsExist(RemainingArguments, CommonLocalizableStrings.ProjectDoesNotExist); - var fullProjectPaths = RemainingArguments.Select((p) => Path.GetFullPath(p)).ToList(); + PathUtility.EnsureAllPathsExist(_appliedCommand.Arguments, CommonLocalizableStrings.ProjectDoesNotExist); + + var fullProjectPaths = _appliedCommand.Arguments + .Select(Path.GetFullPath) + .ToList(); + + var preAddProjectCount = slnFile.Projects.Count; - int preAddProjectCount = slnFile.Projects.Count; foreach (var fullProjectPath in fullProjectPaths) { slnFile.AddProject(fullProjectPath); @@ -57,4 +58,4 @@ namespace Microsoft.DotNet.Tools.Sln.Add return 0; } } -} +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-sln/list/Program.cs b/src/dotnet/commands/dotnet-sln/list/Program.cs index 3ff1f8480..a82bc2f87 100644 --- a/src/dotnet/commands/dotnet-sln/list/Program.cs +++ b/src/dotnet/commands/dotnet-sln/list/Program.cs @@ -1,33 +1,32 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; +using System.Linq; using Microsoft.DotNet.Cli; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Sln.Internal; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.Common; -using Microsoft.DotNet.Tools.Sln; namespace Microsoft.DotNet.Tools.Sln.List { - internal class ListProjectsInSolutionCommand : DotNetSubCommandBase + internal class ListProjectsInSolutionCommand : CommandBase { - public static DotNetSubCommandBase Create() + private readonly string _fileOrDirectory; + + public ListProjectsInSolutionCommand(AppliedOption appliedCommand) { - var command = new ListProjectsInSolutionCommand() + if (appliedCommand == null) { - Name = "list", - FullName = LocalizableStrings.ListAppFullName, - Description = LocalizableStrings.ListSubcommandHelpText, - }; - - command.HelpOption("-h|--help"); - - return command; + throw new ArgumentNullException(nameof(appliedCommand)); + } + _fileOrDirectory = appliedCommand.Arguments.Single(); } - public override int Run(string fileOrDirectory) + public override int Execute() { - SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(fileOrDirectory); + SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(_fileOrDirectory); if (slnFile.Projects.Count == 0) { Reporter.Output.WriteLine(CommonLocalizableStrings.NoProjectsFound); @@ -44,4 +43,4 @@ namespace Microsoft.DotNet.Tools.Sln.List return 0; } } -} +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-sln/remove/Program.cs b/src/dotnet/commands/dotnet-sln/remove/Program.cs index c147052cd..6327e2181 100644 --- a/src/dotnet/commands/dotnet-sln/remove/Program.cs +++ b/src/dotnet/commands/dotnet-sln/remove/Program.cs @@ -1,49 +1,47 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; +using System.IO; +using System.Linq; using Microsoft.DotNet.Cli; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Sln.Internal; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.Common; -using Microsoft.DotNet.Tools.Sln; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; namespace Microsoft.DotNet.Tools.Sln.Remove { - internal class RemoveProjectFromSolutionCommand : DotNetSubCommandBase + internal class RemoveProjectFromSolutionCommand : CommandBase { - public static DotNetSubCommandBase Create() + private readonly AppliedOption _appliedCommand; + private readonly string _fileOrDirectory; + + public RemoveProjectFromSolutionCommand(AppliedOption appliedCommand) { - var command = new RemoveProjectFromSolutionCommand() + if (appliedCommand == null) { - Name = "remove", - FullName = LocalizableStrings.RemoveAppFullName, - Description = LocalizableStrings.RemoveSubcommandHelpText, - HandleRemainingArguments = true, - ArgumentSeparatorHelpText = LocalizableStrings.RemoveSubcommandHelpText, - }; + throw new ArgumentNullException(nameof(appliedCommand)); + } - command.HelpOption("-h|--help"); - - return command; - } - - public override int Run(string fileOrDirectory) - { - SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(fileOrDirectory); - - if (RemainingArguments.Count == 0) + if (_appliedCommand.Arguments.Count == 0) { throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneProjectToRemove); } - var relativeProjectPaths = RemainingArguments.Select((p) => - PathUtility.GetRelativePath( - PathUtility.EnsureTrailingSlash(slnFile.BaseDirectory), - Path.GetFullPath(p))).ToList(); + _appliedCommand = appliedCommand; + _fileOrDirectory = appliedCommand.Arguments.Single(); + } + + public override int Execute() + { + SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(_fileOrDirectory); + + var relativeProjectPaths = _appliedCommand.Arguments.Select(p => + PathUtility.GetRelativePath( + PathUtility.EnsureTrailingSlash(slnFile.BaseDirectory), + Path.GetFullPath(p))) + .ToList(); bool slnChanged = false; foreach (var path in relativeProjectPaths) @@ -63,4 +61,4 @@ namespace Microsoft.DotNet.Tools.Sln.Remove return 0; } } -} +} \ No newline at end of file From 34d9cbf8637abd66b1a56db009201f4df382d4e9 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Fri, 10 Mar 2017 17:11:19 -0800 Subject: [PATCH 053/149] new CliCommandLine version --- build/DependencyVersions.props | 2 +- src/dotnet/CommonOptions.cs | 2 +- src/dotnet/Parser.cs | 2 +- .../commands/dotnet-add/AddCommandParser.cs | 18 ++++++++++-------- .../dotnet-build/BuildCommandParser.cs | 10 +++++----- .../dotnet-clean/CleanCommandParser.cs | 6 +++--- .../dotnet-complete/CompleteCommandParser.cs | 4 ++-- .../commands/dotnet-list/ListCommandParser.cs | 4 ++-- .../commands/dotnet-new/NewCommandParser.cs | 2 +- .../dotnet-nuget/NuGetCommandParser.cs | 18 +++++++++--------- .../commands/dotnet-pack/PackCommandParser.cs | 6 +++--- .../dotnet-publish/PublishCommandParser.cs | 14 +++++++------- .../dotnet-remove/RemoveCommandParser.cs | 4 ++-- .../dotnet-restore/RestoreCommandParser.cs | 18 +++++++++--------- .../commands/dotnet-run/RunCommandParser.cs | 4 ++-- .../commands/dotnet-sln/SlnCommandParser.cs | 4 ++-- .../commands/dotnet-test/TestCommandParser.cs | 12 ++++++------ src/dotnet/dotnet.csproj | 2 +- .../ArgumentForwardingExtensionsTests.cs | 8 ++++---- test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 20 files changed, 72 insertions(+), 70 deletions(-) diff --git a/build/DependencyVersions.props b/build/DependencyVersions.props index ee631dd4f..04d447d7f 100644 --- a/build/DependencyVersions.props +++ b/build/DependencyVersions.props @@ -16,7 +16,7 @@ 1.0.0-beta1-20170209-117 1.0.3 1.0.3 - 0.1.0-alpha-74 + 0.1.0-alpha-84 diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index 8667b5f76..5476d8f31 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -11,7 +11,7 @@ namespace Microsoft.DotNet.Cli Create.Option( "-h|--help", "Show help information", - Accept.NoArguments, + Accept.NoArguments(), materialize: o => o.Option.Command().HelpView()); public static Option VerbosityOption() => diff --git a/src/dotnet/Parser.cs b/src/dotnet/Parser.cs index 4b53bfa45..3a59667b4 100644 --- a/src/dotnet/Parser.cs +++ b/src/dotnet/Parser.cs @@ -12,7 +12,7 @@ namespace Microsoft.DotNet.Cli delimiters: Array.Empty(), options: Create.Command("dotnet", ".NET Command Line Tools", - Accept.NoArguments, + Accept.NoArguments(), NewCommandParser.New(), RestoreCommandParser.Restore(), BuildCommandParser.Build(), diff --git a/src/dotnet/commands/dotnet-add/AddCommandParser.cs b/src/dotnet/commands/dotnet-add/AddCommandParser.cs index a3fc0f102..fd1ed571d 100644 --- a/src/dotnet/commands/dotnet-add/AddCommandParser.cs +++ b/src/dotnet/commands/dotnet-add/AddCommandParser.cs @@ -17,43 +17,45 @@ namespace Microsoft.DotNet.Cli Create.Command( "add", ".NET Add Command", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .DefaultToCurrentDirectory(), Create.Command( "package", ".NET Add Package reference Command", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .WithSuggestionsFrom(QueryNuGet), CommonOptions.HelpOption(), Create.Option("-v|--version", "Version for the package to be added.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "VERSION") .ForwardAs(o => $"--version {o.Arguments.Single()}")), Create.Option("-f|--framework", "Add reference only when targetting a specific framework", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "FRAMEWORK") .ForwardAs(o => $"--framework {o.Arguments.Single()}")), Create.Option("-n|--no-restore ", "Add reference without performing restore preview and compatibility check."), Create.Option("-s|--source", "Use specific NuGet package sources to use during the restore.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "SOURCE") .ForwardAs(o => $"--source {o.Arguments.Single()}")), Create.Option("--package-directory", "Restore the packages to this Directory .", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "PACKAGE_DIRECTORY") .ForwardAs(o => $"--package-directory {o.Arguments.Single()}"))), Create.Command( "reference", "Command to add project to project reference", - Accept.OneOrMoreArguments, CommonOptions.HelpOption(), + Accept.OneOrMoreArguments(), + CommonOptions.HelpOption(), Create.Option("-f|--framework", "Add reference only when targetting a specific framework", Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) - .With(name: "FRAMEWORK"))), CommonOptions.HelpOption()); + .With(name: "FRAMEWORK"))), + CommonOptions.HelpOption()); public static IEnumerable QueryNuGet(string match) { diff --git a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs index 77f393a41..706fbf861 100644 --- a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs +++ b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs @@ -12,13 +12,13 @@ namespace Microsoft.DotNet.Cli Create.Command( "build", ".NET Builder", - Accept.ZeroOrOneArgument + Accept.ZeroOrOneArgument() .Forward(), CommonOptions.HelpOption(), Create.Option( "-o|--output", "Output directory in which to place built artifacts.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "OUTPUT_DIR") .ForwardAs(o => $"/p:OutputPath={o.Arguments.Single()}")), Create.Option( @@ -34,14 +34,14 @@ namespace Microsoft.DotNet.Cli Create.Option( "-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "CONFIGURATION") .WithSuggestionsFrom("DEBUG", "RELEASE") .ForwardAs(o => $"/p:Configuration={o.Arguments.Single()}")), Create.Option( "--version-suffix", "Defines the value for the $(VersionSuffix) property in the project", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "VERSION_SUFFIX") .ForwardAs(o => $"/p:VersionSuffix={o.Arguments.Single()}")), Create.Option( @@ -50,7 +50,7 @@ namespace Microsoft.DotNet.Cli Create.Option( "--no-dependencies", "Set this flag to ignore project-to-project references and only build the root project", - Accept.NoArguments + Accept.NoArguments() .ForwardAs("/p:BuildProjectReferences=false")), CommonOptions.VerbosityOption()); } diff --git a/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs b/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs index dfdc5d1ac..16ef2b715 100644 --- a/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs +++ b/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs @@ -12,15 +12,15 @@ namespace Microsoft.DotNet.Cli ".NET Clean Command", CommonOptions.HelpOption(), Create.Option("-o|--output", "Directory in which the build outputs have been placed.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "OUTPUT_DIR")), Create.Option("-f|--framework", "Clean a specific framework.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "FRAMEWORK") .WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile())), Create.Option("-c|--configuration", "Clean a specific configuration.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "CONFIGURATION") .WithSuggestionsFrom("DEBUG", "RELEASE"))); } diff --git a/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs b/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs index c42db5fc1..658a5e22c 100644 --- a/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs +++ b/src/dotnet/commands/dotnet-complete/CompleteCommandParser.cs @@ -11,10 +11,10 @@ namespace Microsoft.DotNet.Cli public static Command Complete() => Create.Command( "complete", "", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "path"), Create.Option("--position", "", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "command") .MaterializeAs(o => int.Parse(o.Arguments.Single())))); } diff --git a/src/dotnet/commands/dotnet-list/ListCommandParser.cs b/src/dotnet/commands/dotnet-list/ListCommandParser.cs index ddfde2b6f..d90660bc5 100644 --- a/src/dotnet/commands/dotnet-list/ListCommandParser.cs +++ b/src/dotnet/commands/dotnet-list/ListCommandParser.cs @@ -10,14 +10,14 @@ namespace Microsoft.DotNet.Cli public static Command List() => Create.Command("list", ".NET List Command", - Accept.ZeroOrOneArgument + Accept.ZeroOrOneArgument() .With(name: "PROJECT", description: "The project file to operate on. If a file is not specified, the command will search the current directory for one.") .DefaultToCurrentDirectory(), CommonOptions.HelpOption(), Create.Command("reference", "Command to list project to project references", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "PROJECT", description: "The project file to operate on. If a file is not specified, the command will search the current directory for one."), diff --git a/src/dotnet/commands/dotnet-new/NewCommandParser.cs b/src/dotnet/commands/dotnet-new/NewCommandParser.cs index 36f49c8b9..88d81208a 100644 --- a/src/dotnet/commands/dotnet-new/NewCommandParser.cs +++ b/src/dotnet/commands/dotnet-new/NewCommandParser.cs @@ -11,7 +11,7 @@ namespace Microsoft.DotNet.Cli Create.Command("new", "Initialize .NET projects.", Accept - .ExactlyOneArgument + .ExactlyOneArgument() .WithSuggestionsFrom( "console", "classlib", diff --git a/src/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs b/src/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs index 2358c685e..fd80e5589 100644 --- a/src/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs +++ b/src/dotnet/commands/dotnet-nuget/NuGetCommandParser.cs @@ -15,11 +15,11 @@ namespace Microsoft.DotNet.Cli "Show version information"), Create.Option("-v|--verbosity", "The verbosity of logging to use. Allowed values: Debug, Verbose, Information, Minimal, Warning, Error.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "verbosity")), Create.Command("delete", "Deletes a package from the server.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "root", description: "The Package Id and version."), CommonOptions.HelpOption(), @@ -27,13 +27,13 @@ namespace Microsoft.DotNet.Cli "Forces the application to run using an invariant, English-based culture."), Create.Option("-s|--source", "Specifies the server URL", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "source")), Create.Option("--non-interactive", "Do not prompt for user input or confirmations."), Create.Option("-k|--api-key", "The API key for the server.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "apiKey"))), Create.Command("locals", "Clears or lists local NuGet resources such as http requests cache, packages cache or machine-wide global packages folder.", @@ -54,21 +54,21 @@ namespace Microsoft.DotNet.Cli "Forces the application to run using an invariant, English-based culture."), Create.Option("-s|--source", "Specifies the server URL", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "source")), Create.Option("-ss|--symbol-source", "Specifies the symbol server URL. If not specified, nuget.smbsrc.net is used when pushing to nuget.org.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "source")), Create.Option("-t|--timeout", "Specifies the timeout for pushing to a server in seconds. Defaults to 300 seconds (5 minutes).", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "timeout")), Create.Option("-k|--api-key", "The API key for the server.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "apiKey")), Create.Option("-sk|--symbol-api-key", "The API key for the symbol server.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "apiKey")), Create.Option("-d|--disable-buffering", "Disable buffering when pushing to an HTTP(S) server to decrease memory usage."), diff --git a/src/dotnet/commands/dotnet-pack/PackCommandParser.cs b/src/dotnet/commands/dotnet-pack/PackCommandParser.cs index 1f36cd9a3..16b6b582c 100644 --- a/src/dotnet/commands/dotnet-pack/PackCommandParser.cs +++ b/src/dotnet/commands/dotnet-pack/PackCommandParser.cs @@ -13,7 +13,7 @@ namespace Microsoft.DotNet.Cli CommonOptions.HelpOption(), Create.Option("-o|--output", "Directory in which to place built packages.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "OUTPUT_DIR")), Create.Option("--no-build", "Skip building the project prior to packing. By default, the project will be built."), @@ -23,13 +23,13 @@ namespace Microsoft.DotNet.Cli "Include PDBs and source files. Source files go into the src folder in the resulting nuget package"), Create.Option("-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "CONFIGURATION") .WithSuggestionsFrom("DEBUG", "RELEASE")), Create.Option("--version-suffix", "Defines the value for the $(VersionSuffix) property in the project.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "VERSION_SUFFIX")), Create.Option("-s|--serviceable", "Set the serviceable flag in the package. For more information, please see https://aka.ms/nupkgservicing."), diff --git a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs index 4aae155ce..d6eb5f78d 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs @@ -12,36 +12,36 @@ namespace Microsoft.DotNet.Cli Create.Command( "publish", ".NET Publisher", - Accept.ZeroOrMoreArguments, + Accept.ZeroOrMoreArguments(), CommonOptions.HelpOption(), Create.Option("-f|--framework", "Target framework to publish for. The target framework has to be specified in the project file.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile()) .With(name: "FRAMEWORK") .ForwardAs(o => $"/p:TargetFramework={o.Arguments.Single()}")), Create.Option("-r|--runtime", "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile()) .With(name: "RUNTIME_IDENTIFIER") .ForwardAs(o => $"/p:RuntimeIdentifier={o.Arguments.Single()}")), Create.Option("-o|--output", "Output directory in which to place the published artifacts.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "OUTPUT_DIR") .ForwardAs(o => $"/p:PublishDir={o.Arguments.Single()}")), Create.Option("-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "CONFIGURATION") .WithSuggestionsFrom("DEBUG", "RELEASE") .ForwardAs(o => $"/p:Configuration={o.Arguments.Single()}")), Create.Option("--version-suffix", "Defines the value for the $(VersionSuffix) property in the project.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "VERSION_SUFFIX") .ForwardAs(o => $"/p:VersionSuffix={o.Arguments.Single()}")), Create.Option("--filter", "The XML file that contains the list of packages to be excluded from publish step.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "PROFILE_XML") .ForwardAs(o => $"/p:FilterProjectFiles={o.Arguments.Single()}")), CommonOptions.VerbosityOption()); diff --git a/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs b/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs index 0e99c019b..b452057b8 100644 --- a/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs +++ b/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs @@ -10,7 +10,7 @@ namespace Microsoft.DotNet.Cli public static Command Remove() => Create.Command("remove", ".NET Remove Command", - Accept.ZeroOrOneArgument + Accept.ZeroOrOneArgument() .With(name: "PROJECT") .DefaultToCurrentDirectory(), CommonOptions.HelpOption(), @@ -23,7 +23,7 @@ namespace Microsoft.DotNet.Cli CommonOptions.HelpOption(), Create.Option("-f|--framework", "Remove reference only when targetting a specific framework", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "FRAMEWORK")))); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs b/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs index 39ae995cb..48452aef3 100644 --- a/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs +++ b/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs @@ -12,52 +12,52 @@ namespace Microsoft.DotNet.Cli Create.Command( "restore", ".NET dependency restorer", - Accept.ZeroOrMoreArguments, + Accept.ZeroOrMoreArguments(), CommonOptions.HelpOption(), Create.Option( "-s|--source", "Specifies a NuGet package source to use during the restore.", - Accept.OneOrMoreArguments + Accept.OneOrMoreArguments() .With(name: "SOURCE") .ForwardAs(o => $"/p:RestoreSources={string.Join("%3B", o.Arguments)}")), Create.Option( "-r|--runtime", "Target runtime to restore packages for.", - Accept.OneOrMoreArguments + Accept.OneOrMoreArguments() .WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile()) .With(name: "RUNTIME_IDENTIFIER") .ForwardAs(o => $"/p:RuntimeIdentifiers={string.Join("%3B", o.Arguments)}")), Create.Option( "--packages", "Directory to install packages in.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "PACKAGES_DIRECTORY") .ForwardAs(o => $"/p:RestorePackagesPath={o.Arguments.Single()}")), Create.Option( "--disable-parallel", "Disables restoring multiple projects in parallel.", - Accept.NoArguments + Accept.NoArguments() .ForwardAs("/p:RestoreDisableParallel=true")), Create.Option( "--configfile", "The NuGet configuration file to use.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "FILE") .ForwardAs(o => $"/p:RestoreConfigFile={o.Arguments.Single()}")), Create.Option( "--no-cache", "Do not cache packages and http requests.", - Accept.NoArguments + Accept.NoArguments() .ForwardAs("/p:RestoreNoCache=true")), Create.Option( "--ignore-failed-sources", "Treat package source failures as warnings.", - Accept.NoArguments + Accept.NoArguments() .ForwardAs("/p:RestoreIgnoreFailedSources=true")), Create.Option( "--no-dependencies", "Set this flag to ignore project to project references and only restore the root project", - Accept.NoArguments + Accept.NoArguments() .ForwardAs("/p:RestoreRecursive=false")), CommonOptions.VerbosityOption()); } diff --git a/src/dotnet/commands/dotnet-run/RunCommandParser.cs b/src/dotnet/commands/dotnet-run/RunCommandParser.cs index dba6ec68a..5e093ce64 100644 --- a/src/dotnet/commands/dotnet-run/RunCommandParser.cs +++ b/src/dotnet/commands/dotnet-run/RunCommandParser.cs @@ -13,13 +13,13 @@ namespace Microsoft.DotNet.Cli CommonOptions.HelpOption(), Create.Option("-c|--configuration", @"Configuration to use for building the project. Default for most projects is ""Debug"".", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .WithSuggestionsFrom("DEBUG", "RELEASE")), Create.Option("-f|--framework", "Build and run the app using the specified framework. The framework has to be specified in the project file.", Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile)), Create.Option("-p|--project", "The path to the project file to run (defaults to the current directory if there is only one project).", - Accept.ZeroOrOneArgument)); + Accept.ZeroOrOneArgument())); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs index 9d9f073e4..18b244ddf 100644 --- a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs +++ b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs @@ -13,12 +13,12 @@ namespace Microsoft.DotNet.Cli CommonOptions.HelpOption(), Create.Command("add", ".NET Add project(s) to a solution file Command", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "SLN_FILE"), CommonOptions.HelpOption()), Create.Command("list", "List all projects in the solution.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "SLN_FILE"), CommonOptions.HelpOption()), Create.Command("remove", diff --git a/src/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/dotnet/commands/dotnet-test/TestCommandParser.cs index 2340ee4b3..69e8bab2f 100644 --- a/src/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -12,7 +12,7 @@ namespace Microsoft.DotNet.Cli "Show help information"), Create.Option("-s|--settings", "Settings to use when running tests.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "SETTINGS_FILE")), Create.Option("-t|--list-tests", "Lists discovered tests"), @@ -23,16 +23,16 @@ namespace Microsoft.DotNet.Cli Run a test with the specified full name: --filter ""FullyQualifiedName=Namespace.ClassName.MethodName"" Run tests that contain the specified name: --filter ""FullyQualifiedName~Namespace.Class"" More info on filtering support: https://aka.ms/vstest-filtering", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "EXPRESSION")), Create.Option("-a|--test-adapter-path", "Use custom adapters from the given path in the test run.\r\n Example: --test-adapter-path "), Create.Option("-l|--logger", "Specify a logger for test results.\r\n Example: --logger \"trx[;LogFileName=]\"", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "LoggerUri/FriendlyName")), Create.Option("-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "CONFIGURATION") .WithSuggestionsFrom("DEBUG", "RELEASE")), Create.Option("-f|--framework", @@ -41,11 +41,11 @@ namespace Microsoft.DotNet.Cli .With(name: "FRAMEWORK")), Create.Option("-o|--output", "Directory in which to find the binaries to be run", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "OUTPUT_DIR")), Create.Option("-d|--diag", "Enable verbose logs for test platform.\r\n Logs are written to the provided file.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "PATH_TO_FILE")), Create.Option("--no-build", "Do not build project before testing."), diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index 53de43916..549108170 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs b/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs index c40b07888..34eb6ad2f 100644 --- a/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs +++ b/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs @@ -18,10 +18,10 @@ namespace Microsoft.DotNet.Tests.ParserTests { var command = Command("the-command", "", Option("-o|--one", "", - ZeroOrOneArgument + ZeroOrOneArgument() .ForwardAs(o => $"/i:{o.Arguments.Single()}")), Option("-t|--two", "", - NoArguments + NoArguments() .ForwardAs("/s:true"))); var result = command.Parse("the-command -t -o 123"); @@ -37,7 +37,7 @@ namespace Microsoft.DotNet.Tests.ParserTests { var command = Command("the-command", "", Option("-x", "", - ZeroOrMoreArguments + ZeroOrMoreArguments() .ForwardAs(o => $"/x:{string.Join("&", o.Arguments)}"))); var result = command.Parse("the-command -x one -x two"); @@ -53,7 +53,7 @@ namespace Microsoft.DotNet.Tests.ParserTests { var command = Command("the-command", "", Option("-x", "", - ZeroOrMoreArguments + ZeroOrMoreArguments() .Forward())); var result = command.Parse("the-command -x one"); diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index 3c6555049..994f8c214 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From 3bdfe287658d675cb05058f1f392f8cbc7543b67 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 17:52:40 -0800 Subject: [PATCH 054/149] Resolve build breaks --- src/dotnet/CommonOptions.cs | 8 ++--- .../dotnet-cache/CacheCommandParser.cs | 14 ++++---- .../dotnet-clean/CleanCommandParser.cs | 2 +- .../dotnet-migrate/MigrateCommandParser.cs | 2 +- .../commands/dotnet-pack/PackCommandParser.cs | 32 +++++++++++-------- .../dotnet-publish/PublishCommandParser.cs | 1 + .../commands/dotnet-test/TestCommandParser.cs | 18 +++++------ 7 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index 174484253..d58dc53f6 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -30,7 +30,7 @@ namespace Microsoft.DotNet.Cli Create.Option( "-f|--framework", "Target framework to publish for. The target framework has to be specified in the project file.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile()) .With(name: "FRAMEWORK") .ForwardAs(o => $"/p:TargetFramework={o.Arguments.Single()}")); @@ -39,7 +39,7 @@ namespace Microsoft.DotNet.Cli Create.Option( "-r|--runtime", "Publish the project for a given runtime. This is used when creating self-contained deployment. Default is to publish a framework-dependent app.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile()) .With(name: "RUNTIME_IDENTIFIER") .ForwardAs(o => $"/p:RuntimeIdentifier={o.Arguments.Single()}")); @@ -48,7 +48,7 @@ namespace Microsoft.DotNet.Cli Create.Option( "-c|--configuration", "Configuration to use for building the project. Default for most projects is \"Debug\".", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "CONFIGURATION") .WithSuggestionsFrom("DEBUG", "RELEASE") .ForwardAs(o => $"/p:Configuration={o.Arguments.Single()}")); @@ -57,7 +57,7 @@ namespace Microsoft.DotNet.Cli Create.Option( "--version-suffix", "Defines the value for the $(VersionSuffix) property in the project.", - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: "VERSION_SUFFIX") .ForwardAs(o => $"/p:VersionSuffix={o.Arguments.Single()}")); diff --git a/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs b/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs index b314e6c37..1c5985152 100644 --- a/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs +++ b/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs @@ -13,12 +13,12 @@ namespace Microsoft.DotNet.Cli Create.Command( "cache", LocalizableStrings.AppDescription, - Accept.ZeroOrMoreArguments, + Accept.ZeroOrMoreArguments(), CommonOptions.HelpOption(), Create.Option( "-e|--entries", LocalizableStrings.ProjectEntryDescription, - Accept.OneOrMoreArguments + Accept.OneOrMoreArguments() .With(name: LocalizableStrings.ProjectEntries) .ForwardAs(o => { @@ -34,7 +34,7 @@ namespace Microsoft.DotNet.Cli Create.Option( "--framework-version", LocalizableStrings.FrameworkVersionOptionDescription, - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: LocalizableStrings.FrameworkVersionOption) .ForwardAs(o => $"/p:FX_Version={o.Arguments.Single()}")), CommonOptions.RuntimeOption(), @@ -42,24 +42,24 @@ namespace Microsoft.DotNet.Cli Create.Option( "-o|--output", LocalizableStrings.OutputOptionDescription, - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: LocalizableStrings.OutputOption) .ForwardAs(o => $"/p:ComposeDir={o.Arguments.Single()}")), Create.Option( "-w|--working-dir", LocalizableStrings.IntermediateWorkingDirOptionDescription, - Accept.ExactlyOneArgument + Accept.ExactlyOneArgument() .With(name: LocalizableStrings.IntermediateWorkingDirOption) .ForwardAs(o => $"/p:ComposeWorkingDir={o.Arguments.Single()}")), Create.Option( "--preserve-working-dir", LocalizableStrings.PreserveIntermediateWorkingDirOptionDescription, - Accept.NoArguments + Accept.NoArguments() .ForwardAs(o => $"/p:PreserveComposeWorkingDir=true")), Create.Option( "--skip-optimization", LocalizableStrings.SkipOptimizationOptionDescription, - Accept.NoArguments + Accept.NoArguments() .ForwardAs("/p:SkipOptimization=true")), CommonOptions.VerbosityOption()); } diff --git a/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs b/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs index 50db53d60..d157d9d52 100644 --- a/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs +++ b/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs @@ -13,7 +13,7 @@ namespace Microsoft.DotNet.Cli Create.Command( "clean", LocalizableStrings.AppFullName, - Accept.ZeroOrMoreArguments, + Accept.ZeroOrMoreArguments(), CommonOptions.HelpOption(), Create.Option("-o|--output", LocalizableStrings.CmdOutputDirDescription, diff --git a/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs b/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs index 738a95110..fc64a0c74 100644 --- a/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs +++ b/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs @@ -14,7 +14,7 @@ namespace Microsoft.DotNet.Cli Create.Command( "migrate", ".NET Migrate Command", - Accept.ZeroOrOneArgument + Accept.ZeroOrOneArgument() .MaterializeAs(o => { return new MigrateCommand( diff --git a/src/dotnet/commands/dotnet-pack/PackCommandParser.cs b/src/dotnet/commands/dotnet-pack/PackCommandParser.cs index 75b52a7ab..d1e64e86c 100644 --- a/src/dotnet/commands/dotnet-pack/PackCommandParser.cs +++ b/src/dotnet/commands/dotnet-pack/PackCommandParser.cs @@ -13,28 +13,32 @@ namespace Microsoft.DotNet.Cli Create.Command( "pack", LocalizableStrings.AppDescription, - Accept.ZeroOrMoreArguments, + Accept.ZeroOrMoreArguments(), CommonOptions.HelpOption(), Create.Option( "-o|--output", LocalizableStrings.CmdOutputDirDescription, - Accept.ExactlyOneArgument() + Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdOutputDir) .ForwardAs(o => $"/p:PackageOutputPath={o.Arguments.Single()}")), - Create.Option("--no-build", - LocalizableStrings.CmdNoBuildOptionDescription, - Accept.NoArguments.ForwardAs("/p:NoBuild=true")), - Create.Option("--include-symbols", - LocalizableStrings.CmdIncludeSymbolsDescription, - Accept.NoArguments.ForwardAs("/p:IncludeSymbols=true")), - Create.Option("--include-source", - LocalizableStrings.CmdIncludeSourceDescription, - Accept.NoArguments.ForwardAs("/p:IncludeSource=true")), + Create.Option( + "--no-build", + LocalizableStrings.CmdNoBuildOptionDescription, + Accept.NoArguments().ForwardAs("/p:NoBuild=true")), + Create.Option( + "--include-symbols", + LocalizableStrings.CmdIncludeSymbolsDescription, + Accept.NoArguments().ForwardAs("/p:IncludeSymbols=true")), + Create.Option( + "--include-source", + LocalizableStrings.CmdIncludeSourceDescription, + Accept.NoArguments().ForwardAs("/p:IncludeSource=true")), CommonOptions.ConfigurationOption(), CommonOptions.VersionSuffixOption(), - Create.Option("-s|--serviceable", - LocalizableStrings.CmdServiceableDescription, - Accept.NoArguments.ForwardAs("/p:Serviceable=true")), + Create.Option( + "-s|--serviceable", + LocalizableStrings.CmdServiceableDescription, + Accept.NoArguments().ForwardAs("/p:Serviceable=true")), CommonOptions.VerbosityOption()); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs index e62a36de6..e40cac535 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs @@ -24,6 +24,7 @@ namespace Microsoft.DotNet.Cli .With(name: LocalizableStrings.OutputOption) .ForwardAs(o => $"/p:PublishDir={o.Arguments.Single()}")), CommonOptions.ConfigurationOption(), + Create.Option( "--filter", LocalizableStrings.FilterProjOptionDescription, Accept.ExactlyOneArgument() diff --git a/src/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/dotnet/commands/dotnet-test/TestCommandParser.cs index e35feb0ec..f707ce502 100644 --- a/src/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -11,35 +11,35 @@ namespace Microsoft.DotNet.Cli Create.Command( "test", LocalizableStrings.AppFullName, - Accept.ZeroOrMoreArguments, + Accept.ZeroOrMoreArguments(), CommonOptions.HelpOption(), Create.Option( "-s|--settings", LocalizableStrings.CmdSettingsDescription, - Accept.ExactlyOneArgument() + Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdSettingsFile) .ForwardAs(o => $"/p:VSTestSetting={o.Arguments.Single()}")), Create.Option( "-t|--list-tests", LocalizableStrings.CmdListTestsDescription, - Accept.NoArguments + Accept.NoArguments() .ForwardAs(o => "/p:VSTestListTests=true")), Create.Option( "--filter", LocalizableStrings.CmdTestCaseFilterDescription, - Accept.ExactlyOneArgument() + Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdTestCaseFilterExpression) .ForwardAs(o => $"/p:VSTestTestCaseFilter={o.Arguments.Single()}")), Create.Option( "-a|--test-adapter-path", LocalizableStrings.CmdTestAdapterPathDescription, - Accept.ExactlyOneArgument() + Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdTestAdapterPath) .ForwardAs(o => $"/p:VSTestTestAdapterPath={o.Arguments.Single()}")), Create.Option( "-l|--logger", LocalizableStrings.CmdLoggerDescription, - Accept.ExactlyOneArgument() + Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdLoggerOption) .ForwardAs(o => { @@ -52,19 +52,19 @@ namespace Microsoft.DotNet.Cli Create.Option( "-o|--output", LocalizableStrings.CmdOutputDescription, - Accept.ExactlyOneArgument() + Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdOutputDir) .ForwardAs(o => $"/p:OutputPath={o.Arguments.Single()}")), Create.Option( "-d|--diag", LocalizableStrings.CmdPathTologFileDescription, - Accept.ExactlyOneArgument() + Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdPathToLogFile) .ForwardAs(o => $"/p:VSTestDiag={o.Arguments.Single()}")), Create.Option( "--no-build", LocalizableStrings.CmdNoBuildDescription, - Accept.NoArguments + Accept.NoArguments() .ForwardAs(o => "/p:VSTestNoBuild=true")), CommonOptions.VerbosityOption()); From 6e3a55e872c64f6126c0a42f210ef8da7a3007f4 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Fri, 10 Mar 2017 18:21:58 -0800 Subject: [PATCH 055/149] update CliCommandLine version --- build/DependencyVersions.props | 2 +- src/dotnet/dotnet.csproj | 2 +- test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/DependencyVersions.props b/build/DependencyVersions.props index 04d447d7f..0757d73f3 100644 --- a/build/DependencyVersions.props +++ b/build/DependencyVersions.props @@ -16,7 +16,7 @@ 1.0.0-beta1-20170209-117 1.0.3 1.0.3 - 0.1.0-alpha-84 + 0.1.0-alpha-88 diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index 549108170..6d9a78c75 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index 994f8c214..ade1e4d1c 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From 7795ce4d6795be8548a445ff1c765a2ae05664bb Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Fri, 10 Mar 2017 18:59:32 -0800 Subject: [PATCH 056/149] Fix build command --- src/dotnet/commands/dotnet-build/BuildCommandParser.cs | 1 + src/dotnet/commands/dotnet-pack/PackCommandParser.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs index c8c402c4f..3c7246d72 100644 --- a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs +++ b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs @@ -13,6 +13,7 @@ namespace Microsoft.DotNet.Cli Create.Command( "build", LocalizableStrings.AppFullName, + Accept.ZeroOrMoreArguments(), CommonOptions.HelpOption(), Create.Option( "-o|--output", diff --git a/src/dotnet/commands/dotnet-pack/PackCommandParser.cs b/src/dotnet/commands/dotnet-pack/PackCommandParser.cs index d1e64e86c..d470d0127 100644 --- a/src/dotnet/commands/dotnet-pack/PackCommandParser.cs +++ b/src/dotnet/commands/dotnet-pack/PackCommandParser.cs @@ -12,7 +12,7 @@ namespace Microsoft.DotNet.Cli public static Command Pack() => Create.Command( "pack", - LocalizableStrings.AppDescription, + LocalizableStrings.AppFullName, Accept.ZeroOrMoreArguments(), CommonOptions.HelpOption(), Create.Option( From 86f26550f1ef7d798349a083de928ffe827d4b2d Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Sat, 11 Mar 2017 11:00:18 -0800 Subject: [PATCH 057/149] R: fix spelling --- src/dotnet/commands/dotnet-test/Program.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dotnet/commands/dotnet-test/Program.cs b/src/dotnet/commands/dotnet-test/Program.cs index 7c0bff1b7..24b69cc9a 100644 --- a/src/dotnet/commands/dotnet-test/Program.cs +++ b/src/dotnet/commands/dotnet-test/Program.cs @@ -46,7 +46,7 @@ namespace Microsoft.DotNet.Tools.Test var runSettingsOptions = result.UnparsedTokens - .Select(t => GetSemiColonEsacpedstring(t)); + .Select(GetSemiColonEscapedString); if (runSettingsOptions.Any()) { @@ -76,7 +76,7 @@ namespace Microsoft.DotNet.Tools.Test return cmd.Execute(); } - private static string GetSemiColonEsacpedstring(string arg) + private static string GetSemiColonEscapedString(string arg) { if (arg.IndexOf(";") != -1) { @@ -93,7 +93,7 @@ namespace Microsoft.DotNet.Tools.Test foreach (string arg in args) { - array[counter++] = GetSemiColonEsacpedstring(arg); + array[counter++] = GetSemiColonEscapedString(arg); } return array; From 5c4db56d3b2a0b3368eab0d67bf54ae9c2c3ae6a Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Sat, 11 Mar 2017 11:47:04 -0800 Subject: [PATCH 058/149] correct arguments for dotnet sln commands --- src/dotnet/commands/dotnet-sln/Program.cs | 18 ++++++++-- .../commands/dotnet-sln/SlnCommandParser.cs | 33 ++++++++++--------- src/dotnet/commands/dotnet-sln/add/Program.cs | 4 +-- .../commands/dotnet-sln/list/Program.cs | 4 +-- .../commands/dotnet-sln/remove/Program.cs | 4 +-- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/dotnet/commands/dotnet-sln/Program.cs b/src/dotnet/commands/dotnet-sln/Program.cs index 484f20aec..2aea1f1b6 100644 --- a/src/dotnet/commands/dotnet-sln/Program.cs +++ b/src/dotnet/commands/dotnet-sln/Program.cs @@ -22,9 +22,21 @@ namespace Microsoft.DotNet.Tools.Sln internal override Dictionary> SubCommands => new Dictionary> { - { "add", o => new AddProjectToSolutionCommand(o) }, - { "list", o => new ListProjectsInSolutionCommand(o) }, - { "remove", o => new RemoveProjectFromSolutionCommand(o) } + ["add"] = + sln => new AddProjectToSolutionCommand( + sln["add"], + sln.Value()), + + ["list"] = + sln => new ListProjectsInSolutionCommand( + sln["list"], + sln.Value()), + + ["remove"] = + sln => + new RemoveProjectFromSolutionCommand( + sln["remove"], + sln.Value()) }; public static int Run(string[] args) diff --git a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs index 18b244ddf..0fb550859 100644 --- a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs +++ b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs @@ -8,20 +8,23 @@ namespace Microsoft.DotNet.Cli internal static class SlnCommandParser { public static Command Sln() => - Create.Command("sln", - ".NET modify solution file command", - CommonOptions.HelpOption(), - Create.Command("add", - ".NET Add project(s) to a solution file Command", - Accept.ExactlyOneArgument() - .With(name: "SLN_FILE"), - CommonOptions.HelpOption()), - Create.Command("list", - "List all projects in the solution.", - Accept.ExactlyOneArgument() - .With(name: "SLN_FILE"), - CommonOptions.HelpOption()), - Create.Command("remove", - "Remove the specified project(s) from the solution. The project is not impacted.")); + Create.Command( + "sln", + ".NET modify solution file command", + Accept.ExactlyOneArgument() + .DefaultToCurrentDirectory(), + CommonOptions.HelpOption(), + Create.Command("add", + ".NET Add project(s) to a solution file Command", + Accept.ExactlyOneArgument() + .With(name: "SLN_FILE"), + CommonOptions.HelpOption()), + Create.Command("list", + "List all projects in the solution.", + Accept.ExactlyOneArgument() + .With(name: "SLN_FILE"), + CommonOptions.HelpOption()), + Create.Command("remove", + "Remove the specified project(s) from the solution. The project is not impacted.")); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-sln/add/Program.cs b/src/dotnet/commands/dotnet-sln/add/Program.cs index c5d23ff84..18bff60db 100644 --- a/src/dotnet/commands/dotnet-sln/add/Program.cs +++ b/src/dotnet/commands/dotnet-sln/add/Program.cs @@ -17,7 +17,7 @@ namespace Microsoft.DotNet.Tools.Sln.Add private readonly AppliedOption _appliedCommand; private readonly string _fileOrDirectory; - public AddProjectToSolutionCommand(AppliedOption appliedCommand) + public AddProjectToSolutionCommand(AppliedOption appliedCommand, string fileOrDirectory) { if (appliedCommand == null) { @@ -25,7 +25,7 @@ namespace Microsoft.DotNet.Tools.Sln.Add } _appliedCommand = appliedCommand; - _fileOrDirectory = appliedCommand.Arguments.Single(); + _fileOrDirectory = fileOrDirectory; } public override int Execute() diff --git a/src/dotnet/commands/dotnet-sln/list/Program.cs b/src/dotnet/commands/dotnet-sln/list/Program.cs index a82bc2f87..8b699caee 100644 --- a/src/dotnet/commands/dotnet-sln/list/Program.cs +++ b/src/dotnet/commands/dotnet-sln/list/Program.cs @@ -15,13 +15,13 @@ namespace Microsoft.DotNet.Tools.Sln.List { private readonly string _fileOrDirectory; - public ListProjectsInSolutionCommand(AppliedOption appliedCommand) + public ListProjectsInSolutionCommand(AppliedOption appliedCommand, string fileOrDirectory) { if (appliedCommand == null) { throw new ArgumentNullException(nameof(appliedCommand)); } - _fileOrDirectory = appliedCommand.Arguments.Single(); + _fileOrDirectory = fileOrDirectory; } public override int Execute() diff --git a/src/dotnet/commands/dotnet-sln/remove/Program.cs b/src/dotnet/commands/dotnet-sln/remove/Program.cs index 6327e2181..914322d18 100644 --- a/src/dotnet/commands/dotnet-sln/remove/Program.cs +++ b/src/dotnet/commands/dotnet-sln/remove/Program.cs @@ -17,7 +17,7 @@ namespace Microsoft.DotNet.Tools.Sln.Remove private readonly AppliedOption _appliedCommand; private readonly string _fileOrDirectory; - public RemoveProjectFromSolutionCommand(AppliedOption appliedCommand) + public RemoveProjectFromSolutionCommand(AppliedOption appliedCommand, string fileOrDirectory) { if (appliedCommand == null) { @@ -30,7 +30,7 @@ namespace Microsoft.DotNet.Tools.Sln.Remove } _appliedCommand = appliedCommand; - _fileOrDirectory = appliedCommand.Arguments.Single(); + _fileOrDirectory = fileOrDirectory; } public override int Execute() From a6c2b6c9f68f9f2e7bb74f20f32c877894534422 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Sun, 12 Mar 2017 15:06:34 -0700 Subject: [PATCH 059/149] update CliCommandLine, other code changes --- src/Microsoft.DotNet.Cli.Utils/PathUtility.cs | 5 ++++- src/dotnet/CommonOptions.cs | 21 +++++++++++++++++++ src/dotnet/ParseResultExtensions.cs | 2 +- src/dotnet/Parser.cs | 3 ++- src/dotnet/commands/dotnet-add/Program.cs | 21 ++++++++----------- .../dotnet-add/dotnet-add-package/Program.cs | 19 ++++++++++------- .../dotnet-add-reference/Program.cs | 9 +++++++- .../commands/dotnet-complete/ParseCommand.cs | 15 +++++++++++-- .../commands/dotnet-sln/SlnCommandParser.cs | 10 ++++----- src/dotnet/dotnet.csproj | 2 +- test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 11 files changed, 77 insertions(+), 32 deletions(-) diff --git a/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs b/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs index 74d418ffa..cbbc0d401 100644 --- a/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs +++ b/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs @@ -287,7 +287,7 @@ namespace Microsoft.DotNet.Tools.Common return result; } - public static bool HasExtension(string filePath, string extension) + public static bool HasExtension(this string filePath, string extension) { var comparison = StringComparison.Ordinal; @@ -335,5 +335,8 @@ namespace Microsoft.DotNet.Tools.Common notExisting.Select(p => string.Format(pathDoesNotExistLocalizedFormatString, p)))); } } + + public static bool IsDirectory(this string path) => + File.GetAttributes(path).HasFlag(FileAttributes.Directory); } } diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index d58dc53f6..67df7f4e8 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Linq; using Microsoft.DotNet.Cli.CommandLine; @@ -63,5 +64,25 @@ namespace Microsoft.DotNet.Cli public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory())); + + public static ArgumentsRule ExistingSlnFileOrDirectoryOnly( + this ArgumentsRule rule) => + rule + .ExistingFilesOnly() + .And(new ArgumentsRule(o => + { + foreach (var path in o.Arguments) + { + if (path.HasExtension(".sln") || + path.IsDirectory()) + { + continue; + } + + return $"Specified path '{path}' is not a directory or solution file."; + } + + return null; + })); } } \ No newline at end of file diff --git a/src/dotnet/ParseResultExtensions.cs b/src/dotnet/ParseResultExtensions.cs index eda1a5590..211dd8749 100644 --- a/src/dotnet/ParseResultExtensions.cs +++ b/src/dotnet/ParseResultExtensions.cs @@ -14,7 +14,7 @@ namespace Microsoft.DotNet.Cli public static void ShowHelpIfRequested(this ParseResult parseResult) { - if (parseResult.AppliedOptions.Any(o => o.HasOption("help"))) + if (parseResult.HasOption("help")) { // NOTE: this is a temporary stage in refactoring toward the ClicCommandLineParser being used at the CLI entry point. throw new HelpException(parseResult.Command().HelpView()); diff --git a/src/dotnet/Parser.cs b/src/dotnet/Parser.cs index 310d08c10..ebfe1a8db 100644 --- a/src/dotnet/Parser.cs +++ b/src/dotnet/Parser.cs @@ -33,6 +33,7 @@ namespace Microsoft.DotNet.Cli CompleteCommandParser.Complete(), CommonOptions.HelpOption(), Create.Option("--info", ""), - Create.Option("-d", ""))); + Create.Option("-d", ""), + Create.Option("--debug", ""))); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-add/Program.cs b/src/dotnet/commands/dotnet-add/Program.cs index 25fe203ea..c3698dfe7 100644 --- a/src/dotnet/commands/dotnet-add/Program.cs +++ b/src/dotnet/commands/dotnet-add/Program.cs @@ -22,18 +22,15 @@ namespace Microsoft.DotNet.Tools.Add internal override Dictionary> SubCommands => new Dictionary> { - { - "reference", - add => new AddProjectToProjectReferenceCommand( - add["reference"], - add.Value()) - }, - { - "package", - add => new AddPackageReferenceCommand( - add["package"], - add.Value()) - } + ["reference"] = + add => new AddProjectToProjectReferenceCommand( + add["reference"], + add.Value()), + + ["package"] = + add => new AddPackageReferenceCommand( + add["package"], + add.Value()) }; public static int Run(string[] args) diff --git a/src/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs b/src/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs index a5ccd858b..2ebaf833f 100644 --- a/src/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs +++ b/src/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs @@ -20,17 +20,22 @@ namespace Microsoft.DotNet.Tools.Add.PackageReference private readonly string _packageId; private readonly string _fileOrDirectory; - public AddPackageReferenceCommand(AppliedOption appliedCommand, string fileOrDirectory) + public AddPackageReferenceCommand( + AppliedOption appliedCommand, + string fileOrDirectory) { + if (appliedCommand == null) + { + throw new ArgumentNullException(nameof(appliedCommand)); + } + if (fileOrDirectory == null) + { + throw new ArgumentNullException(nameof(fileOrDirectory)); + } + _appliedCommand = appliedCommand; _fileOrDirectory = fileOrDirectory; _packageId = appliedCommand.Value(); - - - if ( string.IsNullOrWhiteSpace(_packageId) || _appliedCommand.Arguments.Count > 1) - { - throw new GracefulException(LocalizableStrings.SpecifyExactlyOnePackageReference); - } } public override int Execute() diff --git a/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs b/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs index a1159ed23..b6cce249a 100644 --- a/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs +++ b/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs @@ -20,12 +20,19 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference private readonly AppliedOption _appliedCommand; private readonly string _fileOrDirectory; - public AddProjectToProjectReferenceCommand(AppliedOption appliedCommand, string fileOrDirectory) + public AddProjectToProjectReferenceCommand( + AppliedOption appliedCommand, + string fileOrDirectory) { if (appliedCommand == null) { throw new ArgumentNullException(nameof(appliedCommand)); } + if (fileOrDirectory == null) + { + throw new ArgumentNullException(nameof(fileOrDirectory)); + } + _appliedCommand = appliedCommand; _fileOrDirectory = fileOrDirectory; } diff --git a/src/dotnet/commands/dotnet-complete/ParseCommand.cs b/src/dotnet/commands/dotnet-complete/ParseCommand.cs index c5fc76d6c..3fc2b1be7 100644 --- a/src/dotnet/commands/dotnet-complete/ParseCommand.cs +++ b/src/dotnet/commands/dotnet-complete/ParseCommand.cs @@ -11,11 +11,22 @@ namespace Microsoft.DotNet.Cli { DebugHelper.HandleDebugSwitch(ref args); - var resultOfParsingArg = + var result = Parser.Instance.Parse( args.Single()); - Console.WriteLine(resultOfParsingArg.Diagram()); + Console.WriteLine(result.Diagram()); + + if (result.Errors.Any()) + { + Console.WriteLine(); + Console.WriteLine("ERRORS"); + Console.WriteLine(); + foreach (var error in result.Errors) + { + Console.WriteLine($"[{error?.Option?.Name ?? "???"}] {error.Message}"); + } + } return 0; } diff --git a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs index 0fb550859..684809e3e 100644 --- a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs +++ b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs @@ -12,19 +12,19 @@ namespace Microsoft.DotNet.Cli "sln", ".NET modify solution file command", Accept.ExactlyOneArgument() + .ExistingSlnFileOrDirectoryOnly() .DefaultToCurrentDirectory(), CommonOptions.HelpOption(), Create.Command("add", ".NET Add project(s) to a solution file Command", - Accept.ExactlyOneArgument() - .With(name: "SLN_FILE"), + Accept.OneOrMoreArguments(), CommonOptions.HelpOption()), Create.Command("list", "List all projects in the solution.", - Accept.ExactlyOneArgument() - .With(name: "SLN_FILE"), + Accept.OneOrMoreArguments(), CommonOptions.HelpOption()), Create.Command("remove", - "Remove the specified project(s) from the solution. The project is not impacted.")); + "Remove the specified project(s) from the solution. The project is not impacted.", + Accept.OneOrMoreArguments())); } } \ No newline at end of file diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index 6d9a78c75..a00b7a7a8 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index ade1e4d1c..51ec7ed2d 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From d3143b779f399e9be37d98d69b9b0c6cec25a3ef Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Sun, 12 Mar 2017 16:48:59 -0700 Subject: [PATCH 060/149] stop writing ParseResult.Diagram to output --- src/dotnet/DotNetTopLevelCommandBase.cs | 2 -- src/dotnet/commands/dotnet-build/BuildCommand.cs | 2 -- src/dotnet/commands/dotnet-cache/Program.cs | 2 -- src/dotnet/commands/dotnet-clean/Program.cs | 2 -- src/dotnet/commands/dotnet-migrate/Program.cs | 2 -- src/dotnet/commands/dotnet-pack/PackCommand.cs | 2 -- src/dotnet/commands/dotnet-publish/Program.cs | 2 -- src/dotnet/commands/dotnet-restore/Program.cs | 2 -- src/dotnet/commands/dotnet-run/Program.cs | 2 -- src/dotnet/commands/dotnet-test/Program.cs | 2 -- test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs | 2 -- test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs | 4 ---- test/dotnet.Tests/ParserTests/RestoreParserTests.cs | 4 ---- 13 files changed, 30 deletions(-) diff --git a/src/dotnet/DotNetTopLevelCommandBase.cs b/src/dotnet/DotNetTopLevelCommandBase.cs index 319c66523..f1469da2b 100644 --- a/src/dotnet/DotNetTopLevelCommandBase.cs +++ b/src/dotnet/DotNetTopLevelCommandBase.cs @@ -25,8 +25,6 @@ namespace Microsoft.DotNet.Cli var result = parser.ParseFrom($"dotnet {CommandName}", args); - Reporter.Output.WriteLine(result.Diagram()); - result.ShowHelpIfRequested(); var subcommandName = result.Command().Name; diff --git a/src/dotnet/commands/dotnet-build/BuildCommand.cs b/src/dotnet/commands/dotnet-build/BuildCommand.cs index 3ecd6eeba..aef57ebb4 100644 --- a/src/dotnet/commands/dotnet-build/BuildCommand.cs +++ b/src/dotnet/commands/dotnet-build/BuildCommand.cs @@ -25,8 +25,6 @@ namespace Microsoft.DotNet.Tools.Build var result = parser.ParseFrom("dotnet build", args); - Reporter.Output.WriteLine(result.Diagram()); - result.ShowHelpIfRequested(); var appliedBuildOptions = result["dotnet"]["build"]; diff --git a/src/dotnet/commands/dotnet-cache/Program.cs b/src/dotnet/commands/dotnet-cache/Program.cs index 2a1a6ec19..3eb78e3da 100644 --- a/src/dotnet/commands/dotnet-cache/Program.cs +++ b/src/dotnet/commands/dotnet-cache/Program.cs @@ -29,8 +29,6 @@ namespace Microsoft.DotNet.Tools.Cache var result = parser.ParseFrom("dotnet cache", args); - Reporter.Output.WriteLine(result.Diagram()); - result.ShowHelpIfRequested(); var appliedBuildOptions = result["dotnet"]["cache"]; diff --git a/src/dotnet/commands/dotnet-clean/Program.cs b/src/dotnet/commands/dotnet-clean/Program.cs index 5963d7048..bcedf9501 100644 --- a/src/dotnet/commands/dotnet-clean/Program.cs +++ b/src/dotnet/commands/dotnet-clean/Program.cs @@ -25,8 +25,6 @@ namespace Microsoft.DotNet.Tools.Clean var result = parser.ParseFrom("dotnet clean", args); - Reporter.Output.WriteLine(result.Diagram()); - result.ShowHelpIfRequested(); var parsedClean = result["dotnet"]["clean"]; diff --git a/src/dotnet/commands/dotnet-migrate/Program.cs b/src/dotnet/commands/dotnet-migrate/Program.cs index 7c0fcb635..ce406290c 100644 --- a/src/dotnet/commands/dotnet-migrate/Program.cs +++ b/src/dotnet/commands/dotnet-migrate/Program.cs @@ -20,8 +20,6 @@ namespace Microsoft.DotNet.Tools.Migrate var result = parser.ParseFrom("dotnet migrate", args); - Reporter.Output.WriteLine(result.Diagram()); - result.ShowHelpIfRequested(); return result["dotnet"]["migrate"].Value(); diff --git a/src/dotnet/commands/dotnet-pack/PackCommand.cs b/src/dotnet/commands/dotnet-pack/PackCommand.cs index 00b8e2d68..37f4dbe61 100644 --- a/src/dotnet/commands/dotnet-pack/PackCommand.cs +++ b/src/dotnet/commands/dotnet-pack/PackCommand.cs @@ -24,8 +24,6 @@ namespace Microsoft.DotNet.Tools.Pack var result = parser.ParseFrom("dotnet pack", args); - Reporter.Output.WriteLine(result.Diagram()); - result.ShowHelpIfRequested(); var parsedPack = result["dotnet"]["pack"]; diff --git a/src/dotnet/commands/dotnet-publish/Program.cs b/src/dotnet/commands/dotnet-publish/Program.cs index 6ba893605..8a556f5fa 100644 --- a/src/dotnet/commands/dotnet-publish/Program.cs +++ b/src/dotnet/commands/dotnet-publish/Program.cs @@ -27,8 +27,6 @@ namespace Microsoft.DotNet.Tools.Publish var result = parser.ParseFrom("dotnet publish", args); - Reporter.Output.WriteLine(result.Diagram()); - result.ShowHelpIfRequested(); msbuildArgs.Add("/t:Publish"); diff --git a/src/dotnet/commands/dotnet-restore/Program.cs b/src/dotnet/commands/dotnet-restore/Program.cs index 1d34a40e1..01b456109 100644 --- a/src/dotnet/commands/dotnet-restore/Program.cs +++ b/src/dotnet/commands/dotnet-restore/Program.cs @@ -29,8 +29,6 @@ namespace Microsoft.DotNet.Tools.Restore var result = parser.ParseFrom("dotnet restore", args); - Reporter.Output.WriteLine(result.Diagram()); - result.ShowHelpIfRequested(); var parsedRestore = result["dotnet"]["restore"]; diff --git a/src/dotnet/commands/dotnet-run/Program.cs b/src/dotnet/commands/dotnet-run/Program.cs index a795b455b..016aa5422 100644 --- a/src/dotnet/commands/dotnet-run/Program.cs +++ b/src/dotnet/commands/dotnet-run/Program.cs @@ -17,8 +17,6 @@ namespace Microsoft.DotNet.Tools.Run var result = parser.ParseFrom("dotnet run", args); - Reporter.Output.WriteLine(result.Diagram()); - result.ShowHelpIfRequested(); return result["dotnet"]["run"].Value(); diff --git a/src/dotnet/commands/dotnet-test/Program.cs b/src/dotnet/commands/dotnet-test/Program.cs index 24b69cc9a..563b86be3 100644 --- a/src/dotnet/commands/dotnet-test/Program.cs +++ b/src/dotnet/commands/dotnet-test/Program.cs @@ -34,8 +34,6 @@ namespace Microsoft.DotNet.Tools.Test var result = parser.ParseFrom("dotnet test", args); - Reporter.Output.WriteLine(result.Diagram()); - result.ShowHelpIfRequested(); var parsedTest = result["dotnet"]["test"]; diff --git a/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs index f577f827f..61088797c 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetPublishInvocation.cs @@ -71,8 +71,6 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests var result = parser.ParseFrom("dotnet publish", args); - output.WriteLine(result.Diagram()); - result["dotnet"]["publish"] .OptionValuesToBeForwarded() .Should() diff --git a/test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs b/test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs index 68121383d..2aa5beec8 100644 --- a/test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs +++ b/test/dotnet.Tests/ParserTests/AddReferenceParserTests.cs @@ -29,8 +29,6 @@ namespace Microsoft.DotNet.Tests.ParserTests var result = command.Parse("dotnet add reference my.csproj"); - output.WriteLine(result.Diagram()); - result["dotnet"]["add"] .Arguments .Should() @@ -45,8 +43,6 @@ namespace Microsoft.DotNet.Tests.ParserTests var result = command.Parse("dotnet add reference"); - output.WriteLine(result.Diagram()); - result .Errors .Select(e => e.Message) diff --git a/test/dotnet.Tests/ParserTests/RestoreParserTests.cs b/test/dotnet.Tests/ParserTests/RestoreParserTests.cs index cb3128cc0..48a566b92 100644 --- a/test/dotnet.Tests/ParserTests/RestoreParserTests.cs +++ b/test/dotnet.Tests/ParserTests/RestoreParserTests.cs @@ -26,8 +26,6 @@ namespace Microsoft.DotNet.Tests.ParserTests var result = parser.Parse(@"dotnet restore .\some.csproj --packages c:\.nuget\packages /p:SkipInvalidConfigurations=true"); - output.WriteLine(result.Diagram()); - result["dotnet"]["restore"] .Arguments .Should() @@ -41,8 +39,6 @@ namespace Microsoft.DotNet.Tests.ParserTests var result = parser.Parse(@"dotnet restore --packages c:\.nuget\packages /p:SkipInvalidConfigurations=true"); - output.WriteLine(result.Diagram()); - result["dotnet"]["restore"] .Arguments .Should() From 8a0f37ed79eee7a685121a79571048c5d8f58fd8 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 13 Mar 2017 08:25:21 -0700 Subject: [PATCH 061/149] bump CliCommandLine version --- src/dotnet/dotnet.csproj | 2 +- test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index a00b7a7a8..d051508bd 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index 51ec7ed2d..30f84e3a2 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From 02ac115f2bcb775173e5536daee54e8a79dc8bd3 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 13 Mar 2017 09:03:14 -0700 Subject: [PATCH 062/149] new CliCommandLine version with help fix --- src/dotnet/ParseResultExtensions.cs | 2 +- src/dotnet/commands/dotnet-add/AddCommandParser.cs | 4 +++- src/dotnet/dotnet.csproj | 2 +- test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/dotnet/ParseResultExtensions.cs b/src/dotnet/ParseResultExtensions.cs index 211dd8749..f19d0cd94 100644 --- a/src/dotnet/ParseResultExtensions.cs +++ b/src/dotnet/ParseResultExtensions.cs @@ -14,7 +14,7 @@ namespace Microsoft.DotNet.Cli public static void ShowHelpIfRequested(this ParseResult parseResult) { - if (parseResult.HasOption("help")) + if (parseResult.AppliedCommand().HasOption("help")) { // NOTE: this is a temporary stage in refactoring toward the ClicCommandLineParser being used at the CLI entry point. throw new HelpException(parseResult.Command().HelpView()); diff --git a/src/dotnet/commands/dotnet-add/AddCommandParser.cs b/src/dotnet/commands/dotnet-add/AddCommandParser.cs index fd1ed571d..062a97a11 100644 --- a/src/dotnet/commands/dotnet-add/AddCommandParser.cs +++ b/src/dotnet/commands/dotnet-add/AddCommandParser.cs @@ -18,12 +18,14 @@ namespace Microsoft.DotNet.Cli "add", ".NET Add Command", Accept.ExactlyOneArgument() + .ExistingFilesOnly() .DefaultToCurrentDirectory(), Create.Command( "package", ".NET Add Package reference Command", Accept.ExactlyOneArgument() - .WithSuggestionsFrom(QueryNuGet), CommonOptions.HelpOption(), + .WithSuggestionsFrom(QueryNuGet), + CommonOptions.HelpOption(), Create.Option("-v|--version", "Version for the package to be added.", Accept.ExactlyOneArgument() diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index d051508bd..47e1469c1 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index 30f84e3a2..c224b4234 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From 11b7e7e4498767805fd4bd24817e9a33ca274f8e Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 13 Mar 2017 12:46:39 -0700 Subject: [PATCH 063/149] new CliCommandLine version --- src/dotnet/dotnet.csproj | 2 +- test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index 47e1469c1..2b1c0107b 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index c224b4234..240ad6a01 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From 204d8594bffaa2257b8b1e2cf32efa3bb09846e7 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 13 Mar 2017 13:29:03 -0700 Subject: [PATCH 064/149] throw exception on parse errors --- .../CommandLine/CommandParsingException.cs | 17 ++++++++++------- src/dotnet/CommonOptions.cs | 16 ++++++++++++++++ src/dotnet/DotNetTopLevelCommandBase.cs | 2 +- src/dotnet/ParseResultExtensions.cs | 9 ++++++++- .../commands/dotnet-add/AddCommandParser.cs | 3 ++- .../commands/dotnet-build/BuildCommand.cs | 2 +- src/dotnet/commands/dotnet-cache/Program.cs | 2 +- src/dotnet/commands/dotnet-clean/Program.cs | 2 +- src/dotnet/commands/dotnet-migrate/Program.cs | 2 +- src/dotnet/commands/dotnet-pack/PackCommand.cs | 2 +- src/dotnet/commands/dotnet-publish/Program.cs | 2 +- src/dotnet/commands/dotnet-restore/Program.cs | 2 +- src/dotnet/commands/dotnet-run/Program.cs | 2 +- .../commands/dotnet-sln/SlnCommandParser.cs | 4 ++-- src/dotnet/commands/dotnet-test/Program.cs | 2 +- 15 files changed, 48 insertions(+), 21 deletions(-) diff --git a/src/dotnet/CommandLine/CommandParsingException.cs b/src/dotnet/CommandLine/CommandParsingException.cs index ef8aaf470..606db5564 100644 --- a/src/dotnet/CommandLine/CommandParsingException.cs +++ b/src/dotnet/CommandLine/CommandParsingException.cs @@ -8,18 +8,21 @@ namespace Microsoft.DotNet.Cli.CommandLine { internal class CommandParsingException : Exception { - private bool _isRequireSubCommandMissing; + private readonly bool _isRequireSubCommandMissing; + + public CommandParsingException(string message) : base(message) + { + Data.Add("CLI_User_Displayed_Exception", true); + } public CommandParsingException( CommandLineApplication command, string message, bool isRequireSubCommandMissing = false) - : base(message) + : this(message) { Command = command; _isRequireSubCommandMissing = isRequireSubCommandMissing; - - Data.Add("CLI_User_Displayed_Exception", true); } public CommandLineApplication Command { get; } @@ -29,9 +32,9 @@ namespace Microsoft.DotNet.Cli.CommandLine get { return _isRequireSubCommandMissing - ? CommonLocalizableStrings.RequiredCommandNotPassed - : base.Message; + ? CommonLocalizableStrings.RequiredCommandNotPassed + : base.Message; } } } -} +} \ No newline at end of file diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index 67df7f4e8..277e90211 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -65,6 +65,22 @@ namespace Microsoft.DotNet.Cli public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory())); + public static ArgumentsRule ExistingFilesOnly( + this ArgumentsRule rule) => + rule.And(new ArgumentsRule(o => + { + foreach (var filePath in o.Arguments) + { + if (!File.Exists(filePath) && + !Directory.Exists(filePath)) + { + return $"File not found: {filePath}"; + } + } + + return null; + })); + public static ArgumentsRule ExistingSlnFileOrDirectoryOnly( this ArgumentsRule rule) => rule diff --git a/src/dotnet/DotNetTopLevelCommandBase.cs b/src/dotnet/DotNetTopLevelCommandBase.cs index f1469da2b..17cdb5e30 100644 --- a/src/dotnet/DotNetTopLevelCommandBase.cs +++ b/src/dotnet/DotNetTopLevelCommandBase.cs @@ -25,7 +25,7 @@ namespace Microsoft.DotNet.Cli var result = parser.ParseFrom($"dotnet {CommandName}", args); - result.ShowHelpIfRequested(); + result.ShowHelpOrErrorIfAppropriate(); var subcommandName = result.Command().Name; diff --git a/src/dotnet/ParseResultExtensions.cs b/src/dotnet/ParseResultExtensions.cs index f19d0cd94..d98991fa4 100644 --- a/src/dotnet/ParseResultExtensions.cs +++ b/src/dotnet/ParseResultExtensions.cs @@ -12,8 +12,15 @@ namespace Microsoft.DotNet.Cli public static void ShowHelp(this ParseResult parseResult) => Console.WriteLine(parseResult.Command().HelpView()); - public static void ShowHelpIfRequested(this ParseResult parseResult) + public static void ShowHelpOrErrorIfAppropriate(this ParseResult parseResult) { + if (parseResult.Errors.Any()) + { + throw new CommandParsingException( + string.Join(Environment.NewLine, + parseResult.Errors.Select(e => e.Message))); + } + if (parseResult.AppliedCommand().HasOption("help")) { // NOTE: this is a temporary stage in refactoring toward the ClicCommandLineParser being used at the CLI entry point. diff --git a/src/dotnet/commands/dotnet-add/AddCommandParser.cs b/src/dotnet/commands/dotnet-add/AddCommandParser.cs index 062a97a11..dcc48737a 100644 --- a/src/dotnet/commands/dotnet-add/AddCommandParser.cs +++ b/src/dotnet/commands/dotnet-add/AddCommandParser.cs @@ -8,6 +8,7 @@ using System.Net.Http; using System.Threading; using Microsoft.DotNet.Cli.CommandLine; using Newtonsoft.Json.Linq; +using LocalizableStrings = Microsoft.DotNet.Tools.Add.PackageReference.LocalizableStrings; namespace Microsoft.DotNet.Cli { @@ -23,7 +24,7 @@ namespace Microsoft.DotNet.Cli Create.Command( "package", ".NET Add Package reference Command", - Accept.ExactlyOneArgument() + Accept.ExactlyOneArgument(errorMessage: o => LocalizableStrings.SpecifyExactlyOnePackageReference) .WithSuggestionsFrom(QueryNuGet), CommonOptions.HelpOption(), Create.Option("-v|--version", diff --git a/src/dotnet/commands/dotnet-build/BuildCommand.cs b/src/dotnet/commands/dotnet-build/BuildCommand.cs index aef57ebb4..691d5ef21 100644 --- a/src/dotnet/commands/dotnet-build/BuildCommand.cs +++ b/src/dotnet/commands/dotnet-build/BuildCommand.cs @@ -25,7 +25,7 @@ namespace Microsoft.DotNet.Tools.Build var result = parser.ParseFrom("dotnet build", args); - result.ShowHelpIfRequested(); + result.ShowHelpOrErrorIfAppropriate(); var appliedBuildOptions = result["dotnet"]["build"]; diff --git a/src/dotnet/commands/dotnet-cache/Program.cs b/src/dotnet/commands/dotnet-cache/Program.cs index 3eb78e3da..64d70a169 100644 --- a/src/dotnet/commands/dotnet-cache/Program.cs +++ b/src/dotnet/commands/dotnet-cache/Program.cs @@ -29,7 +29,7 @@ namespace Microsoft.DotNet.Tools.Cache var result = parser.ParseFrom("dotnet cache", args); - result.ShowHelpIfRequested(); + result.ShowHelpOrErrorIfAppropriate(); var appliedBuildOptions = result["dotnet"]["cache"]; diff --git a/src/dotnet/commands/dotnet-clean/Program.cs b/src/dotnet/commands/dotnet-clean/Program.cs index bcedf9501..e07ec356d 100644 --- a/src/dotnet/commands/dotnet-clean/Program.cs +++ b/src/dotnet/commands/dotnet-clean/Program.cs @@ -25,7 +25,7 @@ namespace Microsoft.DotNet.Tools.Clean var result = parser.ParseFrom("dotnet clean", args); - result.ShowHelpIfRequested(); + result.ShowHelpOrErrorIfAppropriate(); var parsedClean = result["dotnet"]["clean"]; diff --git a/src/dotnet/commands/dotnet-migrate/Program.cs b/src/dotnet/commands/dotnet-migrate/Program.cs index ce406290c..72001edd7 100644 --- a/src/dotnet/commands/dotnet-migrate/Program.cs +++ b/src/dotnet/commands/dotnet-migrate/Program.cs @@ -20,7 +20,7 @@ namespace Microsoft.DotNet.Tools.Migrate var result = parser.ParseFrom("dotnet migrate", args); - result.ShowHelpIfRequested(); + result.ShowHelpOrErrorIfAppropriate(); return result["dotnet"]["migrate"].Value(); } diff --git a/src/dotnet/commands/dotnet-pack/PackCommand.cs b/src/dotnet/commands/dotnet-pack/PackCommand.cs index 37f4dbe61..2821c23d8 100644 --- a/src/dotnet/commands/dotnet-pack/PackCommand.cs +++ b/src/dotnet/commands/dotnet-pack/PackCommand.cs @@ -24,7 +24,7 @@ namespace Microsoft.DotNet.Tools.Pack var result = parser.ParseFrom("dotnet pack", args); - result.ShowHelpIfRequested(); + result.ShowHelpOrErrorIfAppropriate(); var parsedPack = result["dotnet"]["pack"]; diff --git a/src/dotnet/commands/dotnet-publish/Program.cs b/src/dotnet/commands/dotnet-publish/Program.cs index 8a556f5fa..8c8fbc9cf 100644 --- a/src/dotnet/commands/dotnet-publish/Program.cs +++ b/src/dotnet/commands/dotnet-publish/Program.cs @@ -27,7 +27,7 @@ namespace Microsoft.DotNet.Tools.Publish var result = parser.ParseFrom("dotnet publish", args); - result.ShowHelpIfRequested(); + result.ShowHelpOrErrorIfAppropriate(); msbuildArgs.Add("/t:Publish"); diff --git a/src/dotnet/commands/dotnet-restore/Program.cs b/src/dotnet/commands/dotnet-restore/Program.cs index 01b456109..1e1ff728d 100644 --- a/src/dotnet/commands/dotnet-restore/Program.cs +++ b/src/dotnet/commands/dotnet-restore/Program.cs @@ -29,7 +29,7 @@ namespace Microsoft.DotNet.Tools.Restore var result = parser.ParseFrom("dotnet restore", args); - result.ShowHelpIfRequested(); + result.ShowHelpOrErrorIfAppropriate(); var parsedRestore = result["dotnet"]["restore"]; diff --git a/src/dotnet/commands/dotnet-run/Program.cs b/src/dotnet/commands/dotnet-run/Program.cs index 016aa5422..6bfaffefa 100644 --- a/src/dotnet/commands/dotnet-run/Program.cs +++ b/src/dotnet/commands/dotnet-run/Program.cs @@ -17,7 +17,7 @@ namespace Microsoft.DotNet.Tools.Run var result = parser.ParseFrom("dotnet run", args); - result.ShowHelpIfRequested(); + result.ShowHelpOrErrorIfAppropriate(); return result["dotnet"]["run"].Value(); } diff --git a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs index 684809e3e..d20cef621 100644 --- a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs +++ b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs @@ -13,7 +13,8 @@ namespace Microsoft.DotNet.Cli ".NET modify solution file command", Accept.ExactlyOneArgument() .ExistingSlnFileOrDirectoryOnly() - .DefaultToCurrentDirectory(), + .DefaultToCurrentDirectory() + .With(name: "SLN_FILE" ), CommonOptions.HelpOption(), Create.Command("add", ".NET Add project(s) to a solution file Command", @@ -21,7 +22,6 @@ namespace Microsoft.DotNet.Cli CommonOptions.HelpOption()), Create.Command("list", "List all projects in the solution.", - Accept.OneOrMoreArguments(), CommonOptions.HelpOption()), Create.Command("remove", "Remove the specified project(s) from the solution. The project is not impacted.", diff --git a/src/dotnet/commands/dotnet-test/Program.cs b/src/dotnet/commands/dotnet-test/Program.cs index 563b86be3..913181a20 100644 --- a/src/dotnet/commands/dotnet-test/Program.cs +++ b/src/dotnet/commands/dotnet-test/Program.cs @@ -34,7 +34,7 @@ namespace Microsoft.DotNet.Tools.Test var result = parser.ParseFrom("dotnet test", args); - result.ShowHelpIfRequested(); + result.ShowHelpOrErrorIfAppropriate(); var parsedTest = result["dotnet"]["test"]; From f5d9cfc79c0c5b25c57ea41324c3af4d5ea16847 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 13 Mar 2017 15:29:39 -0700 Subject: [PATCH 065/149] reverse order of help response vs error response --- src/dotnet/ParseResultExtensions.cs | 12 ++++++------ src/dotnet/commands/dotnet-sln/SlnCommandParser.cs | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/dotnet/ParseResultExtensions.cs b/src/dotnet/ParseResultExtensions.cs index d98991fa4..ea238571e 100644 --- a/src/dotnet/ParseResultExtensions.cs +++ b/src/dotnet/ParseResultExtensions.cs @@ -14,18 +14,18 @@ namespace Microsoft.DotNet.Cli public static void ShowHelpOrErrorIfAppropriate(this ParseResult parseResult) { + if (parseResult.AppliedCommand().HasOption("help")) + { + // NOTE: this is a temporary stage in refactoring toward the ClicCommandLineParser being used at the CLI entry point. + throw new HelpException(parseResult.Command().HelpView()); + } + if (parseResult.Errors.Any()) { throw new CommandParsingException( string.Join(Environment.NewLine, parseResult.Errors.Select(e => e.Message))); } - - if (parseResult.AppliedCommand().HasOption("help")) - { - // NOTE: this is a temporary stage in refactoring toward the ClicCommandLineParser being used at the CLI entry point. - throw new HelpException(parseResult.Command().HelpView()); - } } } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs index d20cef621..090ce9c73 100644 --- a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs +++ b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs @@ -14,7 +14,7 @@ namespace Microsoft.DotNet.Cli Accept.ExactlyOneArgument() .ExistingSlnFileOrDirectoryOnly() .DefaultToCurrentDirectory() - .With(name: "SLN_FILE" ), + .With(name: "SLN_FILE"), CommonOptions.HelpOption(), Create.Command("add", ".NET Add project(s) to a solution file Command", @@ -25,6 +25,7 @@ namespace Microsoft.DotNet.Cli CommonOptions.HelpOption()), Create.Command("remove", "Remove the specified project(s) from the solution. The project is not impacted.", - Accept.OneOrMoreArguments())); + Accept.OneOrMoreArguments(), + CommonOptions.HelpOption())); } } \ No newline at end of file From ace4fe49f67361e719632a1de4b352fed4e673e0 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 13 Mar 2017 16:01:58 -0700 Subject: [PATCH 066/149] new CliCommandLine version --- src/dotnet/dotnet.csproj | 2 +- test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index 2b1c0107b..b5abadf71 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index 240ad6a01..e5c165e23 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From 2c96d8e8b9dba98ae81fcb1d937597a890f659fd Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 13 Mar 2017 20:06:59 -0700 Subject: [PATCH 067/149] throw exceptions for command not found --- src/dotnet/DotNetTopLevelCommandBase.cs | 13 +++++++++---- src/dotnet/HelpException.cs | 8 +------- src/dotnet/Program.cs | 2 +- src/dotnet/commands/dotnet-sln/SlnCommandParser.cs | 1 - 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/dotnet/DotNetTopLevelCommandBase.cs b/src/dotnet/DotNetTopLevelCommandBase.cs index 17cdb5e30..ea5abba13 100644 --- a/src/dotnet/DotNetTopLevelCommandBase.cs +++ b/src/dotnet/DotNetTopLevelCommandBase.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.Tools; namespace Microsoft.DotNet.Cli { @@ -29,14 +30,18 @@ namespace Microsoft.DotNet.Cli var subcommandName = result.Command().Name; - var create = SubCommands[subcommandName]; - - var command = create(result["dotnet"][CommandName]); - try { + var create = SubCommands[subcommandName]; + + var command = create(result["dotnet"][CommandName]); + return command.Execute(); } + catch (KeyNotFoundException e) + { + throw new GracefulException(CommonLocalizableStrings.RequiredCommandNotPassed); + } catch (GracefulException e) { Reporter.Error.WriteLine(e.Message.Red()); diff --git a/src/dotnet/HelpException.cs b/src/dotnet/HelpException.cs index be6427f06..98f2eb6f7 100644 --- a/src/dotnet/HelpException.cs +++ b/src/dotnet/HelpException.cs @@ -9,15 +9,9 @@ namespace Microsoft.DotNet.Cli [Obsolete("This is intended to facilitate refactoring during parser replacement and should not be used after that work is done.")] public class HelpException : Exception { - public HelpException( - string message, - bool isError = false) : base(message) + public HelpException(string message) : base(message) { - IsError = isError; - Data.Add(ExceptionExtensions.CLI_User_Displayed_Exception, true); } - - public bool IsError { get; } } } \ No newline at end of file diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 8cf7f58a2..0fcefae45 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -80,7 +80,7 @@ namespace Microsoft.DotNet.Cli catch (HelpException e) { Reporter.Output.Write(e.Message); - return e.IsError ? 1 : 0; + return 0; } catch (Exception e) when (e.ShouldBeDisplayedAsError()) { diff --git a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs index 090ce9c73..d71c3f3f7 100644 --- a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs +++ b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs @@ -12,7 +12,6 @@ namespace Microsoft.DotNet.Cli "sln", ".NET modify solution file command", Accept.ExactlyOneArgument() - .ExistingSlnFileOrDirectoryOnly() .DefaultToCurrentDirectory() .With(name: "SLN_FILE"), CommonOptions.HelpOption(), From 96683c14215acbf345234e1f0561c626f4ff4623 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 14 Mar 2017 10:33:58 -0700 Subject: [PATCH 068/149] help text updates --- src/dotnet/CommonOptions.cs | 2 +- src/dotnet/commands/dotnet-add/AddCommandParser.cs | 10 +++++++--- .../commands/dotnet-build/BuildCommandParser.cs | 5 ++++- src/dotnet/commands/dotnet-sln/SlnCommandParser.cs | 13 ++++++++++--- .../commands/dotnet-test/TestCommandParser.cs | 4 +++- src/dotnet/dotnet.csproj | 2 +- test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs | 10 ++++------ test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 8 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index 277e90211..fbcbca261 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -18,7 +18,7 @@ namespace Microsoft.DotNet.Cli public static Option VerbosityOption() => Create.Option( "-v|--verbosity", - "Set the verbosity level of the command. Allowed values are q[uiet],�m[inimal],�n[ormal],�d[etailed], and�diag[nostic]", + "Set the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]", Accept.AnyOneOf( "q", "quiet", "m", "minimal", diff --git a/src/dotnet/commands/dotnet-add/AddCommandParser.cs b/src/dotnet/commands/dotnet-add/AddCommandParser.cs index dcc48737a..d178b80c1 100644 --- a/src/dotnet/commands/dotnet-add/AddCommandParser.cs +++ b/src/dotnet/commands/dotnet-add/AddCommandParser.cs @@ -20,12 +20,16 @@ namespace Microsoft.DotNet.Cli ".NET Add Command", Accept.ExactlyOneArgument() .ExistingFilesOnly() - .DefaultToCurrentDirectory(), + .DefaultToCurrentDirectory() + .With(name: "PROJECT", + description: "The project file to operate on. If a file is not specified, the command will search the current directory for one."), Create.Command( "package", ".NET Add Package reference Command", Accept.ExactlyOneArgument(errorMessage: o => LocalizableStrings.SpecifyExactlyOnePackageReference) - .WithSuggestionsFrom(QueryNuGet), + .WithSuggestionsFrom(QueryNuGet) + .With(name: "PACKAGE_NAME", + description: "Package references to add"), CommonOptions.HelpOption(), Create.Option("-v|--version", "Version for the package to be added.", @@ -52,7 +56,7 @@ namespace Microsoft.DotNet.Cli Create.Command( "reference", "Command to add project to project reference", - Accept.OneOrMoreArguments(), + Accept.OneOrMoreArguments(), CommonOptions.HelpOption(), Create.Option("-f|--framework", "Add reference only when targetting a specific framework", diff --git a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs index 3c7246d72..b1a492318 100644 --- a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs +++ b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs @@ -13,7 +13,10 @@ namespace Microsoft.DotNet.Cli Create.Command( "build", LocalizableStrings.AppFullName, - Accept.ZeroOrMoreArguments(), + Accept.ZeroOrMoreArguments() + .With(name: "PROJECT", + description: + "The MSBuild project file to build. If a project file is not specified, MSBuild searches the current working directory for a file that has a file extension that ends in `proj` and uses that file."), CommonOptions.HelpOption(), Create.Option( "-o|--output", diff --git a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs index d71c3f3f7..7fc307ed2 100644 --- a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs +++ b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs @@ -2,6 +2,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Tools; +using LocalizableStrings = Microsoft.DotNet.Tools.Sln.LocalizableStrings; namespace Microsoft.DotNet.Cli { @@ -13,18 +15,23 @@ namespace Microsoft.DotNet.Cli ".NET modify solution file command", Accept.ExactlyOneArgument() .DefaultToCurrentDirectory() - .With(name: "SLN_FILE"), + .With(name: "SLN_FILE", + description: CommonLocalizableStrings.ArgumentsSolutionDescription), CommonOptions.HelpOption(), Create.Command("add", ".NET Add project(s) to a solution file Command", - Accept.OneOrMoreArguments(), + Accept.OneOrMoreArguments() + .With(name: "args", + description: LocalizableStrings.AddSubcommandHelpText), CommonOptions.HelpOption()), Create.Command("list", "List all projects in the solution.", CommonOptions.HelpOption()), Create.Command("remove", "Remove the specified project(s) from the solution. The project is not impacted.", - Accept.OneOrMoreArguments(), + Accept.OneOrMoreArguments() + .With(name: "args", + description: LocalizableStrings.RemoveSubcommandHelpText), CommonOptions.HelpOption())); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/dotnet/commands/dotnet-test/TestCommandParser.cs index f707ce502..b885acf3b 100644 --- a/src/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -11,7 +11,9 @@ namespace Microsoft.DotNet.Cli Create.Command( "test", LocalizableStrings.AppFullName, - Accept.ZeroOrMoreArguments(), + Accept.ZeroOrMoreArguments() + .With(name: LocalizableStrings.CmdArgProject, + description: LocalizableStrings.CmdArgDescription), CommonOptions.HelpOption(), Create.Option( "-s|--settings", diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index b5abadf71..49ebe85be 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs b/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs index cd7b9c38a..9461e59a7 100644 --- a/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs +++ b/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs @@ -17,16 +17,14 @@ namespace Microsoft.DotNet.Cli.Sln.Add.Tests { private string HelpText = @".NET Add project(s) to a solution file Command -Usage: dotnet sln add [options] [args] +Usage: dotnet sln add [options] Arguments: - Solution file to operate on. If not specified, the command will search the current directory for one. + Solution file to operate on. If not specified, the command will search the current directory for one. + Add one or more specified projects to the solution. Options: - -h|--help Show help information - -Additional Arguments: - Add one or more specified projects to the solution. + -h, --help Show help information "; private ITestOutputHelper _output; diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index e5c165e23..13acbe278 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From 898d10cb2d5b781fa54df709c54666f9e73cc3b7 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 14 Mar 2017 11:23:19 -0700 Subject: [PATCH 069/149] help text adjustments for dotnet sln --- src/dotnet/Program.cs | 4 ++-- src/dotnet/commands/dotnet-sln/SlnCommandParser.cs | 7 ++++--- src/dotnet/commands/dotnet-sln/remove/Program.cs | 2 +- test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs | 5 +++-- test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs | 10 ++++------ 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 0fcefae45..983f6507f 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -79,7 +79,7 @@ namespace Microsoft.DotNet.Cli } catch (HelpException e) { - Reporter.Output.Write(e.Message); + Reporter.Output.WriteLine(e.Message); return 0; } catch (Exception e) when (e.ShouldBeDisplayedAsError()) @@ -92,7 +92,7 @@ namespace Microsoft.DotNet.Cli } catch (Exception e) when (!e.ShouldBeDisplayedAsError()) { - Reporter.Output.WriteLine(e.ToString().Red().Bold()); + Reporter.Error.WriteLine(e.ToString().Red().Bold()); return 1; } diff --git a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs index 7fc307ed2..5a38fe68b 100644 --- a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs +++ b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs @@ -25,13 +25,14 @@ namespace Microsoft.DotNet.Cli description: LocalizableStrings.AddSubcommandHelpText), CommonOptions.HelpOption()), Create.Command("list", - "List all projects in the solution.", + ".NET List project(s) in a solution file Command", CommonOptions.HelpOption()), Create.Command("remove", - "Remove the specified project(s) from the solution. The project is not impacted.", - Accept.OneOrMoreArguments() + ".NET Remove project(s) from a solution file Command", + Accept.OneOrMoreArguments(o => CommonLocalizableStrings.SpecifyAtLeastOneProjectToRemove) .With(name: "args", description: LocalizableStrings.RemoveSubcommandHelpText), CommonOptions.HelpOption())); + } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-sln/remove/Program.cs b/src/dotnet/commands/dotnet-sln/remove/Program.cs index 914322d18..c2c6cfd4d 100644 --- a/src/dotnet/commands/dotnet-sln/remove/Program.cs +++ b/src/dotnet/commands/dotnet-sln/remove/Program.cs @@ -24,7 +24,7 @@ namespace Microsoft.DotNet.Tools.Sln.Remove throw new ArgumentNullException(nameof(appliedCommand)); } - if (_appliedCommand.Arguments.Count == 0) + if (appliedCommand.Arguments.Count == 0) { throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneProjectToRemove); } diff --git a/test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs b/test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs index aa032eed8..f8f785071 100644 --- a/test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs +++ b/test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs @@ -18,10 +18,11 @@ namespace Microsoft.DotNet.Cli.Sln.List.Tests Usage: dotnet sln list [options] Arguments: - Solution file to operate on. If not specified, the command will search the current directory for one. + Solution file to operate on. If not specified, the command will search the current directory for one. Options: - -h|--help Show help information"; + -h, --help Show help information +"; [Theory] [InlineData("--help")] diff --git a/test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs b/test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs index 9b226515c..bc3594607 100644 --- a/test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs +++ b/test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs @@ -15,16 +15,14 @@ namespace Microsoft.DotNet.Cli.Sln.Remove.Tests { private const string HelpText = @".NET Remove project(s) from a solution file Command -Usage: dotnet sln remove [options] [args] +Usage: dotnet sln remove [options] Arguments: - Solution file to operate on. If not specified, the command will search the current directory for one. + Solution file to operate on. If not specified, the command will search the current directory for one. + Remove the specified project(s) from the solution. The project is not impacted. Options: - -h|--help Show help information - -Additional Arguments: - Remove the specified project(s) from the solution. The project is not impacted. + -h, --help Show help information "; private const string ExpectedSlnContentsAfterRemove = @" From 22fb17422f63d3b8a8220a006768909f2dbc64fa Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 14 Mar 2017 11:30:35 -0700 Subject: [PATCH 070/149] handle -? and /? arguments as help --- src/dotnet/ParseResultExtensions.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dotnet/ParseResultExtensions.cs b/src/dotnet/ParseResultExtensions.cs index ea238571e..9fa549dc9 100644 --- a/src/dotnet/ParseResultExtensions.cs +++ b/src/dotnet/ParseResultExtensions.cs @@ -14,7 +14,11 @@ namespace Microsoft.DotNet.Cli public static void ShowHelpOrErrorIfAppropriate(this ParseResult parseResult) { - if (parseResult.AppliedCommand().HasOption("help")) + var appliedCommand = parseResult.AppliedCommand(); + + if (appliedCommand.HasOption("help") || + appliedCommand.Arguments.Contains("-?") || + appliedCommand.Arguments.Contains("/?")) { // NOTE: this is a temporary stage in refactoring toward the ClicCommandLineParser being used at the CLI entry point. throw new HelpException(parseResult.Command().HelpView()); From 35732fc07dc267882d9938d5933e2c54464d1edd Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 14 Mar 2017 12:26:24 -0700 Subject: [PATCH 071/149] include HelpText in CommandParsingError, write it to stdout --- src/dotnet/CommandLine/CommandParsingException.cs | 7 ++++++- src/dotnet/ParseResultExtensions.cs | 5 +++-- src/dotnet/Program.cs | 13 ++++++++++--- src/dotnet/commands/dotnet-sln/SlnCommandParser.cs | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/dotnet/CommandLine/CommandParsingException.cs b/src/dotnet/CommandLine/CommandParsingException.cs index 606db5564..79e19e522 100644 --- a/src/dotnet/CommandLine/CommandParsingException.cs +++ b/src/dotnet/CommandLine/CommandParsingException.cs @@ -10,8 +10,11 @@ namespace Microsoft.DotNet.Cli.CommandLine { private readonly bool _isRequireSubCommandMissing; - public CommandParsingException(string message) : base(message) + public CommandParsingException( + string message, + string helpText = null) : base(message) { + HelpText = helpText ?? ""; Data.Add("CLI_User_Displayed_Exception", true); } @@ -27,6 +30,8 @@ namespace Microsoft.DotNet.Cli.CommandLine public CommandLineApplication Command { get; } + public string HelpText { get; } = ""; + public override string Message { get diff --git a/src/dotnet/ParseResultExtensions.cs b/src/dotnet/ParseResultExtensions.cs index 9fa549dc9..82932de0b 100644 --- a/src/dotnet/ParseResultExtensions.cs +++ b/src/dotnet/ParseResultExtensions.cs @@ -27,8 +27,9 @@ namespace Microsoft.DotNet.Cli if (parseResult.Errors.Any()) { throw new CommandParsingException( - string.Join(Environment.NewLine, - parseResult.Errors.Select(e => e.Message))); + message: string.Join(Environment.NewLine, + parseResult.Errors.Select(e => e.Message)), + helpText: parseResult?.Command()?.HelpView()); } } } diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 983f6507f..9af50b56e 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Configurer; using Microsoft.DotNet.PlatformAbstractions; @@ -84,9 +85,15 @@ namespace Microsoft.DotNet.Cli } catch (Exception e) when (e.ShouldBeDisplayedAsError()) { - Reporter.Error.WriteLine(CommandContext.IsVerbose() ? - e.ToString().Red().Bold() : - e.Message.Red().Bold()); + Reporter.Error.WriteLine(CommandContext.IsVerbose() + ? e.ToString().Red().Bold() + : e.Message.Red().Bold()); + + var commandParsingException = e as CommandParsingException; + if (commandParsingException != null) + { + Reporter.Output.WriteLine(commandParsingException.HelpText); + } return 1; } diff --git a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs index 5a38fe68b..ce4865921 100644 --- a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs +++ b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs @@ -20,7 +20,7 @@ namespace Microsoft.DotNet.Cli CommonOptions.HelpOption(), Create.Command("add", ".NET Add project(s) to a solution file Command", - Accept.OneOrMoreArguments() + Accept.OneOrMoreArguments(o => CommonLocalizableStrings.SpecifyAtLeastOneProjectToAdd) .With(name: "args", description: LocalizableStrings.AddSubcommandHelpText), CommonOptions.HelpOption()), From cb52224272cda0e148dbd0f88332f21dcc508750 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Tue, 14 Mar 2017 13:54:11 -0700 Subject: [PATCH 072/149] Fix test using `:` as option value separator --- .../GivenDotnetTestBuildsAndRunsTestfromCsproj.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs index 256c92609..9f3b7f050 100644 --- a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs +++ b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs @@ -134,7 +134,7 @@ namespace Microsoft.DotNet.Cli.Test.Tests // Call test with logger enable CommandResult result = new DotnetTestCommand() .WithWorkingDirectory(testProjectDirectory) - .ExecuteWithCapturedOutput("--logger:trx"); + .ExecuteWithCapturedOutput("--logger trx"); // Verify String[] trxFiles = Directory.GetFiles(trxLoggerDirectory, "*.trx"); From fac34c7b3bbc345a4d257c90c84134ca24c283e7 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Tue, 14 Mar 2017 14:07:51 -0700 Subject: [PATCH 073/149] Move all test commands to DotNetCommand base --- .../Commands/AddReferenceCommand.cs | 7 +------ .../Commands/BuildCommand.cs | 7 +------ .../Commands/CacheCommand.cs | 7 +------ .../Commands/CleanCommand.cs | 7 +------ .../Commands/DependencyToolInvokerCommand.cs | 7 +------ .../Commands/DotnetTestCommand.cs | 6 +----- .../Commands/HelpCommand.cs | 7 +------ .../Commands/ListReferenceCommand.cs | 7 +------ .../Commands/MSBuildCommand.cs | 7 +------ .../Commands/MigrateCommand.cs | 8 +------- .../Commands/NewCommand.cs | 8 +------- .../Commands/NewCommandShim.cs | 8 +------- .../Commands/PackCommand.cs | 3 +-- .../Commands/PublishCommand.cs | 9 ++------- .../Commands/RemoveReferenceCommand.cs | 7 +------ .../Commands/RestoreCommand.cs | 7 +------ .../Commands/RunCommand.cs | 7 +------ .../Commands/VSTestCommand.cs | 7 +------ 18 files changed, 19 insertions(+), 107 deletions(-) diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/AddReferenceCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/AddReferenceCommand.cs index a89025016..838597d86 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/AddReferenceCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/AddReferenceCommand.cs @@ -5,15 +5,10 @@ using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class AddReferenceCommand : TestCommand + public sealed class AddReferenceCommand : DotnetCommand { private string _projectName = null; - public AddReferenceCommand() - : base("dotnet") - { - } - public override CommandResult Execute(string args = "") { args = $"add {_projectName} reference {args}"; diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/BuildCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/BuildCommand.cs index 48b411471..86d22bbb1 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/BuildCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/BuildCommand.cs @@ -7,7 +7,7 @@ using NuGet.Frameworks; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class BuildCommand : TestCommand + public sealed class BuildCommand : DotnetCommand { private bool _captureOutput; @@ -26,11 +26,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities private DirectoryInfo _workingDirectory; - public BuildCommand() - : base("dotnet") - { - } - public override CommandResult Execute(string args = "") { args = $"build {GetNoDependencies()} {GetProjectFile()} {GetOutputPath()} {GetConfiguration()} {GetFramework()} {GetRuntime()} {args}"; diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/CacheCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/CacheCommand.cs index 08209f911..b6374b260 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/CacheCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/CacheCommand.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class CacheCommand : TestCommand + public sealed class CacheCommand : DotnetCommand { private List _profileProject = new List(); private string _framework; @@ -16,11 +16,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities private string _frameworkVersion; private string _intermediateWorkingDirectory; - public CacheCommand() - : base("dotnet") - { - } - public CacheCommand WithEntries(string profileProject) { _profileProject.Add($"--entries {profileProject}"); diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/CleanCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/CleanCommand.cs index 86e40f694..61d44dbf5 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/CleanCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/CleanCommand.cs @@ -7,13 +7,8 @@ using System.Runtime.InteropServices; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class CleanCommand : TestCommand + public sealed class CleanCommand : DotnetCommand { - public CleanCommand() - : base("dotnet") - { - } - public override CommandResult Execute(string args = "") { args = $"clean {args}"; diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/DependencyToolInvokerCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/DependencyToolInvokerCommand.cs index 029538177..a045c8ae6 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/DependencyToolInvokerCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/DependencyToolInvokerCommand.cs @@ -7,13 +7,8 @@ using System.Runtime.InteropServices; namespace Microsoft.DotNet.Tools.Test.Utilities { - public class DependencyToolInvokerCommand : TestCommand + public class DependencyToolInvokerCommand : DotnetCommand { - public DependencyToolInvokerCommand() - : base("dotnet") - { - } - public CommandResult Execute(string commandName, string framework, string additionalArgs) { var args = $"dependency-tool-invoker {commandName} --framework {framework} {additionalArgs}"; diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/DotnetTestCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/DotnetTestCommand.cs index 8b67d2d6e..129080b8e 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/DotnetTestCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/DotnetTestCommand.cs @@ -5,14 +5,10 @@ using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Tools.Test.Utilities { - public class DotnetTestCommand : TestCommand + public class DotnetTestCommand : DotnetCommand { private string _runtime; - public DotnetTestCommand() : base("dotnet") - { - } - public override CommandResult Execute(string args = "") { args = $"test {GetRuntime()} {args}"; diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/HelpCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/HelpCommand.cs index d7d78a7d4..ce3948e61 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/HelpCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/HelpCommand.cs @@ -5,13 +5,8 @@ using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class HelpCommand : TestCommand + public sealed class HelpCommand : DotnetCommand { - public HelpCommand() - : base("dotnet") - { - } - public override CommandResult Execute(string args = "") { args = $"help {args}"; diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/ListReferenceCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/ListReferenceCommand.cs index 0dc5b5df3..4d7cb5b35 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/ListReferenceCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/ListReferenceCommand.cs @@ -5,15 +5,10 @@ using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class ListReferenceCommand : TestCommand + public sealed class ListReferenceCommand : DotnetCommand { private string _projectName = null; - public ListReferenceCommand() - : base("dotnet") - { - } - public override CommandResult Execute(string args = "") { args = $"list {_projectName} reference {args}"; diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/MSBuildCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/MSBuildCommand.cs index d24ec36f0..5f6a184bf 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/MSBuildCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/MSBuildCommand.cs @@ -5,13 +5,8 @@ using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class MSBuildCommand : TestCommand + public sealed class MSBuildCommand : DotnetCommand { - public MSBuildCommand() - : base("dotnet") - { - } - public override CommandResult Execute(string args = "") { args = $"msbuild {args}"; diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/MigrateCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/MigrateCommand.cs index e3e87fd0e..63398ce7b 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/MigrateCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/MigrateCommand.cs @@ -5,14 +5,8 @@ using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class MigrateCommand : TestCommand + public sealed class MigrateCommand : DotnetCommand { - public MigrateCommand() - : base("dotnet") - { - - } - public override CommandResult Execute(string args="") { args = $"migrate {args}"; diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/NewCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/NewCommand.cs index 951982dde..3e0e4d89f 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/NewCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/NewCommand.cs @@ -5,14 +5,8 @@ using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class NewCommand : TestCommand + public sealed class NewCommand : DotnetCommand { - public NewCommand() - : base("dotnet") - { - - } - public override CommandResult Execute(string args = "") { args = $"new {args}"; diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/NewCommandShim.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/NewCommandShim.cs index ff7b0bc15..8a6e28dcb 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/NewCommandShim.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/NewCommandShim.cs @@ -6,14 +6,8 @@ using Xunit; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class NewCommandShim : TestCommand + public sealed class NewCommandShim : DotnetCommand { - public NewCommandShim() - : base("dotnet") - { - - } - public override CommandResult Execute(string args = "") { args = $"new {args} --debug:ephemeral-hive"; diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PackCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PackCommand.cs index 8a91d3780..f18af106a 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PackCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PackCommand.cs @@ -6,7 +6,7 @@ using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class PackCommand : TestCommand + public sealed class PackCommand : DotnetCommand { private string _projectPath; private string _outputDirectory; @@ -90,7 +90,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities string configuration="", string versionSuffix="", bool serviceable = false) - : base("dotnet") { _projectPath = projectPath; _outputDirectory = output; diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs index 5bb0d01a6..e411e83f2 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs @@ -7,18 +7,13 @@ using System.Collections.Generic; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class PublishCommand : TestCommand + public sealed class PublishCommand : DotnetCommand { private string _framework; private string _output; private string _runtime; private List _profileFilterProject = new List(); - - public PublishCommand() - : base("dotnet") - { - } - + public PublishCommand WithFramework(string framework) { _framework = framework; diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/RemoveReferenceCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/RemoveReferenceCommand.cs index 68107fce0..66c7b9bc4 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/RemoveReferenceCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/RemoveReferenceCommand.cs @@ -5,15 +5,10 @@ using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class RemoveReferenceCommand : TestCommand + public sealed class RemoveReferenceCommand : DotnetCommand { private string _projectName = null; - public RemoveReferenceCommand() - : base("dotnet") - { - } - public override CommandResult Execute(string args = "") { args = $"remove {_projectName} reference {args}"; diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/RestoreCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/RestoreCommand.cs index c0096101f..cc5804a1a 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/RestoreCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/RestoreCommand.cs @@ -5,15 +5,10 @@ using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class RestoreCommand : TestCommand + public sealed class RestoreCommand : DotnetCommand { private string _runtime; - public RestoreCommand() - : base("dotnet") - { - } - public RestoreCommand WithRuntime(string runtime) { _runtime = runtime; diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/RunCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/RunCommand.cs index d5596dc0e..81349a6c6 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/RunCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/RunCommand.cs @@ -7,13 +7,8 @@ using System.Runtime.InteropServices; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class RunCommand : TestCommand + public sealed class RunCommand : DotnetCommand { - public RunCommand() - : base("dotnet") - { - } - public override CommandResult Execute(string args = "") { args = $"run {args}"; diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/VSTestCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/VSTestCommand.cs index b191a4231..38c340ee1 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/VSTestCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/VSTestCommand.cs @@ -5,13 +5,8 @@ using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class VSTestCommand: TestCommand + public sealed class VSTestCommand: DotnetCommand { - public VSTestCommand() - :base("dotnet") - { - } - public override CommandResult Execute(string args = "") { args = $"vstest {args}"; From f318ac33f9628d10fee6a69520c35f12ba1e0e66 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Tue, 14 Mar 2017 14:22:11 -0700 Subject: [PATCH 074/149] Unseal! --- .../Commands/DotnetCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/DotnetCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/DotnetCommand.cs index 48dc47926..97bb41ab4 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/DotnetCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/DotnetCommand.cs @@ -5,7 +5,7 @@ using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Tools.Test.Utilities { - public sealed class DotnetCommand : TestCommand + public class DotnetCommand : TestCommand { public DotnetCommand() : base(DotnetUnderTest.FullName) From 59d1fe32bcba795c3aedfd1f2e09bdf3ef732d4a Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 14 Mar 2017 15:22:31 -0700 Subject: [PATCH 075/149] remove redundant help --- src/dotnet/commands/dotnet-list/ListCommandParser.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/dotnet/commands/dotnet-list/ListCommandParser.cs b/src/dotnet/commands/dotnet-list/ListCommandParser.cs index d90660bc5..61e5129da 100644 --- a/src/dotnet/commands/dotnet-list/ListCommandParser.cs +++ b/src/dotnet/commands/dotnet-list/ListCommandParser.cs @@ -17,10 +17,7 @@ namespace Microsoft.DotNet.Cli .DefaultToCurrentDirectory(), CommonOptions.HelpOption(), Create.Command("reference", "Command to list project to project references", - Accept.ExactlyOneArgument() - .With(name: "PROJECT", - description: - "The project file to operate on. If a file is not specified, the command will search the current directory for one."), + Accept.ExactlyOneArgument(), CommonOptions.HelpOption())); } } \ No newline at end of file From 11270a436b0fe19ea171db5c11b58d531ff255ba Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 14 Mar 2017 16:13:49 -0700 Subject: [PATCH 076/149] list command help text fix --- src/dotnet/commands/dotnet-list/ListCommandParser.cs | 4 +++- test/dotnet-list-reference.Tests/GivenDotnetListReference.cs | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/dotnet/commands/dotnet-list/ListCommandParser.cs b/src/dotnet/commands/dotnet-list/ListCommandParser.cs index 61e5129da..ff03ab588 100644 --- a/src/dotnet/commands/dotnet-list/ListCommandParser.cs +++ b/src/dotnet/commands/dotnet-list/ListCommandParser.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using Microsoft.DotNet.Cli.CommandLine; +using LocalizableStrings = Microsoft.DotNet.Tools.List.ProjectToProjectReferences.LocalizableStrings; namespace Microsoft.DotNet.Cli { @@ -16,7 +17,8 @@ namespace Microsoft.DotNet.Cli "The project file to operate on. If a file is not specified, the command will search the current directory for one.") .DefaultToCurrentDirectory(), CommonOptions.HelpOption(), - Create.Command("reference", "Command to list project to project references", + Create.Command("reference", + LocalizableStrings.AppFullName, Accept.ExactlyOneArgument(), CommonOptions.HelpOption())); } diff --git a/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs b/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs index 8d7be59ad..499c1b74e 100644 --- a/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs +++ b/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs @@ -18,10 +18,11 @@ namespace Microsoft.DotNet.Cli.List.Reference.Tests Usage: dotnet list reference [options] Arguments: - The project file to operate on. If a file is not specified, the command will search the current directory for one. + The project file to operate on. If a file is not specified, the command will search the current directory for one. Options: - -h|--help Show help information"; + -h, --help Show help information +"; const string FrameworkNet451Arg = "-f net451"; const string ConditionFrameworkNet451 = "== 'net451'"; From 4940c2a6ee0bb8852bab07d7bfe54ac74b9d1170 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 14 Mar 2017 18:41:27 -0700 Subject: [PATCH 077/149] use ValueOrDefault --- src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs | 2 +- .../commands/dotnet-remove/dotnet-remove-reference/Program.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs b/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs index b6cce249a..c63391a15 100644 --- a/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs +++ b/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs @@ -42,7 +42,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference var projects = new ProjectCollection(); MsbuildProject msbuildProj = MsbuildProject.FromFileOrDirectory(projects, _fileOrDirectory); - var frameworkString = _appliedCommand["framework"].Value(); + var frameworkString = _appliedCommand.ValueOrDefault("framework"); PathUtility.EnsureAllPathsExist(_appliedCommand.Arguments, CommonLocalizableStrings.ReferenceDoesNotExist); List refs = _appliedCommand.Arguments diff --git a/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs b/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs index 55c6b3e2c..963cd5565 100644 --- a/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs +++ b/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs @@ -36,7 +36,7 @@ namespace Microsoft.DotNet.Tools.Remove.ProjectToProjectReference var msbuildProj = MsbuildProject.FromFileOrDirectory(new ProjectCollection(), _fileOrDirectory); int numberOfRemovedReferences = msbuildProj.RemoveProjectToProjectReferences( - _appliedCommand["framework"].Value(), + _appliedCommand.ValueOrDefault("framework"), _appliedCommand.Arguments); if (numberOfRemovedReferences != 0) From 1ca338838ab2f5ced7bae9e04bb51a9ab049762c Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Tue, 14 Mar 2017 19:19:31 -0700 Subject: [PATCH 078/149] dotnet list reference fix --- src/dotnet/commands/dotnet-list/ListCommandParser.cs | 1 - src/dotnet/commands/dotnet-list/Program.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/dotnet/commands/dotnet-list/ListCommandParser.cs b/src/dotnet/commands/dotnet-list/ListCommandParser.cs index ff03ab588..5d393cffb 100644 --- a/src/dotnet/commands/dotnet-list/ListCommandParser.cs +++ b/src/dotnet/commands/dotnet-list/ListCommandParser.cs @@ -19,7 +19,6 @@ namespace Microsoft.DotNet.Cli CommonOptions.HelpOption(), Create.Command("reference", LocalizableStrings.AppFullName, - Accept.ExactlyOneArgument(), CommonOptions.HelpOption())); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-list/Program.cs b/src/dotnet/commands/dotnet-list/Program.cs index 016cfebe9..f4b39cb04 100644 --- a/src/dotnet/commands/dotnet-list/Program.cs +++ b/src/dotnet/commands/dotnet-list/Program.cs @@ -20,7 +20,7 @@ namespace Microsoft.DotNet.Tools.List internal override Dictionary> SubCommands => new Dictionary> { - { "list", o => new ListProjectToProjectReferencesCommand(o) } + { "reference", o => new ListProjectToProjectReferencesCommand(o) } }; public static int Run(string[] args) From d3a101ebade11575ffea4b3b145a80bc16399bf8 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Tue, 14 Mar 2017 20:20:25 -0700 Subject: [PATCH 079/149] list reference accepts zero or one arg --- src/dotnet/commands/dotnet-list/ListCommandParser.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dotnet/commands/dotnet-list/ListCommandParser.cs b/src/dotnet/commands/dotnet-list/ListCommandParser.cs index 5d393cffb..867c5c3e0 100644 --- a/src/dotnet/commands/dotnet-list/ListCommandParser.cs +++ b/src/dotnet/commands/dotnet-list/ListCommandParser.cs @@ -19,6 +19,7 @@ namespace Microsoft.DotNet.Cli CommonOptions.HelpOption(), Create.Command("reference", LocalizableStrings.AppFullName, + Accept.ZeroOrOneArgument(), CommonOptions.HelpOption())); } } \ No newline at end of file From bbc2722cb7708c2a9e07c2c93dd97f4286021fcf Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 14 Mar 2017 23:13:59 -0700 Subject: [PATCH 080/149] loc spelling error and other fixes --- .../commands/dotnet-add/AddCommandParser.cs | 4 +-- .../dotnet-remove/RemoveCommandParser.cs | 29 ++++++++++++------- .../dotnet-remove-reference/Program.cs | 2 +- .../GivenDotnetRemoveP2P.cs | 12 ++++---- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/dotnet/commands/dotnet-add/AddCommandParser.cs b/src/dotnet/commands/dotnet-add/AddCommandParser.cs index d178b80c1..b507a88dc 100644 --- a/src/dotnet/commands/dotnet-add/AddCommandParser.cs +++ b/src/dotnet/commands/dotnet-add/AddCommandParser.cs @@ -37,7 +37,7 @@ namespace Microsoft.DotNet.Cli .With(name: "VERSION") .ForwardAs(o => $"--version {o.Arguments.Single()}")), Create.Option("-f|--framework", - "Add reference only when targetting a specific framework", + "Add reference only when targeting a specific framework", Accept.ExactlyOneArgument() .With(name: "FRAMEWORK") .ForwardAs(o => $"--framework {o.Arguments.Single()}")), @@ -59,7 +59,7 @@ namespace Microsoft.DotNet.Cli Accept.OneOrMoreArguments(), CommonOptions.HelpOption(), Create.Option("-f|--framework", - "Add reference only when targetting a specific framework", + "Add reference only when targeting a specific framework", Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) .With(name: "FRAMEWORK"))), CommonOptions.HelpOption()); diff --git a/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs b/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs index b452057b8..23b976094 100644 --- a/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs +++ b/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs @@ -2,6 +2,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Tools; +using LocalizableStrings = Microsoft.DotNet.Tools.Remove.ProjectToProjectReference.LocalizableStrings; namespace Microsoft.DotNet.Cli { @@ -11,19 +13,26 @@ namespace Microsoft.DotNet.Cli Create.Command("remove", ".NET Remove Command", Accept.ZeroOrOneArgument() - .With(name: "PROJECT") + .With(name: "PROJECT", + description: CommonLocalizableStrings.ArgumentsProjectDescription) .DefaultToCurrentDirectory(), CommonOptions.HelpOption(), Create.Command("package", - "Command to remove package reference.", + LocalizableStrings.AppFullName, CommonOptions.HelpOption()), - Create.Command("reference", - "Command to remove project to project reference", - Accept.AnyOneOf(Suggest.ProjectReferencesFromProjectFile), - CommonOptions.HelpOption(), - Create.Option("-f|--framework", - "Remove reference only when targetting a specific framework", - Accept.ExactlyOneArgument() - .With(name: "FRAMEWORK")))); + Create.Command( + "reference", + LocalizableStrings.AppFullName, + Accept + .OneOrMoreArguments() + .WithSuggestionsFrom(_ => Suggest.ProjectReferencesFromProjectFile()) + .With(name: "args", + description: LocalizableStrings.AppHelpText), + CommonOptions.HelpOption(), + Create.Option( + "-f|--framework", + "Remove reference only when targeting a specific framework", + Accept.ExactlyOneArgument() + .With(name: "FRAMEWORK")))); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs b/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs index 963cd5565..74693b343 100644 --- a/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs +++ b/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs @@ -22,7 +22,7 @@ namespace Microsoft.DotNet.Tools.Remove.ProjectToProjectReference throw new ArgumentNullException(nameof(appliedCommand)); } - if (_appliedCommand.Arguments.Count == 0) + if (appliedCommand.Arguments.Count == 0) { throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneReferenceToRemove); } diff --git a/test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs b/test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs index 793330431..a02968355 100644 --- a/test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs +++ b/test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs @@ -15,17 +15,15 @@ namespace Microsoft.DotNet.Cli.Remove.Reference.Tests { private const string HelpText = @".NET Remove Project to Project reference Command -Usage: dotnet remove reference [options] [args] +Usage: dotnet remove reference [options] Arguments: - The project file to operate on. If a file is not specified, the command will search the current directory for one. + The project file to operate on. If a file is not specified, the command will search the current directory for one. + Project to project references to remove Options: - -h|--help Show help information - -f|--framework Remove reference only when targeting a specific framework - -Additional Arguments: - Project to project references to remove + -h, --help Show help information + -f, --framework Remove reference only when targeting a specific framework "; const string FrameworkNet451Arg = "-f net451"; From c316b98c74673f2096a915d28c32beb20fa9d66f Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Wed, 15 Mar 2017 09:27:27 -0700 Subject: [PATCH 081/149] remove command fixes --- src/dotnet/commands/dotnet-remove/Program.cs | 11 +++++++++-- .../commands/dotnet-remove/RemoveCommandParser.cs | 11 +++++++---- .../dotnet-remove/dotnet-remove-package/Program.cs | 10 ++++++++-- .../dotnet-remove/dotnet-remove-reference/Program.cs | 11 +++++++++-- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/dotnet/commands/dotnet-remove/Program.cs b/src/dotnet/commands/dotnet-remove/Program.cs index c30791bf5..086bdef6a 100644 --- a/src/dotnet/commands/dotnet-remove/Program.cs +++ b/src/dotnet/commands/dotnet-remove/Program.cs @@ -21,8 +21,15 @@ namespace Microsoft.DotNet.Tools.Remove internal override Dictionary> SubCommands => new Dictionary> { - { "reference", o => new RemoveProjectToProjectReferenceCommand(o) }, - { "package", o => new RemovePackageReferenceCommand(o) } + ["reference"] = + remove => new RemoveProjectToProjectReferenceCommand( + remove["reference"], + remove.Value()), + + ["package"] = + remove => new RemovePackageReferenceCommand( + remove["package"], + remove.Value()) }; public static int Run(string[] args) diff --git a/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs b/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs index 23b976094..d5af30cd1 100644 --- a/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs +++ b/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs @@ -12,14 +12,17 @@ namespace Microsoft.DotNet.Cli public static Command Remove() => Create.Command("remove", ".NET Remove Command", - Accept.ZeroOrOneArgument() + Accept.ExactlyOneArgument() + .ExistingFilesOnly() + .DefaultToCurrentDirectory() .With(name: "PROJECT", description: CommonLocalizableStrings.ArgumentsProjectDescription) .DefaultToCurrentDirectory(), CommonOptions.HelpOption(), - Create.Command("package", - LocalizableStrings.AppFullName, - CommonOptions.HelpOption()), + Create.Command( + "package", + LocalizableStrings.AppFullName, + CommonOptions.HelpOption()), Create.Command( "reference", LocalizableStrings.AppFullName, diff --git a/src/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs b/src/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs index 082b97ff6..7176c581a 100644 --- a/src/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs +++ b/src/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs @@ -16,19 +16,25 @@ namespace Microsoft.DotNet.Tools.Remove.PackageReference private readonly AppliedOption _appliedCommand; private readonly string _fileOrDirectory; - public RemovePackageReferenceCommand(AppliedOption appliedCommand) + public RemovePackageReferenceCommand( + AppliedOption appliedCommand, + string fileOrDirectory) { if (appliedCommand == null) { throw new ArgumentNullException(nameof(appliedCommand)); } + if (fileOrDirectory == null) + { + throw new ArgumentNullException(nameof(fileOrDirectory)); + } if (_appliedCommand.Arguments.Count != 1) { throw new GracefulException(LocalizableStrings.SpecifyExactlyOnePackageReference); } _appliedCommand = appliedCommand; - _fileOrDirectory = appliedCommand.Arguments.Single(); + _fileOrDirectory = fileOrDirectory; } public override int Execute() diff --git a/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs b/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs index 74693b343..ddfecfec9 100644 --- a/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs +++ b/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs @@ -15,20 +15,27 @@ namespace Microsoft.DotNet.Tools.Remove.ProjectToProjectReference private readonly AppliedOption _appliedCommand; private readonly string _fileOrDirectory; - public RemoveProjectToProjectReferenceCommand(AppliedOption appliedCommand) + public RemoveProjectToProjectReferenceCommand( + AppliedOption appliedCommand, + string fileOrDirectory) { if (appliedCommand == null) { throw new ArgumentNullException(nameof(appliedCommand)); } + if (fileOrDirectory == null) + { + throw new ArgumentNullException(nameof(fileOrDirectory)); + } + if (appliedCommand.Arguments.Count == 0) { throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneReferenceToRemove); } _appliedCommand = appliedCommand; - _fileOrDirectory = appliedCommand.Arguments.Single(); + _fileOrDirectory = fileOrDirectory; } public override int Execute() From bcfc16000ce33c1939233b6a69b0b50dd6aadade Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Wed, 15 Mar 2017 09:28:10 -0700 Subject: [PATCH 082/149] latest CliCommandLine --- src/dotnet/dotnet.csproj | 2 +- test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index 49ebe85be..142c3c12d 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index 13acbe278..56960da6c 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From 8a2be5761757b0f0984ffeaa5ff5865cfc1118a6 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Wed, 15 Mar 2017 13:59:39 -0700 Subject: [PATCH 083/149] text fixes for dotnet remove --- .../commands/dotnet-add/AddCommandParser.cs | 8 ++- .../commands/dotnet-complete/ParseCommand.cs | 11 +++- .../commands/dotnet-complete/Suggest.cs | 56 ++++++++++++------- .../GivenDotnetAddReference.cs | 12 ++-- 4 files changed, 55 insertions(+), 32 deletions(-) diff --git a/src/dotnet/commands/dotnet-add/AddCommandParser.cs b/src/dotnet/commands/dotnet-add/AddCommandParser.cs index b507a88dc..781ffb450 100644 --- a/src/dotnet/commands/dotnet-add/AddCommandParser.cs +++ b/src/dotnet/commands/dotnet-add/AddCommandParser.cs @@ -55,13 +55,15 @@ namespace Microsoft.DotNet.Cli .ForwardAs(o => $"--package-directory {o.Arguments.Single()}"))), Create.Command( "reference", - "Command to add project to project reference", - Accept.OneOrMoreArguments(), + Tools.Add.ProjectToProjectReference.LocalizableStrings.AppFullName, + Accept.OneOrMoreArguments() + .With(name: "args", + description: Tools.Add.ProjectToProjectReference.LocalizableStrings.AppHelpText), CommonOptions.HelpOption(), Create.Option("-f|--framework", "Add reference only when targeting a specific framework", Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) - .With(name: "FRAMEWORK"))), + .With(name: "FRAMEWORK"))), CommonOptions.HelpOption()); public static IEnumerable QueryNuGet(string match) diff --git a/src/dotnet/commands/dotnet-complete/ParseCommand.cs b/src/dotnet/commands/dotnet-complete/ParseCommand.cs index 3fc2b1be7..fb86c6300 100644 --- a/src/dotnet/commands/dotnet-complete/ParseCommand.cs +++ b/src/dotnet/commands/dotnet-complete/ParseCommand.cs @@ -11,9 +11,16 @@ namespace Microsoft.DotNet.Cli { DebugHelper.HandleDebugSwitch(ref args); - var result = - Parser.Instance.Parse( + ParseResult result; + try + { + result = Parser.Instance.Parse( args.Single()); + } + catch (Exception e) + { + throw new InvalidOperationException("The parser threw an exception.", e); + } Console.WriteLine(result.Diagram()); diff --git a/src/dotnet/commands/dotnet-complete/Suggest.cs b/src/dotnet/commands/dotnet-complete/Suggest.cs index e4b78e65c..e9dd0c7ef 100644 --- a/src/dotnet/commands/dotnet-complete/Suggest.cs +++ b/src/dotnet/commands/dotnet-complete/Suggest.cs @@ -1,8 +1,11 @@ +using System; using System.Collections.Generic; using System.IO; using System.Linq; using Microsoft.Build.Evaluation; +using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools; +using static System.Array; namespace Microsoft.DotNet.Cli { @@ -10,33 +13,46 @@ namespace Microsoft.DotNet.Cli { public static IEnumerable TargetFrameworksFromProjectFile() { - var msbuildProj = MsbuildProject.FromFileOrDirectory( - new ProjectCollection(), - Directory.GetCurrentDirectory()); + var msBuildProject = GetMSBuildProject(); - foreach (var tfm in msbuildProj.GetTargetFrameworks()) + if (msBuildProject == null) + { + yield break; + } + + foreach (var tfm in msBuildProject.GetTargetFrameworks()) { yield return tfm.GetShortFolderName(); } } - public static IEnumerable RunTimesFromProjectFile() + private static void Report(Exception e) => + Reporter.Verbose.WriteLine($"Exception occurred while getting suggestions: {e}"); + + public static IEnumerable RunTimesFromProjectFile() => + GetMSBuildProject() + .GetRuntimeIdentifiers() ?? + Empty(); + + public static IEnumerable ProjectReferencesFromProjectFile() => + GetMSBuildProject() + ?.GetProjectToProjectReferences() + .Select(r => r.Include) ?? + Empty(); + + private static MsbuildProject GetMSBuildProject() { - var msbuildProj = MsbuildProject.FromFileOrDirectory( - new ProjectCollection(), - Directory.GetCurrentDirectory()); - - return msbuildProj.GetRuntimeIdentifiers(); - } - - public static IEnumerable ProjectReferencesFromProjectFile() - { - var msbuildProj = MsbuildProject.FromFileOrDirectory( - new ProjectCollection(), - Directory.GetCurrentDirectory()); - - return msbuildProj.GetProjectToProjectReferences() - .Select(r => r.Include); + try + { + return MsbuildProject.FromFileOrDirectory( + new ProjectCollection(), + Directory.GetCurrentDirectory()); + } + catch (Exception e) + { + Report(e); + return null; + } } } } \ No newline at end of file diff --git a/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs b/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs index 0f71da16c..71984d279 100644 --- a/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs +++ b/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs @@ -16,17 +16,15 @@ namespace Microsoft.DotNet.Cli.Add.Reference.Tests { private const string HelpText = @".NET Add Project to Project reference Command -Usage: dotnet add reference [options] [args] +Usage: dotnet add reference [options] Arguments: - The project file to operate on. If a file is not specified, the command will search the current directory for one. + The project file to operate on. If a file is not specified, the command will search the current directory for one. + Project to project references to add Options: - -h|--help Show help information - -f|--framework Add reference only when targeting a specific framework - -Additional Arguments: - Project to project references to add + -h, --help Show help information + -f, --framework Add reference only when targeting a specific framework "; const string FrameworkNet451Arg = "-f net451"; From 9d1adadb9d1c1a89f53897318b44ec5ba642fcad Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Wed, 15 Mar 2017 15:17:37 -0700 Subject: [PATCH 084/149] Extra diagnostics --- test/ArgumentForwardingTests/ArgumentForwardingTests.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/ArgumentForwardingTests/ArgumentForwardingTests.cs b/test/ArgumentForwardingTests/ArgumentForwardingTests.cs index 2d889e043..51128ab86 100644 --- a/test/ArgumentForwardingTests/ArgumentForwardingTests.cs +++ b/test/ArgumentForwardingTests/ArgumentForwardingTests.cs @@ -176,6 +176,10 @@ namespace Microsoft.DotNet.Tests.ArgumentForwarding .CaptureStdOut() .Execute(); + Console.WriteLine($"STDOUT: {commandResult.StdOut}"); + + Console.WriteLine($"STDERR: {commandResult.StdErr}"); + commandResult.ExitCode.Should().Be(0); return ParseReflectorOutput(commandResult.StdOut); From ae312b796553f982b1d1606509e0531b9a7519bd Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Wed, 15 Mar 2017 19:09:54 -0700 Subject: [PATCH 085/149] adjust parser constraints for dotnet add --- src/dotnet/commands/dotnet-add/AddCommandParser.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/dotnet/commands/dotnet-add/AddCommandParser.cs b/src/dotnet/commands/dotnet-add/AddCommandParser.cs index 781ffb450..645fc652f 100644 --- a/src/dotnet/commands/dotnet-add/AddCommandParser.cs +++ b/src/dotnet/commands/dotnet-add/AddCommandParser.cs @@ -37,7 +37,7 @@ namespace Microsoft.DotNet.Cli .With(name: "VERSION") .ForwardAs(o => $"--version {o.Arguments.Single()}")), Create.Option("-f|--framework", - "Add reference only when targeting a specific framework", + LocalizableStrings.CmdFrameworkDescription, Accept.ExactlyOneArgument() .With(name: "FRAMEWORK") .ForwardAs(o => $"--framework {o.Arguments.Single()}")), @@ -61,9 +61,11 @@ namespace Microsoft.DotNet.Cli description: Tools.Add.ProjectToProjectReference.LocalizableStrings.AppHelpText), CommonOptions.HelpOption(), Create.Option("-f|--framework", - "Add reference only when targeting a specific framework", - Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile) - .With(name: "FRAMEWORK"))), + LocalizableStrings.CmdFrameworkDescription, + Accept + .ExactlyOneArgument() + .WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile()) + .With(name: "FRAMEWORK"))), CommonOptions.HelpOption()); public static IEnumerable QueryNuGet(string match) From 339b1435cbec74153b511544fffc7022c3de1353 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Wed, 15 Mar 2017 19:25:05 -0700 Subject: [PATCH 086/149] fix OS-specific path in test --- test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs index d0bb45cbf..a65a6793d 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs @@ -46,7 +46,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [InlineData("--output")] public void ItAddsOutputPathToMsBuildInvocation(string optionName) { - string path = "/some/path"; + string path = Directory.GetCurrentDirectory(); var args = ArgsPrefix.Concat(new string[] { optionName, path }).ToArray(); var msbuildPath = ""; From 5bfd610407c0d5db88e30fa946ab960a6512f1a6 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Wed, 15 Mar 2017 19:25:16 -0700 Subject: [PATCH 087/149] add back --version-suffix --- src/dotnet/commands/dotnet-publish/PublishCommandParser.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs index e40cac535..c6ca8361f 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs @@ -24,6 +24,7 @@ namespace Microsoft.DotNet.Cli .With(name: LocalizableStrings.OutputOption) .ForwardAs(o => $"/p:PublishDir={o.Arguments.Single()}")), CommonOptions.ConfigurationOption(), + CommonOptions.VersionSuffixOption(), Create.Option( "--filter", LocalizableStrings.FilterProjOptionDescription, From 0dc3661ed1bfaf993b1c90e1f8dc4dffe9da55ce Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Wed, 15 Mar 2017 19:40:53 -0700 Subject: [PATCH 088/149] remove colon from logger option --- test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs index 28c0a25a9..8d03c666a 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs @@ -19,7 +19,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities { protected const string DefaultFramework = "netcoreapp1.0"; protected const string DefaultLibraryFramework = "netstandard1.5"; - protected const string ConsoleLoggerOutputNormal = "--logger:console;verbosity=normal"; + protected const string ConsoleLoggerOutputNormal = "--logger console;verbosity=normal"; private TempRoot _temp; private static TestAssets s_testAssets; From 13458b17c4b3cd740208271705b3efef91de7679 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Wed, 15 Mar 2017 19:57:03 -0700 Subject: [PATCH 089/149] test fix --- test/dotnet-list-reference.Tests/GivenDotnetListReference.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs b/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs index 499c1b74e..e11317825 100644 --- a/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs +++ b/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs @@ -53,7 +53,7 @@ Options: [Fact] public void WhenTooManyArgumentsArePassedItPrintsError() { - var cmd = new AddReferenceCommand() + var cmd = new ListReferenceCommand() .WithProject("one two three") .Execute("proj.csproj"); cmd.ExitCode.Should().NotBe(0); From 69ba7095e5044576b9e3ae097d69d6a3f70e3836 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Wed, 15 Mar 2017 20:33:22 -0700 Subject: [PATCH 090/149] update parser --- src/dotnet/dotnet.csproj | 2 +- test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index 142c3c12d..cf9ac78f0 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index 56960da6c..e2de4858a 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From 9d2d633d1c64e36b2f5a7a61f7377923f3fd02ea Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Thu, 16 Mar 2017 01:31:16 -0700 Subject: [PATCH 091/149] Move remaining `TestCommand("dotnet")` to `DotnetCommand` --- .../GivenAppThrowingException.cs | 2 +- test/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs | 4 ++-- .../GivenDotnetCachesAndPublishesProjects.cs | 6 +++--- .../GivenDotnetPublishPublishesProjects.cs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAppThrowingException.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAppThrowingException.cs index fb4299442..e5da522f8 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAppThrowingException.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAppThrowingException.cs @@ -67,7 +67,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests string msg1 = "Unhandled Exception: AppThrowing.MyException: " + "Exception of type 'AppThrowing.MyException' was thrown."; string msg2 = "at AppThrowing.MyException.Main(String[] args)"; - new TestCommand("dotnet") + new DotnetCommand() .WithWorkingDirectory(appWithToolDepRoot) .ExecuteWithCapturedOutput("throwingtool") .Should().Fail() diff --git a/test/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs b/test/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs index 6a18ddcbc..a126e5a16 100644 --- a/test/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs +++ b/test/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs @@ -31,7 +31,7 @@ namespace Microsoft.DotNet.Cli.Build.Tests var outputDll = testInstance.Root.GetDirectory("bin", configuration, "netcoreapp2.0") .GetFile($"{testAppName}.dll"); - var outputRunCommand = new TestCommand("dotnet"); + var outputRunCommand = new DotnetCommand(); outputRunCommand.ExecuteWithCapturedOutput(outputDll.FullName) .Should().Pass() @@ -72,7 +72,7 @@ namespace Microsoft.DotNet.Cli.Build.Tests SearchOption.TopDirectoryOnly) .Single(); - var outputRunCommand = new TestCommand("dotnet"); + var outputRunCommand = new DotnetCommand(); outputRunCommand.ExecuteWithCapturedOutput(outputDll) .Should().Pass() diff --git a/test/dotnet-cache.Tests/GivenDotnetCachesAndPublishesProjects.cs b/test/dotnet-cache.Tests/GivenDotnetCachesAndPublishesProjects.cs index 296b06888..92d22fbd2 100644 --- a/test/dotnet-cache.Tests/GivenDotnetCachesAndPublishesProjects.cs +++ b/test/dotnet-cache.Tests/GivenDotnetCachesAndPublishesProjects.cs @@ -63,7 +63,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, _tfm, "publish", $"{testAppName}.dll"); - new TestCommand("dotnet") + new DotnetCommand() .WithEnvironmentVariable("DOTNET_SHARED_PACKAGES", localAssemblyCache) .ExecuteWithCapturedOutput(outputDll) .Should().Pass() @@ -101,7 +101,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, _tfm, "publish", $"{testAppName}.dll"); - new TestCommand("dotnet") + new DotnetCommand() .ExecuteWithCapturedOutput(outputDll) .Should().Fail() .And.HaveStdErrContaining("assembly specified in the dependencies manifest was not found -- package: 'newtonsoft.json',"); @@ -160,7 +160,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, _tfm, "publish", $"{testAppName}.dll"); - new TestCommand("dotnet") + new DotnetCommand() .WithEnvironmentVariable("DOTNET_SHARED_PACKAGES", localAssemblyCache) .ExecuteWithCapturedOutput(outputDll) .Should().Pass() diff --git a/test/dotnet-publish.Tests/GivenDotnetPublishPublishesProjects.cs b/test/dotnet-publish.Tests/GivenDotnetPublishPublishesProjects.cs index 1ca2a1c9a..289c40ccc 100644 --- a/test/dotnet-publish.Tests/GivenDotnetPublishPublishesProjects.cs +++ b/test/dotnet-publish.Tests/GivenDotnetPublishPublishesProjects.cs @@ -38,7 +38,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug"; var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, "netcoreapp2.0", "publish", $"{testAppName}.dll"); - new TestCommand("dotnet") + new DotnetCommand() .ExecuteWithCapturedOutput(outputDll) .Should().Pass() .And.HaveStdOutContaining("Hello World"); From 6c8400b8bea4ceaa14b8d0fec0b1e35f45a38a50 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Thu, 16 Mar 2017 02:39:48 -0700 Subject: [PATCH 092/149] dotnet run --no-build test shows the option was previously supported, but ignored. --- src/dotnet/commands/dotnet-run/LocalizableStrings.cs | 2 ++ src/dotnet/commands/dotnet-run/RunCommandParser.cs | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/dotnet/commands/dotnet-run/LocalizableStrings.cs b/src/dotnet/commands/dotnet-run/LocalizableStrings.cs index 9c5d8e022..b1143338f 100644 --- a/src/dotnet/commands/dotnet-run/LocalizableStrings.cs +++ b/src/dotnet/commands/dotnet-run/LocalizableStrings.cs @@ -11,6 +11,8 @@ namespace Microsoft.DotNet.Tools.Run public const string CommandOptionProjectDescription = "The path to the project file to run (defaults to the current directory if there is only one project)."; + public const string CommandOptionNoBuildDescription = "Skip building the project prior to running. By default, the project will be built."; + public const string RunCommandException = "The build failed. Please fix the build errors and run again."; public const string RunCommandExceptionUnableToRun = "Unable to run your project\nPlease ensure you have a runnable project type and ensure '{0}' supports this project.\nThe current {1} is '{2}'"; diff --git a/src/dotnet/commands/dotnet-run/RunCommandParser.cs b/src/dotnet/commands/dotnet-run/RunCommandParser.cs index d42f58ba6..737e43b23 100644 --- a/src/dotnet/commands/dotnet-run/RunCommandParser.cs +++ b/src/dotnet/commands/dotnet-run/RunCommandParser.cs @@ -31,6 +31,10 @@ namespace Microsoft.DotNet.Cli Create.Option( "-p|--project", LocalizableStrings.CommandOptionProjectDescription, - Accept.ExactlyOneArgument())); + Accept.ExactlyOneArgument()), + Create.Option( + "--no-build", + LocalizableStrings.CommandOptionNoBuildDescription, + Accept.NoArguments().ForwardAs("/p:NoBuild=true"))); } -} \ No newline at end of file +} From 3c8f33093081aab5403642cf62a12f1552fbc762 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Thu, 16 Mar 2017 08:31:15 -0700 Subject: [PATCH 093/149] update parser --- src/dotnet/dotnet.csproj | 2 +- test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index cf9ac78f0..a4cce6367 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index e2de4858a..d23100d8a 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From 9c2e8f00379999b8b83abff3eb0462d9c439a98e Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Thu, 16 Mar 2017 09:49:07 -0700 Subject: [PATCH 094/149] text fixes, remove file existence validations from parse --- src/dotnet/CommonOptions.cs | 36 ------------------- .../commands/dotnet-add/AddCommandParser.cs | 1 - .../GivenDotnetAddReference.cs | 4 +-- .../GivenDotnetListReference.cs | 3 +- 4 files changed, 4 insertions(+), 40 deletions(-) diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index fbcbca261..f20359963 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -64,41 +64,5 @@ namespace Microsoft.DotNet.Cli public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory())); - - public static ArgumentsRule ExistingFilesOnly( - this ArgumentsRule rule) => - rule.And(new ArgumentsRule(o => - { - foreach (var filePath in o.Arguments) - { - if (!File.Exists(filePath) && - !Directory.Exists(filePath)) - { - return $"File not found: {filePath}"; - } - } - - return null; - })); - - public static ArgumentsRule ExistingSlnFileOrDirectoryOnly( - this ArgumentsRule rule) => - rule - .ExistingFilesOnly() - .And(new ArgumentsRule(o => - { - foreach (var path in o.Arguments) - { - if (path.HasExtension(".sln") || - path.IsDirectory()) - { - continue; - } - - return $"Specified path '{path}' is not a directory or solution file."; - } - - return null; - })); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-add/AddCommandParser.cs b/src/dotnet/commands/dotnet-add/AddCommandParser.cs index 645fc652f..fd1dcde1e 100644 --- a/src/dotnet/commands/dotnet-add/AddCommandParser.cs +++ b/src/dotnet/commands/dotnet-add/AddCommandParser.cs @@ -19,7 +19,6 @@ namespace Microsoft.DotNet.Cli "add", ".NET Add Command", Accept.ExactlyOneArgument() - .ExistingFilesOnly() .DefaultToCurrentDirectory() .With(name: "PROJECT", description: "The project file to operate on. If a file is not specified, the command will search the current directory for one."), diff --git a/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs b/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs index 71984d279..2192205d4 100644 --- a/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs +++ b/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs @@ -112,8 +112,8 @@ Options: .WithProject("one two three") .Execute("proj.csproj"); cmd.ExitCode.Should().NotBe(0); - cmd.StdErr.Should().Be("Unrecognized command or argument 'two'"); - cmd.StdOut.Should().Be("Specify --help for a list of available options and commands."); + cmd.StdErr.Should().BeVisuallyEquivalentTo( + "Unrecognized command or argument 'two'\r\nUnrecognized command or argument 'three'"); } [Theory] diff --git a/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs b/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs index e11317825..a4337273b 100644 --- a/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs +++ b/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs @@ -57,7 +57,8 @@ Options: .WithProject("one two three") .Execute("proj.csproj"); cmd.ExitCode.Should().NotBe(0); - cmd.StdErr.Should().Be("Unrecognized command or argument 'two'"); + cmd.StdErr.Should().BeVisuallyEquivalentTo( + "Unrecognized command or argument 'one'\r\nUnrecognized command or argument 'two'\r\nUnrecognized command or argument 'three'"); } [Theory] From 8aa702dc97998ec4de0ff4b507347f230811fb56 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Thu, 16 Mar 2017 10:46:08 -0700 Subject: [PATCH 095/149] text fixes for dotnet remove --- src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs | 1 - test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs b/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs index d5af30cd1..7a7dcfa01 100644 --- a/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs +++ b/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs @@ -13,7 +13,6 @@ namespace Microsoft.DotNet.Cli Create.Command("remove", ".NET Remove Command", Accept.ExactlyOneArgument() - .ExistingFilesOnly() .DefaultToCurrentDirectory() .With(name: "PROJECT", description: CommonLocalizableStrings.ArgumentsProjectDescription) diff --git a/test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs b/test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs index a02968355..956d380d7 100644 --- a/test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs +++ b/test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs @@ -138,8 +138,7 @@ Options: .WithProject("one two three") .Execute("proj.csproj"); cmd.ExitCode.Should().NotBe(0); - cmd.StdErr.Should().Be("Unrecognized command or argument 'two'"); - cmd.StdOut.Should().Be("Specify --help for a list of available options and commands."); + cmd.StdErr.Should().BeVisuallyEquivalentTo("Unrecognized command or argument 'two'\r\nUnrecognized command or argument 'three'"); } [Theory] From 973021b21451317067b76794ab10853334bd0723 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Thu, 16 Mar 2017 13:22:08 -0700 Subject: [PATCH 096/149] publish, cache, text fixes; rename ForwardAs and introduce ForwardAsMany --- src/dotnet/ArgumentForwardingExtensions.cs | 31 ++++++++------- src/dotnet/CommonOptions.cs | 10 ++--- .../commands/dotnet-add/AddCommandParser.cs | 8 ++-- .../dotnet-build/BuildCommandParser.cs | 2 +- .../dotnet-cache/CacheCommandParser.cs | 38 ++++++++++++------- .../dotnet-clean/CleanCommandParser.cs | 2 +- .../commands/dotnet-pack/PackCommandParser.cs | 2 +- .../dotnet-publish/PublishCommandParser.cs | 6 +-- .../dotnet-restore/RestoreCommandParser.cs | 8 ++-- .../commands/dotnet-test/TestCommandParser.cs | 16 ++++---- .../GivenDotnetListReference.cs | 2 +- .../GivenDotnetCacheInvocation.cs | 1 + .../GivenDotnetSlnList.cs | 2 +- .../GivenDotnetSlnRemove.cs | 3 +- .../ArgumentForwardingExtensionsTests.cs | 4 +- 15 files changed, 72 insertions(+), 63 deletions(-) diff --git a/src/dotnet/ArgumentForwardingExtensions.cs b/src/dotnet/ArgumentForwardingExtensions.cs index ac8aa9c4a..da4a3cdc9 100644 --- a/src/dotnet/ArgumentForwardingExtensions.cs +++ b/src/dotnet/ArgumentForwardingExtensions.cs @@ -13,37 +13,36 @@ namespace Microsoft.DotNet.Cli public static ArgumentsRule ForwardAs( this ArgumentsRule rule, - string template) => - rule.MaterializeAs(o => new ForwardedArgument(template)); + string value) => + rule.MaterializeAs(o => new ForwardedArgument(value)); - public static ArgumentsRule ForwardAs( + public static ArgumentsRule ForwardAsSingle( this ArgumentsRule rule, Func format) => rule.MaterializeAs(o => - new ForwardedArgument(format(o))); + new ForwardedArgument(format(o))); + + public static ArgumentsRule ForwardAsMany( + this ArgumentsRule rule, + Func> format) => + rule.MaterializeAs(o => + new ForwardedArgument(format(o).ToArray())); public static IEnumerable OptionValuesToBeForwarded( this AppliedOption command) => command.AppliedOptions .Select(o => o.Value()) .OfType() - .Select(o => o.ToString()); + .SelectMany(o => o.Values); private class ForwardedArgument { - private readonly string _value; - - public ForwardedArgument(string value) + public ForwardedArgument(params string[] values) { - _value = value; + Values = values; } - public override string ToString() => _value; - - public static explicit operator string(ForwardedArgument argument) - { - return argument.ToString(); - } + public string[] Values { get; } } } -} +} \ No newline at end of file diff --git a/src/dotnet/CommonOptions.cs b/src/dotnet/CommonOptions.cs index f20359963..4dc1dfacf 100644 --- a/src/dotnet/CommonOptions.cs +++ b/src/dotnet/CommonOptions.cs @@ -25,7 +25,7 @@ namespace Microsoft.DotNet.Cli "n", "normal", "d", "detailed", "diag", "diagnostic") - .ForwardAs(o => $"/verbosity:{o.Arguments.Single()}")); + .ForwardAsSingle(o => $"/verbosity:{o.Arguments.Single()}")); public static Option FrameworkOption() => Create.Option( @@ -34,7 +34,7 @@ namespace Microsoft.DotNet.Cli Accept.ExactlyOneArgument() .WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile()) .With(name: "FRAMEWORK") - .ForwardAs(o => $"/p:TargetFramework={o.Arguments.Single()}")); + .ForwardAsSingle(o => $"/p:TargetFramework={o.Arguments.Single()}")); public static Option RuntimeOption() => Create.Option( @@ -43,7 +43,7 @@ namespace Microsoft.DotNet.Cli Accept.ExactlyOneArgument() .WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile()) .With(name: "RUNTIME_IDENTIFIER") - .ForwardAs(o => $"/p:RuntimeIdentifier={o.Arguments.Single()}")); + .ForwardAsSingle(o => $"/p:RuntimeIdentifier={o.Arguments.Single()}")); public static Option ConfigurationOption() => Create.Option( @@ -52,7 +52,7 @@ namespace Microsoft.DotNet.Cli Accept.ExactlyOneArgument() .With(name: "CONFIGURATION") .WithSuggestionsFrom("DEBUG", "RELEASE") - .ForwardAs(o => $"/p:Configuration={o.Arguments.Single()}")); + .ForwardAsSingle(o => $"/p:Configuration={o.Arguments.Single()}")); public static Option VersionSuffixOption() => Create.Option( @@ -60,7 +60,7 @@ namespace Microsoft.DotNet.Cli "Defines the value for the $(VersionSuffix) property in the project.", Accept.ExactlyOneArgument() .With(name: "VERSION_SUFFIX") - .ForwardAs(o => $"/p:VersionSuffix={o.Arguments.Single()}")); + .ForwardAsSingle(o => $"/p:VersionSuffix={o.Arguments.Single()}")); public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) => rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory())); diff --git a/src/dotnet/commands/dotnet-add/AddCommandParser.cs b/src/dotnet/commands/dotnet-add/AddCommandParser.cs index fd1dcde1e..ed816ace3 100644 --- a/src/dotnet/commands/dotnet-add/AddCommandParser.cs +++ b/src/dotnet/commands/dotnet-add/AddCommandParser.cs @@ -34,24 +34,24 @@ namespace Microsoft.DotNet.Cli "Version for the package to be added.", Accept.ExactlyOneArgument() .With(name: "VERSION") - .ForwardAs(o => $"--version {o.Arguments.Single()}")), + .ForwardAsSingle(o => $"--version {o.Arguments.Single()}")), Create.Option("-f|--framework", LocalizableStrings.CmdFrameworkDescription, Accept.ExactlyOneArgument() .With(name: "FRAMEWORK") - .ForwardAs(o => $"--framework {o.Arguments.Single()}")), + .ForwardAsSingle(o => $"--framework {o.Arguments.Single()}")), Create.Option("-n|--no-restore ", "Add reference without performing restore preview and compatibility check."), Create.Option("-s|--source", "Use specific NuGet package sources to use during the restore.", Accept.ExactlyOneArgument() .With(name: "SOURCE") - .ForwardAs(o => $"--source {o.Arguments.Single()}")), + .ForwardAsSingle(o => $"--source {o.Arguments.Single()}")), Create.Option("--package-directory", "Restore the packages to this Directory .", Accept.ExactlyOneArgument() .With(name: "PACKAGE_DIRECTORY") - .ForwardAs(o => $"--package-directory {o.Arguments.Single()}"))), + .ForwardAsSingle(o => $"--package-directory {o.Arguments.Single()}"))), Create.Command( "reference", Tools.Add.ProjectToProjectReference.LocalizableStrings.AppFullName, diff --git a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs index b1a492318..e75d179e6 100644 --- a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs +++ b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs @@ -23,7 +23,7 @@ namespace Microsoft.DotNet.Cli LocalizableStrings.OutputOptionDescription, Accept.ExactlyOneArgument() .With(name: LocalizableStrings.OutputOptionName) - .ForwardAs(o => $"/p:OutputPath={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/p:OutputPath={o.Arguments.Single()}")), CommonOptions.FrameworkOption(), CommonOptions.RuntimeOption(), CommonOptions.ConfigurationOption(), diff --git a/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs b/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs index 1c5985152..382795680 100644 --- a/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs +++ b/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs @@ -19,24 +19,34 @@ namespace Microsoft.DotNet.Cli "-e|--entries", LocalizableStrings.ProjectEntryDescription, Accept.OneOrMoreArguments() - .With(name: LocalizableStrings.ProjectEntries) - .ForwardAs(o => - { - var materializedString = $"{o.Arguments.First()}"; + .With(name: LocalizableStrings.ProjectEntries) + .ForwardAsMany(o => + { + var materializedString = $"{o.Arguments.First()}"; - if (o.Arguments.Count() == 1) return materializedString; - - var additionalProjects = string.Join("%3B", o.Arguments.Skip(1)); - - return $"{materializedString} /p:AdditionalProjects={additionalProjects}"; - })), + if (o.Arguments.Count == 1) + { + return new[] + { + materializedString + }; + } + else + { + return new[] + { + materializedString, + $"/p:AdditionalProjects={string.Join("%3B", o.Arguments.Skip(1))}" + }; + } + })), CommonOptions.FrameworkOption(), Create.Option( "--framework-version", LocalizableStrings.FrameworkVersionOptionDescription, Accept.ExactlyOneArgument() .With(name: LocalizableStrings.FrameworkVersionOption) - .ForwardAs(o => $"/p:FX_Version={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/p:FX_Version={o.Arguments.Single()}")), CommonOptions.RuntimeOption(), CommonOptions.ConfigurationOption(), Create.Option( @@ -44,18 +54,18 @@ namespace Microsoft.DotNet.Cli LocalizableStrings.OutputOptionDescription, Accept.ExactlyOneArgument() .With(name: LocalizableStrings.OutputOption) - .ForwardAs(o => $"/p:ComposeDir={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/p:ComposeDir={o.Arguments.Single()}")), Create.Option( "-w|--working-dir", LocalizableStrings.IntermediateWorkingDirOptionDescription, Accept.ExactlyOneArgument() .With(name: LocalizableStrings.IntermediateWorkingDirOption) - .ForwardAs(o => $"/p:ComposeWorkingDir={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/p:ComposeWorkingDir={o.Arguments.Single()}")), Create.Option( "--preserve-working-dir", LocalizableStrings.PreserveIntermediateWorkingDirOptionDescription, Accept.NoArguments() - .ForwardAs(o => $"/p:PreserveComposeWorkingDir=true")), + .ForwardAsSingle(o => $"/p:PreserveComposeWorkingDir=true")), Create.Option( "--skip-optimization", LocalizableStrings.SkipOptimizationOptionDescription, diff --git a/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs b/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs index d157d9d52..3a78ebfa9 100644 --- a/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs +++ b/src/dotnet/commands/dotnet-clean/CleanCommandParser.cs @@ -19,7 +19,7 @@ namespace Microsoft.DotNet.Cli LocalizableStrings.CmdOutputDirDescription, Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdOutputDir) - .ForwardAs(o => $"/p:OutputPath={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/p:OutputPath={o.Arguments.Single()}")), CommonOptions.FrameworkOption(), CommonOptions.ConfigurationOption(), CommonOptions.VerbosityOption()); diff --git a/src/dotnet/commands/dotnet-pack/PackCommandParser.cs b/src/dotnet/commands/dotnet-pack/PackCommandParser.cs index d470d0127..56be1ee3d 100644 --- a/src/dotnet/commands/dotnet-pack/PackCommandParser.cs +++ b/src/dotnet/commands/dotnet-pack/PackCommandParser.cs @@ -20,7 +20,7 @@ namespace Microsoft.DotNet.Cli LocalizableStrings.CmdOutputDirDescription, Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdOutputDir) - .ForwardAs(o => $"/p:PackageOutputPath={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/p:PackageOutputPath={o.Arguments.Single()}")), Create.Option( "--no-build", LocalizableStrings.CmdNoBuildOptionDescription, diff --git a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs index c6ca8361f..0372ae89f 100644 --- a/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs +++ b/src/dotnet/commands/dotnet-publish/PublishCommandParser.cs @@ -22,15 +22,15 @@ namespace Microsoft.DotNet.Cli LocalizableStrings.OutputOptionDescription, Accept.ExactlyOneArgument() .With(name: LocalizableStrings.OutputOption) - .ForwardAs(o => $"/p:PublishDir={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/p:PublishDir={o.Arguments.Single()}")), CommonOptions.ConfigurationOption(), CommonOptions.VersionSuffixOption(), Create.Option( "--filter", LocalizableStrings.FilterProjOptionDescription, - Accept.ExactlyOneArgument() + Accept.OneOrMoreArguments() .With(name: LocalizableStrings.FilterProjOption) - .ForwardAs(o => $"/p:FilterProjectFiles={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/p:FilterProjectFiles={string.Join("%3B", o.Arguments)}")), CommonOptions.VerbosityOption()); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs b/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs index 34a98764c..f42acad6b 100644 --- a/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs +++ b/src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs @@ -20,20 +20,20 @@ namespace Microsoft.DotNet.Cli LocalizableStrings.CmdSourceOptionDescription, Accept.OneOrMoreArguments() .With(name: LocalizableStrings.CmdSourceOption) - .ForwardAs(o => $"/p:RestoreSources={string.Join("%3B", o.Arguments)}")), + .ForwardAsSingle(o => $"/p:RestoreSources={string.Join("%3B", o.Arguments)}")), Create.Option( "-r|--runtime", LocalizableStrings.CmdRuntimeOptionDescription, Accept.OneOrMoreArguments() .WithSuggestionsFrom(_ => Suggest.RunTimesFromProjectFile()) .With(name: LocalizableStrings.CmdRuntimeOption) - .ForwardAs(o => $"/p:RuntimeIdentifiers={string.Join("%3B", o.Arguments)}")), + .ForwardAsSingle(o => $"/p:RuntimeIdentifiers={string.Join("%3B", o.Arguments)}")), Create.Option( "--packages", LocalizableStrings.CmdPackagesOptionDescription, Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdPackagesOption) - .ForwardAs(o => $"/p:RestorePackagesPath={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/p:RestorePackagesPath={o.Arguments.Single()}")), Create.Option( "--disable-parallel", LocalizableStrings.CmdDisableParallelOptionDescription, @@ -44,7 +44,7 @@ namespace Microsoft.DotNet.Cli LocalizableStrings.CmdConfigFileOptionDescription, Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdConfigFileOption) - .ForwardAs(o => $"/p:RestoreConfigFile={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/p:RestoreConfigFile={o.Arguments.Single()}")), Create.Option( "--no-cache", LocalizableStrings.CmdNoCacheOptionDescription, diff --git a/src/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/dotnet/commands/dotnet-test/TestCommandParser.cs index b885acf3b..029734404 100644 --- a/src/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -20,30 +20,30 @@ namespace Microsoft.DotNet.Cli LocalizableStrings.CmdSettingsDescription, Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdSettingsFile) - .ForwardAs(o => $"/p:VSTestSetting={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/p:VSTestSetting={o.Arguments.Single()}")), Create.Option( "-t|--list-tests", LocalizableStrings.CmdListTestsDescription, Accept.NoArguments() - .ForwardAs(o => "/p:VSTestListTests=true")), + .ForwardAsSingle(o => "/p:VSTestListTests=true")), Create.Option( "--filter", LocalizableStrings.CmdTestCaseFilterDescription, Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdTestCaseFilterExpression) - .ForwardAs(o => $"/p:VSTestTestCaseFilter={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/p:VSTestTestCaseFilter={o.Arguments.Single()}")), Create.Option( "-a|--test-adapter-path", LocalizableStrings.CmdTestAdapterPathDescription, Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdTestAdapterPath) - .ForwardAs(o => $"/p:VSTestTestAdapterPath={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/p:VSTestTestAdapterPath={o.Arguments.Single()}")), Create.Option( "-l|--logger", LocalizableStrings.CmdLoggerDescription, Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdLoggerOption) - .ForwardAs(o => + .ForwardAsSingle(o => { var loggersString = string.Join(";", GetSemiColonEscapedArgs(o.Arguments)); @@ -56,18 +56,18 @@ namespace Microsoft.DotNet.Cli LocalizableStrings.CmdOutputDescription, Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdOutputDir) - .ForwardAs(o => $"/p:OutputPath={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/p:OutputPath={o.Arguments.Single()}")), Create.Option( "-d|--diag", LocalizableStrings.CmdPathTologFileDescription, Accept.ExactlyOneArgument() .With(name: LocalizableStrings.CmdPathToLogFile) - .ForwardAs(o => $"/p:VSTestDiag={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/p:VSTestDiag={o.Arguments.Single()}")), Create.Option( "--no-build", LocalizableStrings.CmdNoBuildDescription, Accept.NoArguments() - .ForwardAs(o => "/p:VSTestNoBuild=true")), + .ForwardAsSingle(o => "/p:VSTestNoBuild=true")), CommonOptions.VerbosityOption()); private static string GetSemiColonEsacpedstring(string arg) diff --git a/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs b/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs index a4337273b..f82c98700 100644 --- a/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs +++ b/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs @@ -58,7 +58,7 @@ Options: .Execute("proj.csproj"); cmd.ExitCode.Should().NotBe(0); cmd.StdErr.Should().BeVisuallyEquivalentTo( - "Unrecognized command or argument 'one'\r\nUnrecognized command or argument 'two'\r\nUnrecognized command or argument 'three'"); + "Unrecognized command or argument 'two'\r\nUnrecognized command or argument 'three'"); } [Theory] diff --git a/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs index a65a6793d..29ee67a13 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs @@ -31,6 +31,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [InlineData(new string[] { "--framework", "" }, @"/p:TargetFramework=")] [InlineData(new string[] { "-r", "" }, @"/p:RuntimeIdentifier=")] [InlineData(new string[] { "--runtime", "" }, @"/p:RuntimeIdentifier=")] + [InlineData(new string[] { "--entries", "one.xml", "--entries", "two.xml", "--entries", "three.xml" }, @"/p:AdditionalProjects=one.xml%3Btwo.xml%3Bthree.xml")] public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs) { args = ArgsPrefix.Concat(args).ToArray(); diff --git a/test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs b/test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs index f8f785071..abaa51cea 100644 --- a/test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs +++ b/test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs @@ -52,7 +52,7 @@ Options: var cmd = new DotnetCommand() .ExecuteWithCapturedOutput("sln one.sln two.sln three.sln list"); cmd.Should().Fail(); - cmd.StdErr.Should().Be("Unrecognized command or argument 'two.sln'"); + cmd.StdErr.Should().BeVisuallyEquivalentTo("Unrecognized command or argument 'two.sln'\r\nUnrecognized command or argument 'three.sln'"); } [Theory] diff --git a/test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs b/test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs index bc3594607..c0e51ff8a 100644 --- a/test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs +++ b/test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs @@ -175,8 +175,7 @@ EndGlobal var cmd = new DotnetCommand() .ExecuteWithCapturedOutput("sln one.sln two.sln three.sln remove"); cmd.Should().Fail(); - cmd.StdErr.Should().Be("Unrecognized command or argument 'two.sln'"); - cmd.StdOut.Should().Be("Specify --help for a list of available options and commands."); + cmd.StdErr.Should().BeVisuallyEquivalentTo("Unrecognized command or argument 'two.sln'\r\nUnrecognized command or argument 'three.sln'\r\nYou must specify at least one project to remove."); } [Theory] diff --git a/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs b/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs index 99fe3fb88..c445c9812 100644 --- a/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs +++ b/test/dotnet.Tests/ParserTests/ArgumentForwardingExtensionsTests.cs @@ -19,7 +19,7 @@ namespace Microsoft.DotNet.Tests.ParserTests var command = Command("the-command", "", Option("-o|--one", "", ZeroOrOneArgument() - .ForwardAs(o => $"/i:{o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/i:{o.Arguments.Single()}")), Option("-t|--two", "", NoArguments() .ForwardAs("/s:true"))); @@ -38,7 +38,7 @@ namespace Microsoft.DotNet.Tests.ParserTests var command = Command("the-command", "", Option("-x", "", ZeroOrMoreArguments() - .ForwardAs(o => $"/x:{string.Join("&", o.Arguments)}"))); + .ForwardAsSingle(o => $"/x:{string.Join("&", o.Arguments)}"))); var result = command.Parse("the-command -x one -x two"); From e5d7fb8236031bbfa1296fa5469b6cacb9b3f93f Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Thu, 16 Mar 2017 13:34:12 -0700 Subject: [PATCH 097/149] change test's expected text --- test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs b/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs index 9461e59a7..8ee3ca5c4 100644 --- a/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs +++ b/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs @@ -201,8 +201,7 @@ EndGlobal var cmd = new DotnetCommand() .ExecuteWithCapturedOutput("sln one.sln two.sln three.sln add"); cmd.Should().Fail(); - cmd.StdErr.Should().Be("Unrecognized command or argument 'two.sln'"); - cmd.StdOut.Should().Be("Specify --help for a list of available options and commands."); + cmd.StdErr.Should().BeVisuallyEquivalentTo("Unrecognized command or argument 'two.sln'\r\nUnrecognized command or argument 'three.sln'\r\nYou must specify at least one project to add."); } [Theory] From 4d8bab8389a123e8516a89964318e02441dc6368 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Thu, 16 Mar 2017 15:46:27 -0700 Subject: [PATCH 098/149] remove extra diagnostic output from ForwardApp --- src/dotnet/ForwardingApp.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/dotnet/ForwardingApp.cs b/src/dotnet/ForwardingApp.cs index aad57a197..2ae292b75 100644 --- a/src/dotnet/ForwardingApp.cs +++ b/src/dotnet/ForwardingApp.cs @@ -80,8 +80,6 @@ namespace Microsoft.DotNet.Cli UseShellExecute = false }; - Reporter.Output.WriteLine($"[Forwarding] {processInfo.FileName} {processInfo.Arguments}"); - if (_environmentVariables != null) { foreach (var entry in _environmentVariables) From 4d4ebf9d3a8584463fd71782cd3892ba709dee3d Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Thu, 16 Mar 2017 17:05:18 -0700 Subject: [PATCH 099/149] put colon back into logger parameter --- test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs index 8d03c666a..a6c72d638 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs @@ -19,7 +19,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities { protected const string DefaultFramework = "netcoreapp1.0"; protected const string DefaultLibraryFramework = "netstandard1.5"; - protected const string ConsoleLoggerOutputNormal = "--logger console;verbosity=normal"; + protected const string ConsoleLoggerOutputNormal = "--logger:console;verbosity=normal"; private TempRoot _temp; private static TestAssets s_testAssets; @@ -42,7 +42,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities s_testAssets = new TestAssets( new DirectoryInfo(assetsRoot), - new FileInfo(new EnvironmentProvider().GetCommandPath("dotnet")), + new FileInfo(new Muxer().MuxerPath), new FileInfo(new RepoDirectoriesProvider().PjDotnet)); } From de6a4bd022591e2e45cc2deb8001c32d8998aa8a Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Thu, 16 Mar 2017 23:15:45 -0700 Subject: [PATCH 100/149] fix a few tests, revert one change --- test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs | 2 +- test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs | 2 +- test/dotnet-vstest.Tests/VSTestTests.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs index a6c72d638..e2e1269a6 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs @@ -19,7 +19,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities { protected const string DefaultFramework = "netcoreapp1.0"; protected const string DefaultLibraryFramework = "netstandard1.5"; - protected const string ConsoleLoggerOutputNormal = "--logger:console;verbosity=normal"; + protected const string ConsoleLoggerOutputNormal = "--logger console;verbosity=normal"; private TempRoot _temp; private static TestAssets s_testAssets; diff --git a/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs index 29ee67a13..936c12d69 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetCacheInvocation.cs @@ -47,7 +47,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [InlineData("--output")] public void ItAddsOutputPathToMsBuildInvocation(string optionName) { - string path = Directory.GetCurrentDirectory(); + string path = "/some/path"; var args = ArgsPrefix.Concat(new string[] { optionName, path }).ToArray(); var msbuildPath = ""; diff --git a/test/dotnet-vstest.Tests/VSTestTests.cs b/test/dotnet-vstest.Tests/VSTestTests.cs index 37d307708..cd7b0e8e9 100644 --- a/test/dotnet-vstest.Tests/VSTestTests.cs +++ b/test/dotnet-vstest.Tests/VSTestTests.cs @@ -34,7 +34,7 @@ namespace Microsoft.DotNet.Cli.VSTest.Tests .GetDirectory("bin", configuration, "netcoreapp2.0") .GetFile($"{testAppName}.dll"); - var argsForVstest = $"\"{outputDll.FullName}\" {TestBase.ConsoleLoggerOutputNormal}"; + var argsForVstest = $"\"{outputDll.FullName}\" --logger:console;verbosity=normal"; // Call vstest var result = new VSTestCommand().ExecuteWithCapturedOutput(argsForVstest); From 0d04b51c93b6da4c55ed17a0b5b21f575b2c94cc Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Fri, 17 Mar 2017 11:06:58 -0700 Subject: [PATCH 101/149] get the full path for dotnet cache output --- src/dotnet/commands/dotnet-cache/CacheCommandParser.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs b/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs index 382795680..b1ed74d8f 100644 --- a/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs +++ b/src/dotnet/commands/dotnet-cache/CacheCommandParser.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.IO; using System.Linq; using Microsoft.DotNet.Cli.CommandLine; using LocalizableStrings = Microsoft.DotNet.Tools.Cache.LocalizableStrings; @@ -54,7 +55,7 @@ namespace Microsoft.DotNet.Cli LocalizableStrings.OutputOptionDescription, Accept.ExactlyOneArgument() .With(name: LocalizableStrings.OutputOption) - .ForwardAsSingle(o => $"/p:ComposeDir={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"/p:ComposeDir={Path.GetFullPath(o.Arguments.Single())}")), Create.Option( "-w|--working-dir", LocalizableStrings.IntermediateWorkingDirOptionDescription, From f8e051895e9188d1e5b16a53afb9eebed8cb628f Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Fri, 17 Mar 2017 13:28:21 -0700 Subject: [PATCH 102/149] re-enable colon and equals signs as argument delimiters --- src/dotnet/Parser.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dotnet/Parser.cs b/src/dotnet/Parser.cs index ebfe1a8db..e47427316 100644 --- a/src/dotnet/Parser.cs +++ b/src/dotnet/Parser.cs @@ -9,7 +9,6 @@ namespace Microsoft.DotNet.Cli public static class Parser { public static CommandLine.Parser Instance { get; } = new CommandLine.Parser( - delimiters: Array.Empty(), options: Create.Command("dotnet", ".NET Command Line Tools", Accept.NoArguments(), From ca914334eadccfeb4cdfa0137d4fe0d890d8fcd4 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Sun, 19 Mar 2017 13:02:09 -0700 Subject: [PATCH 103/149] revert logger colon change --- build_projects/dotnet-cli-build/DotNetTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_projects/dotnet-cli-build/DotNetTest.cs b/build_projects/dotnet-cli-build/DotNetTest.cs index 735356771..6ed55055c 100644 --- a/build_projects/dotnet-cli-build/DotNetTest.cs +++ b/build_projects/dotnet-cli-build/DotNetTest.cs @@ -37,7 +37,7 @@ namespace Microsoft.DotNet.Cli.Build { if (!string.IsNullOrEmpty(Logger)) { - return $"--logger {Logger}"; + return $"--logger:{Logger}"; } return null; From e0ca794ed5579bc4469207e27e7094f13df036c1 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Sun, 19 Mar 2017 13:02:34 -0700 Subject: [PATCH 104/149] compare effective rather than literal path --- .../Microsoft.DotNet.Cli.Sln.Internal.Tests.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.DotNet.Cli.Sln.Internal.Tests/Microsoft.DotNet.Cli.Sln.Internal.Tests.cs b/test/Microsoft.DotNet.Cli.Sln.Internal.Tests/Microsoft.DotNet.Cli.Sln.Internal.Tests.cs index 1fb96775e..1a2155266 100644 --- a/test/Microsoft.DotNet.Cli.Sln.Internal.Tests/Microsoft.DotNet.Cli.Sln.Internal.Tests.cs +++ b/test/Microsoft.DotNet.Cli.Sln.Internal.Tests/Microsoft.DotNet.Cli.Sln.Internal.Tests.cs @@ -104,12 +104,23 @@ EndGlobal SlnFile slnFile = SlnFile.Read(tmpFile.Path); + Console.WriteLine(new + { + slnFile_FormatVersion = slnFile.FormatVersion, + slnFile_ProductDescription = slnFile.ProductDescription, + slnFile_VisualStudioVersion = slnFile.VisualStudioVersion, + slnFile_MinimumVisualStudioVersion = slnFile.MinimumVisualStudioVersion, + slnFile_BaseDirectory = slnFile.BaseDirectory, + slnFile_FullPath = slnFile.FullPath, + tmpFilePath = tmpFile.Path + }.ToString()); + slnFile.FormatVersion.Should().Be("12.00"); slnFile.ProductDescription.Should().Be("Visual Studio 15"); slnFile.VisualStudioVersion.Should().Be("15.0.26006.2"); slnFile.MinimumVisualStudioVersion.Should().Be("10.0.40219.1"); slnFile.BaseDirectory.Should().Be(Path.GetDirectoryName(tmpFile.Path)); - slnFile.FullPath.Should().Be(tmpFile.Path); + slnFile.FullPath.Should().Be(Path.GetFullPath(tmpFile.Path)); slnFile.Projects.Count.Should().Be(2); var project = slnFile.Projects[0]; From 43c13f2f5330149581dbf3ad44c22fdbd3db6ddf Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Sun, 19 Mar 2017 14:30:43 -0700 Subject: [PATCH 105/149] move parse result validation to CommandBase to allow custom messages --- src/dotnet/CommandBase.cs | 14 +++++++++++++- src/dotnet/DotNetTopLevelCommandBase.cs | 19 +++++++------------ src/dotnet/commands/dotnet-add/Program.cs | 6 ++++-- .../dotnet-add/dotnet-add-package/Program.cs | 13 ++++++++++++- .../dotnet-add-reference/Program.cs | 3 ++- src/dotnet/commands/dotnet-list/Program.cs | 7 ++++++- .../dotnet-list-reference/Program.cs | 4 +++- src/dotnet/commands/dotnet-remove/Program.cs | 6 ++++-- .../dotnet-remove-package/Program.cs | 3 ++- .../dotnet-remove-reference/Program.cs | 3 ++- src/dotnet/commands/dotnet-sln/Program.cs | 9 ++++++--- src/dotnet/commands/dotnet-sln/add/Program.cs | 5 ++++- .../commands/dotnet-sln/list/Program.cs | 5 ++++- .../commands/dotnet-sln/remove/Program.cs | 5 ++++- src/dotnet/dotnet.csproj | 2 +- test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 16 files changed, 75 insertions(+), 31 deletions(-) diff --git a/src/dotnet/CommandBase.cs b/src/dotnet/CommandBase.cs index ce9bb13e3..2f4e6316a 100644 --- a/src/dotnet/CommandBase.cs +++ b/src/dotnet/CommandBase.cs @@ -1,10 +1,22 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using Microsoft.DotNet.Cli.CommandLine; + namespace Microsoft.DotNet.Cli { public abstract class CommandBase { + protected CommandBase(ParseResult parseResult) + { + ShowHelpOrErrorIfAppropriate(parseResult); + } + + protected virtual void ShowHelpOrErrorIfAppropriate(ParseResult parseResult) + { + parseResult.ShowHelpOrErrorIfAppropriate(); + } + public abstract int Execute(); } -} \ No newline at end of file +} diff --git a/src/dotnet/DotNetTopLevelCommandBase.cs b/src/dotnet/DotNetTopLevelCommandBase.cs index ea5abba13..5e2850ee5 100644 --- a/src/dotnet/DotNetTopLevelCommandBase.cs +++ b/src/dotnet/DotNetTopLevelCommandBase.cs @@ -16,6 +16,8 @@ namespace Microsoft.DotNet.Cli protected abstract string FullCommandNameLocalized { get; } protected abstract string ArgumentName { get; } protected abstract string ArgumentDescriptionLocalized { get; } + protected ParseResult ParseResult { get; private set; } + internal abstract Dictionary> SubCommands { get; } public int RunCommand(string[] args) @@ -24,33 +26,26 @@ namespace Microsoft.DotNet.Cli var parser = Parser.Instance; - var result = parser.ParseFrom($"dotnet {CommandName}", args); + ParseResult = parser.ParseFrom($"dotnet {CommandName}", args); - result.ShowHelpOrErrorIfAppropriate(); - - var subcommandName = result.Command().Name; + var subcommandName = ParseResult.Command().Name; try { var create = SubCommands[subcommandName]; - var command = create(result["dotnet"][CommandName]); + var command = create(ParseResult["dotnet"][CommandName]); return command.Execute(); } - catch (KeyNotFoundException e) + catch (KeyNotFoundException) { throw new GracefulException(CommonLocalizableStrings.RequiredCommandNotPassed); } catch (GracefulException e) { Reporter.Error.WriteLine(e.Message.Red()); - result.ShowHelp(); - return 1; - } - catch (CommandParsingException e) - { - Reporter.Error.WriteLine(e.Message.Red()); + ParseResult.ShowHelp(); return 1; } } diff --git a/src/dotnet/commands/dotnet-add/Program.cs b/src/dotnet/commands/dotnet-add/Program.cs index c3698dfe7..829c5e454 100644 --- a/src/dotnet/commands/dotnet-add/Program.cs +++ b/src/dotnet/commands/dotnet-add/Program.cs @@ -25,12 +25,14 @@ namespace Microsoft.DotNet.Tools.Add ["reference"] = add => new AddProjectToProjectReferenceCommand( add["reference"], - add.Value()), + add.Value(), + ParseResult), ["package"] = add => new AddPackageReferenceCommand( add["package"], - add.Value()) + add.Value(), + ParseResult) }; public static int Run(string[] args) diff --git a/src/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs b/src/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs index 2ebaf833f..7b32750fb 100644 --- a/src/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs +++ b/src/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs @@ -22,7 +22,8 @@ namespace Microsoft.DotNet.Tools.Add.PackageReference public AddPackageReferenceCommand( AppliedOption appliedCommand, - string fileOrDirectory) + string fileOrDirectory, + ParseResult parseResult) : base(parseResult) { if (appliedCommand == null) { @@ -38,6 +39,16 @@ namespace Microsoft.DotNet.Tools.Add.PackageReference _packageId = appliedCommand.Value(); } + protected override void ShowHelpOrErrorIfAppropriate(ParseResult parseResult) + { + if (parseResult.UnmatchedTokens.Any()) + { + throw new GracefulException(LocalizableStrings.SpecifyExactlyOnePackageReference); + } + + base.ShowHelpOrErrorIfAppropriate(parseResult); + } + public override int Execute() { var projectFilePath = string.Empty; diff --git a/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs b/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs index c63391a15..72498b37f 100644 --- a/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs +++ b/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs @@ -22,7 +22,8 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference public AddProjectToProjectReferenceCommand( AppliedOption appliedCommand, - string fileOrDirectory) + string fileOrDirectory, + ParseResult parseResult) : base(parseResult) { if (appliedCommand == null) { diff --git a/src/dotnet/commands/dotnet-list/Program.cs b/src/dotnet/commands/dotnet-list/Program.cs index f4b39cb04..403302b39 100644 --- a/src/dotnet/commands/dotnet-list/Program.cs +++ b/src/dotnet/commands/dotnet-list/Program.cs @@ -20,7 +20,12 @@ namespace Microsoft.DotNet.Tools.List internal override Dictionary> SubCommands => new Dictionary> { - { "reference", o => new ListProjectToProjectReferencesCommand(o) } + { + "reference", + o => new ListProjectToProjectReferencesCommand( + o, + ParseResult) + } }; public static int Run(string[] args) diff --git a/src/dotnet/commands/dotnet-list/dotnet-list-reference/Program.cs b/src/dotnet/commands/dotnet-list/dotnet-list-reference/Program.cs index fe33c9a0f..7a4f3cb18 100644 --- a/src/dotnet/commands/dotnet-list/dotnet-list-reference/Program.cs +++ b/src/dotnet/commands/dotnet-list/dotnet-list-reference/Program.cs @@ -14,7 +14,9 @@ namespace Microsoft.DotNet.Tools.List.ProjectToProjectReferences { private readonly string _fileOrDirectory; - public ListProjectToProjectReferencesCommand(AppliedOption appliedCommand) + public ListProjectToProjectReferencesCommand( + AppliedOption appliedCommand, + ParseResult parseResult) : base(parseResult) { if (appliedCommand == null) { diff --git a/src/dotnet/commands/dotnet-remove/Program.cs b/src/dotnet/commands/dotnet-remove/Program.cs index 086bdef6a..d77317f64 100644 --- a/src/dotnet/commands/dotnet-remove/Program.cs +++ b/src/dotnet/commands/dotnet-remove/Program.cs @@ -24,12 +24,14 @@ namespace Microsoft.DotNet.Tools.Remove ["reference"] = remove => new RemoveProjectToProjectReferenceCommand( remove["reference"], - remove.Value()), + remove.Value(), + ParseResult), ["package"] = remove => new RemovePackageReferenceCommand( remove["package"], - remove.Value()) + remove.Value(), + ParseResult) }; public static int Run(string[] args) diff --git a/src/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs b/src/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs index 7176c581a..de13b8b97 100644 --- a/src/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs +++ b/src/dotnet/commands/dotnet-remove/dotnet-remove-package/Program.cs @@ -18,7 +18,8 @@ namespace Microsoft.DotNet.Tools.Remove.PackageReference public RemovePackageReferenceCommand( AppliedOption appliedCommand, - string fileOrDirectory) + string fileOrDirectory, + ParseResult parseResult) : base(parseResult) { if (appliedCommand == null) { diff --git a/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs b/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs index ddfecfec9..e813dda3a 100644 --- a/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs +++ b/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs @@ -17,7 +17,8 @@ namespace Microsoft.DotNet.Tools.Remove.ProjectToProjectReference public RemoveProjectToProjectReferenceCommand( AppliedOption appliedCommand, - string fileOrDirectory) + string fileOrDirectory, + ParseResult parseResult) : base(parseResult) { if (appliedCommand == null) { diff --git a/src/dotnet/commands/dotnet-sln/Program.cs b/src/dotnet/commands/dotnet-sln/Program.cs index 2aea1f1b6..88dbe2993 100644 --- a/src/dotnet/commands/dotnet-sln/Program.cs +++ b/src/dotnet/commands/dotnet-sln/Program.cs @@ -25,18 +25,21 @@ namespace Microsoft.DotNet.Tools.Sln ["add"] = sln => new AddProjectToSolutionCommand( sln["add"], - sln.Value()), + sln.Value(), + ParseResult), ["list"] = sln => new ListProjectsInSolutionCommand( sln["list"], - sln.Value()), + sln.Value(), + ParseResult), ["remove"] = sln => new RemoveProjectFromSolutionCommand( sln["remove"], - sln.Value()) + sln.Value(), + ParseResult) }; public static int Run(string[] args) diff --git a/src/dotnet/commands/dotnet-sln/add/Program.cs b/src/dotnet/commands/dotnet-sln/add/Program.cs index 18bff60db..9ce0a7d09 100644 --- a/src/dotnet/commands/dotnet-sln/add/Program.cs +++ b/src/dotnet/commands/dotnet-sln/add/Program.cs @@ -17,7 +17,10 @@ namespace Microsoft.DotNet.Tools.Sln.Add private readonly AppliedOption _appliedCommand; private readonly string _fileOrDirectory; - public AddProjectToSolutionCommand(AppliedOption appliedCommand, string fileOrDirectory) + public AddProjectToSolutionCommand( + AppliedOption appliedCommand, + string fileOrDirectory, + ParseResult parseResult) : base(parseResult) { if (appliedCommand == null) { diff --git a/src/dotnet/commands/dotnet-sln/list/Program.cs b/src/dotnet/commands/dotnet-sln/list/Program.cs index 8b699caee..3b82bd255 100644 --- a/src/dotnet/commands/dotnet-sln/list/Program.cs +++ b/src/dotnet/commands/dotnet-sln/list/Program.cs @@ -15,7 +15,10 @@ namespace Microsoft.DotNet.Tools.Sln.List { private readonly string _fileOrDirectory; - public ListProjectsInSolutionCommand(AppliedOption appliedCommand, string fileOrDirectory) + public ListProjectsInSolutionCommand( + AppliedOption appliedCommand, + string fileOrDirectory, + ParseResult parseResult) : base(parseResult) { if (appliedCommand == null) { diff --git a/src/dotnet/commands/dotnet-sln/remove/Program.cs b/src/dotnet/commands/dotnet-sln/remove/Program.cs index c2c6cfd4d..ce2b88703 100644 --- a/src/dotnet/commands/dotnet-sln/remove/Program.cs +++ b/src/dotnet/commands/dotnet-sln/remove/Program.cs @@ -17,7 +17,10 @@ namespace Microsoft.DotNet.Tools.Sln.Remove private readonly AppliedOption _appliedCommand; private readonly string _fileOrDirectory; - public RemoveProjectFromSolutionCommand(AppliedOption appliedCommand, string fileOrDirectory) + public RemoveProjectFromSolutionCommand( + AppliedOption appliedCommand, + string fileOrDirectory, + ParseResult parseResult) : base(parseResult) { if (appliedCommand == null) { diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index a4cce6367..a9c9a6f86 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index d23100d8a..c37528336 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From b4cf73ec204c1a719c2c3d60c91fbc3c5f1ff485 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Sun, 19 Mar 2017 14:35:11 -0700 Subject: [PATCH 106/149] add additional args to dotnet run help --- src/dotnet/commands/dotnet-run/RunCommand.cs | 6 +-- .../commands/dotnet-run/RunCommandParser.cs | 48 +++++++++---------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/dotnet/commands/dotnet-run/RunCommand.cs b/src/dotnet/commands/dotnet-run/RunCommand.cs index e9f0c8bdd..225757c50 100644 --- a/src/dotnet/commands/dotnet-run/RunCommand.cs +++ b/src/dotnet/commands/dotnet-run/RunCommand.cs @@ -16,14 +16,10 @@ namespace Microsoft.DotNet.Tools.Run public string Configuration { get; set; } public string Framework { get; set; } public string Project { get; set; } - public IReadOnlyList Args { get; set; } + public IReadOnlyCollection Args { get; set; } private List _args; - public RunCommand() - { - } - public int Start() { Initialize(); diff --git a/src/dotnet/commands/dotnet-run/RunCommandParser.cs b/src/dotnet/commands/dotnet-run/RunCommandParser.cs index 737e43b23..1dc22c122 100644 --- a/src/dotnet/commands/dotnet-run/RunCommandParser.cs +++ b/src/dotnet/commands/dotnet-run/RunCommandParser.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System.Collections.Generic; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Tools.Run; using LocalizableStrings = Microsoft.DotNet.Tools.Run.LocalizableStrings; @@ -14,27 +13,28 @@ namespace Microsoft.DotNet.Cli Create.Command( "run", LocalizableStrings.AppFullName, - Accept.ZeroOrMoreArguments() - .MaterializeAs(o => - { - return new RunCommand() - { - Configuration = o.SingleArgumentOrDefault("--configuration"), - Framework = o.SingleArgumentOrDefault("--framework"), - Project = o.SingleArgumentOrDefault("--project"), - Args = (IReadOnlyList)o.Arguments - }; - }), - CommonOptions.HelpOption(), - CommonOptions.ConfigurationOption(), - CommonOptions.FrameworkOption(), - Create.Option( - "-p|--project", - LocalizableStrings.CommandOptionProjectDescription, - Accept.ExactlyOneArgument()), - Create.Option( - "--no-build", - LocalizableStrings.CommandOptionNoBuildDescription, - Accept.NoArguments().ForwardAs("/p:NoBuild=true"))); + treatUnmatchedTokensAsErrors: false, + arguments: Accept.ZeroOrMoreArguments() + .MaterializeAs(o => new RunCommand + { + Configuration = o.SingleArgumentOrDefault("--configuration"), + Framework = o.SingleArgumentOrDefault("--framework"), + Project = o.SingleArgumentOrDefault("--project"), + Args = o.Arguments + }), + options: new[] + { + CommonOptions.HelpOption(), + CommonOptions.ConfigurationOption(), + CommonOptions.FrameworkOption(), + Create.Option( + "-p|--project", + LocalizableStrings.CommandOptionProjectDescription, + Accept.ExactlyOneArgument()), + Create.Option( + "--no-build", + LocalizableStrings.CommandOptionNoBuildDescription, + Accept.NoArguments().ForwardAs("/p:NoBuild=true")) + }); } -} +} \ No newline at end of file From daac9457420cd5e1f97124776ba71a4b1bc48b91 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Sun, 19 Mar 2017 14:35:11 -0700 Subject: [PATCH 107/149] restore loc strings, subcommand parsers into separate files --- src/dotnet/CommonLocalizableStrings.cs | 4 +- .../commands/dotnet-add/AddCommandParser.cs | 84 ++----------------- .../dotnet-add-package/AddPackageParser.cs | 78 +++++++++++++++++ .../AddProjectToProjectReferenceParser.cs | 26 ++++++ .../dotnet-build/BuildCommandParser.cs | 3 +- .../commands/dotnet-list/ListCommandParser.cs | 11 +-- .../dotnet-migrate/MigrateCommandParser.cs | 40 +++++---- .../dotnet-remove/RemoveCommandParser.cs | 26 ++---- .../RemovePackageParser.cs | 14 ++++ .../RemoveProjectToProjectReferenceParser.cs | 25 ++++++ src/dotnet/commands/dotnet-run/RunCommand.cs | 6 +- .../commands/dotnet-run/RunCommandParser.cs | 48 +++++------ .../commands/dotnet-sln/SlnCommandParser.cs | 23 ++--- .../commands/dotnet-sln/add/SlnAddParser.cs | 20 +++++ .../commands/dotnet-sln/list/SlnListParser.cs | 16 ++++ .../dotnet-sln/remove/SlnRemoveParser.cs | 20 +++++ 16 files changed, 269 insertions(+), 175 deletions(-) create mode 100644 src/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs create mode 100644 src/dotnet/commands/dotnet-add/dotnet-add-reference/AddProjectToProjectReferenceParser.cs create mode 100644 src/dotnet/commands/dotnet-remove/dotnet-remove-package/RemovePackageParser.cs create mode 100644 src/dotnet/commands/dotnet-remove/dotnet-remove-reference/RemoveProjectToProjectReferenceParser.cs create mode 100644 src/dotnet/commands/dotnet-sln/add/SlnAddParser.cs create mode 100644 src/dotnet/commands/dotnet-sln/list/SlnListParser.cs create mode 100644 src/dotnet/commands/dotnet-sln/remove/SlnRemoveParser.cs diff --git a/src/dotnet/CommonLocalizableStrings.cs b/src/dotnet/CommonLocalizableStrings.cs index 191509ab4..d19b462d5 100644 --- a/src/dotnet/CommonLocalizableStrings.cs +++ b/src/dotnet/CommonLocalizableStrings.cs @@ -158,8 +158,8 @@ namespace Microsoft.DotNet.Tools /// sln public const string ArgumentsProjectDescription = "The project file to operate on. If a file is not specified, the command will search the current directory for one."; public const string ArgumentsSolutionDescription = "Solution file to operate on. If not specified, the command will search the current directory for one."; - public const string CmdSlnFile = ""; - public const string CmdProjectFile = ""; + public const string CmdSlnFile = "SLN_FILE"; + public const string CmdProjectFile = "PROJECT"; /// commands public const string CmdFramework = "FRAMEWORK"; diff --git a/src/dotnet/commands/dotnet-add/AddCommandParser.cs b/src/dotnet/commands/dotnet-add/AddCommandParser.cs index ed816ace3..39093759a 100644 --- a/src/dotnet/commands/dotnet-add/AddCommandParser.cs +++ b/src/dotnet/commands/dotnet-add/AddCommandParser.cs @@ -2,13 +2,10 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; using System.Linq; -using System.Net.Http; -using System.Threading; using Microsoft.DotNet.Cli.CommandLine; -using Newtonsoft.Json.Linq; -using LocalizableStrings = Microsoft.DotNet.Tools.Add.PackageReference.LocalizableStrings; +using Microsoft.DotNet.Tools; +using LocalizableStrings = Microsoft.DotNet.Tools.Add.LocalizableStrings; namespace Microsoft.DotNet.Cli { @@ -17,81 +14,12 @@ namespace Microsoft.DotNet.Cli public static Command Add() => Create.Command( "add", - ".NET Add Command", + LocalizableStrings.NetAddCommand, Accept.ExactlyOneArgument() .DefaultToCurrentDirectory() - .With(name: "PROJECT", - description: "The project file to operate on. If a file is not specified, the command will search the current directory for one."), - Create.Command( - "package", - ".NET Add Package reference Command", - Accept.ExactlyOneArgument(errorMessage: o => LocalizableStrings.SpecifyExactlyOnePackageReference) - .WithSuggestionsFrom(QueryNuGet) - .With(name: "PACKAGE_NAME", - description: "Package references to add"), - CommonOptions.HelpOption(), - Create.Option("-v|--version", - "Version for the package to be added.", - Accept.ExactlyOneArgument() - .With(name: "VERSION") - .ForwardAsSingle(o => $"--version {o.Arguments.Single()}")), - Create.Option("-f|--framework", - LocalizableStrings.CmdFrameworkDescription, - Accept.ExactlyOneArgument() - .With(name: "FRAMEWORK") - .ForwardAsSingle(o => $"--framework {o.Arguments.Single()}")), - Create.Option("-n|--no-restore ", - "Add reference without performing restore preview and compatibility check."), - Create.Option("-s|--source", - "Use specific NuGet package sources to use during the restore.", - Accept.ExactlyOneArgument() - .With(name: "SOURCE") - .ForwardAsSingle(o => $"--source {o.Arguments.Single()}")), - Create.Option("--package-directory", - "Restore the packages to this Directory .", - Accept.ExactlyOneArgument() - .With(name: "PACKAGE_DIRECTORY") - .ForwardAsSingle(o => $"--package-directory {o.Arguments.Single()}"))), - Create.Command( - "reference", - Tools.Add.ProjectToProjectReference.LocalizableStrings.AppFullName, - Accept.OneOrMoreArguments() - .With(name: "args", - description: Tools.Add.ProjectToProjectReference.LocalizableStrings.AppHelpText), - CommonOptions.HelpOption(), - Create.Option("-f|--framework", - LocalizableStrings.CmdFrameworkDescription, - Accept - .ExactlyOneArgument() - .WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile()) - .With(name: "FRAMEWORK"))), + .With(name: CommonLocalizableStrings.CmdProjectFile, + description: CommonLocalizableStrings.ArgumentsProjectDescription), AddPackageParser.AddPackage(), + AddProjectToProjectReferenceParser.AddProjectReference(), CommonOptions.HelpOption()); - - public static IEnumerable QueryNuGet(string match) - { - var httpClient = new HttpClient(); - - string result; - - try - { - var cancellation = new CancellationTokenSource(TimeSpan.FromSeconds(10)); - var response = httpClient.GetAsync($"https://api-v2v3search-0.nuget.org/query?q={match}&skip=0&take=100&prerelease=true", cancellation.Token) - .Result; - - result = response.Content.ReadAsStringAsync().Result; - } - catch (Exception) - { - yield break; - } - - var json = JObject.Parse(result); - - foreach (var id in json["data"]) - { - yield return id["id"].Value(); - } - } } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs b/src/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs new file mode 100644 index 000000000..70687e8d2 --- /dev/null +++ b/src/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs @@ -0,0 +1,78 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Threading; +using Microsoft.DotNet.Cli.CommandLine; +using Newtonsoft.Json.Linq; +using LocalizableStrings = Microsoft.DotNet.Tools.Add.PackageReference.LocalizableStrings; + +namespace Microsoft.DotNet.Cli +{ + internal static class AddPackageParser + { + public static Command AddPackage() + { + return Create.Command( + "package", + LocalizableStrings.AppFullName, + Accept.ExactlyOneArgument(errorMessage: o => LocalizableStrings.SpecifyExactlyOnePackageReference) + .WithSuggestionsFrom(QueryNuGet) + .With(name: LocalizableStrings.CmdPackage, + description: LocalizableStrings.CmdPackageDescription), + CommonOptions.HelpOption(), + Create.Option("-v|--version", + LocalizableStrings.CmdVersionDescription, + Accept.ExactlyOneArgument() + .With(name: LocalizableStrings.CmdVersion) + .ForwardAsSingle(o => $"--version {o.Arguments.Single()}")), + Create.Option("-f|--framework", + LocalizableStrings.CmdFrameworkDescription, + Accept.ExactlyOneArgument() + .With(name: LocalizableStrings.CmdFramework) + .ForwardAsSingle(o => $"--framework {o.Arguments.Single()}")), + Create.Option("-n|--no-restore ", + LocalizableStrings.CmdNoRestoreDescription), + Create.Option("-s|--source", + LocalizableStrings.CmdSourceDescription, + Accept.ExactlyOneArgument() + .With(name: LocalizableStrings.CmdSource) + .ForwardAsSingle(o => $"--source {o.Arguments.Single()}")), + Create.Option("--package-directory", + LocalizableStrings.CmdPackageDirectoryDescription, + Accept.ExactlyOneArgument() + .With(name: LocalizableStrings.CmdPackageDirectory) + .ForwardAsSingle(o => $"--package-directory {o.Arguments.Single()}"))); + } + + public static IEnumerable QueryNuGet(string match) + { + var httpClient = new HttpClient(); + + string result; + + try + { + var cancellation = new CancellationTokenSource(TimeSpan.FromSeconds(10)); + var response = httpClient.GetAsync($"https://api-v2v3search-0.nuget.org/query?q={match}&skip=0&take=100&prerelease=true", cancellation.Token) + .Result; + + result = response.Content.ReadAsStringAsync().Result; + } + catch (Exception) + { + yield break; + } + + var json = JObject.Parse(result); + + foreach (var id in json["data"]) + { + yield return id["id"].Value(); + } + } + } +} diff --git a/src/dotnet/commands/dotnet-add/dotnet-add-reference/AddProjectToProjectReferenceParser.cs b/src/dotnet/commands/dotnet-add/dotnet-add-reference/AddProjectToProjectReferenceParser.cs new file mode 100644 index 000000000..417e2f97c --- /dev/null +++ b/src/dotnet/commands/dotnet-add/dotnet-add-reference/AddProjectToProjectReferenceParser.cs @@ -0,0 +1,26 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Cli.CommandLine; +using LocalizableStrings = Microsoft.DotNet.Tools.Add.ProjectToProjectReference.LocalizableStrings; + +namespace Microsoft.DotNet.Cli +{ + internal static class AddProjectToProjectReferenceParser + { + public static Command AddProjectReference() + { + return Create.Command( + "reference", + LocalizableStrings.AppFullName, + Accept.OneOrMoreArguments() + .With(name: "args", + description: LocalizableStrings.AppHelpText), + CommonOptions.HelpOption(), + Create.Option("-f|--framework", LocalizableStrings.CmdFrameworkDescription, + Accept.ExactlyOneArgument() + .WithSuggestionsFrom(_ => Suggest.TargetFrameworksFromProjectFile()) + .With(name: Tools.Add.PackageReference.LocalizableStrings.CmdFramework))); + } + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs index e75d179e6..eaa00740f 100644 --- a/src/dotnet/commands/dotnet-build/BuildCommandParser.cs +++ b/src/dotnet/commands/dotnet-build/BuildCommandParser.cs @@ -3,6 +3,7 @@ using System.Linq; using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Tools; using LocalizableStrings = Microsoft.DotNet.Tools.Build.LocalizableStrings; namespace Microsoft.DotNet.Cli @@ -14,7 +15,7 @@ namespace Microsoft.DotNet.Cli "build", LocalizableStrings.AppFullName, Accept.ZeroOrMoreArguments() - .With(name: "PROJECT", + .With(name: CommonLocalizableStrings.CmdProjectFile, description: "The MSBuild project file to build. If a project file is not specified, MSBuild searches the current working directory for a file that has a file extension that ends in `proj` and uses that file."), CommonOptions.HelpOption(), diff --git a/src/dotnet/commands/dotnet-list/ListCommandParser.cs b/src/dotnet/commands/dotnet-list/ListCommandParser.cs index 867c5c3e0..1fee43e0f 100644 --- a/src/dotnet/commands/dotnet-list/ListCommandParser.cs +++ b/src/dotnet/commands/dotnet-list/ListCommandParser.cs @@ -2,7 +2,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using Microsoft.DotNet.Cli.CommandLine; -using LocalizableStrings = Microsoft.DotNet.Tools.List.ProjectToProjectReferences.LocalizableStrings; +using Microsoft.DotNet.Tools; +using LocalizableStrings = Microsoft.DotNet.Tools.List.LocalizableStrings; namespace Microsoft.DotNet.Cli { @@ -10,15 +11,15 @@ namespace Microsoft.DotNet.Cli { public static Command List() => Create.Command("list", - ".NET List Command", + LocalizableStrings.NetListCommand, Accept.ZeroOrOneArgument() - .With(name: "PROJECT", + .With(name: CommonLocalizableStrings.CmdProjectFile, description: - "The project file to operate on. If a file is not specified, the command will search the current directory for one.") + CommonLocalizableStrings.ArgumentsProjectDescription) .DefaultToCurrentDirectory(), CommonOptions.HelpOption(), Create.Command("reference", - LocalizableStrings.AppFullName, + Tools.List.ProjectToProjectReferences.LocalizableStrings.AppFullName, Accept.ZeroOrOneArgument(), CommonOptions.HelpOption())); } diff --git a/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs b/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs index fc64a0c74..f5f5c771f 100644 --- a/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs +++ b/src/dotnet/commands/dotnet-migrate/MigrateCommandParser.cs @@ -15,34 +15,32 @@ namespace Microsoft.DotNet.Cli "migrate", ".NET Migrate Command", Accept.ZeroOrOneArgument() - .MaterializeAs(o => - { - return new MigrateCommand( - o.ValueOrDefault("--template-file"), - o.Arguments.FirstOrDefault(), - o.ValueOrDefault("--sdk-package-version"), - o.ValueOrDefault("--xproj-file"), - o.ValueOrDefault("--report-file"), - o.ValueOrDefault("--skip-project-references"), - o.ValueOrDefault("--format-report-file-json"), - o.ValueOrDefault("--skip-backup")); - }) - .With(name: LocalizableStrings.CmdProjectArgument, - description: LocalizableStrings.CmdProjectArgumentDescription), + .MaterializeAs(o => + new MigrateCommand( + o.ValueOrDefault("--template-file"), + o.Arguments.FirstOrDefault(), + o.ValueOrDefault("--sdk-package-version"), + o.ValueOrDefault("--xproj-file"), + o.ValueOrDefault("--report-file"), + o.ValueOrDefault("--skip-project-references"), + o.ValueOrDefault("--format-report-file-json"), + o.ValueOrDefault("--skip-backup"))) + .With(name: LocalizableStrings.CmdProjectArgument, + description: LocalizableStrings.CmdProjectArgumentDescription), CommonOptions.HelpOption(), Create.Option("-t|--template-file", - LocalizableStrings.CmdTemplateDescription), + LocalizableStrings.CmdTemplateDescription), Create.Option("-v|--sdk-package-version", - LocalizableStrings.CmdVersionDescription), + LocalizableStrings.CmdVersionDescription), Create.Option("-x|--xproj-file", - LocalizableStrings.CmdXprojFileDescription), + LocalizableStrings.CmdXprojFileDescription), Create.Option("-s|--skip-project-references", - LocalizableStrings.CmdSkipProjectReferencesDescription), + LocalizableStrings.CmdSkipProjectReferencesDescription), Create.Option("-r|--report-file", - LocalizableStrings.CmdReportFileDescription), + LocalizableStrings.CmdReportFileDescription), Create.Option("--format-report-file-json", - LocalizableStrings.CmdReportOutputDescription), + LocalizableStrings.CmdReportOutputDescription), Create.Option("--skip-backup", - LocalizableStrings.CmdSkipBackupDescription)); + LocalizableStrings.CmdSkipBackupDescription)); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs b/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs index 7a7dcfa01..c45c14599 100644 --- a/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs +++ b/src/dotnet/commands/dotnet-remove/RemoveCommandParser.cs @@ -3,7 +3,7 @@ using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Tools; -using LocalizableStrings = Microsoft.DotNet.Tools.Remove.ProjectToProjectReference.LocalizableStrings; +using LocalizableStrings = Microsoft.DotNet.Tools.Remove.LocalizableStrings; namespace Microsoft.DotNet.Cli { @@ -11,30 +11,14 @@ namespace Microsoft.DotNet.Cli { public static Command Remove() => Create.Command("remove", - ".NET Remove Command", + LocalizableStrings.NetRemoveCommand, Accept.ExactlyOneArgument() .DefaultToCurrentDirectory() - .With(name: "PROJECT", + .With(name: CommonLocalizableStrings.CmdProjectFile, description: CommonLocalizableStrings.ArgumentsProjectDescription) .DefaultToCurrentDirectory(), CommonOptions.HelpOption(), - Create.Command( - "package", - LocalizableStrings.AppFullName, - CommonOptions.HelpOption()), - Create.Command( - "reference", - LocalizableStrings.AppFullName, - Accept - .OneOrMoreArguments() - .WithSuggestionsFrom(_ => Suggest.ProjectReferencesFromProjectFile()) - .With(name: "args", - description: LocalizableStrings.AppHelpText), - CommonOptions.HelpOption(), - Create.Option( - "-f|--framework", - "Remove reference only when targeting a specific framework", - Accept.ExactlyOneArgument() - .With(name: "FRAMEWORK")))); + RemovePackageParser.RemovePackage(), + RemoveProjectToProjectReferenceParser.RemoveReference()); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-remove/dotnet-remove-package/RemovePackageParser.cs b/src/dotnet/commands/dotnet-remove/dotnet-remove-package/RemovePackageParser.cs new file mode 100644 index 000000000..acfe8fa1c --- /dev/null +++ b/src/dotnet/commands/dotnet-remove/dotnet-remove-package/RemovePackageParser.cs @@ -0,0 +1,14 @@ +using Microsoft.DotNet.Cli.CommandLine; +using LocalizableStrings = Microsoft.DotNet.Tools.Remove.ProjectToProjectReference.LocalizableStrings; + +namespace Microsoft.DotNet.Cli +{ + internal static class RemovePackageParser + { + public static Command RemovePackage() => + Create.Command( + "package", + LocalizableStrings.AppFullName, + CommonOptions.HelpOption()); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/RemoveProjectToProjectReferenceParser.cs b/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/RemoveProjectToProjectReferenceParser.cs new file mode 100644 index 000000000..9489c9643 --- /dev/null +++ b/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/RemoveProjectToProjectReferenceParser.cs @@ -0,0 +1,25 @@ +using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Tools; +using LocalizableStrings = Microsoft.DotNet.Tools.Remove.ProjectToProjectReference.LocalizableStrings; + +namespace Microsoft.DotNet.Cli +{ + internal static class RemoveProjectToProjectReferenceParser + { + public static Command RemoveReference() => + Create.Command( + "reference", + LocalizableStrings.AppFullName, + Accept + .OneOrMoreArguments() + .WithSuggestionsFrom(_ => Suggest.ProjectReferencesFromProjectFile()) + .With(name: "args", + description: LocalizableStrings.AppHelpText), + CommonOptions.HelpOption(), + Create.Option( + "-f|--framework", + LocalizableStrings.CmdFrameworkDescription, + Accept.ExactlyOneArgument() + .With(name: CommonLocalizableStrings.CmdFramework))); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-run/RunCommand.cs b/src/dotnet/commands/dotnet-run/RunCommand.cs index e9f0c8bdd..225757c50 100644 --- a/src/dotnet/commands/dotnet-run/RunCommand.cs +++ b/src/dotnet/commands/dotnet-run/RunCommand.cs @@ -16,14 +16,10 @@ namespace Microsoft.DotNet.Tools.Run public string Configuration { get; set; } public string Framework { get; set; } public string Project { get; set; } - public IReadOnlyList Args { get; set; } + public IReadOnlyCollection Args { get; set; } private List _args; - public RunCommand() - { - } - public int Start() { Initialize(); diff --git a/src/dotnet/commands/dotnet-run/RunCommandParser.cs b/src/dotnet/commands/dotnet-run/RunCommandParser.cs index 737e43b23..1dc22c122 100644 --- a/src/dotnet/commands/dotnet-run/RunCommandParser.cs +++ b/src/dotnet/commands/dotnet-run/RunCommandParser.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System.Collections.Generic; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Tools.Run; using LocalizableStrings = Microsoft.DotNet.Tools.Run.LocalizableStrings; @@ -14,27 +13,28 @@ namespace Microsoft.DotNet.Cli Create.Command( "run", LocalizableStrings.AppFullName, - Accept.ZeroOrMoreArguments() - .MaterializeAs(o => - { - return new RunCommand() - { - Configuration = o.SingleArgumentOrDefault("--configuration"), - Framework = o.SingleArgumentOrDefault("--framework"), - Project = o.SingleArgumentOrDefault("--project"), - Args = (IReadOnlyList)o.Arguments - }; - }), - CommonOptions.HelpOption(), - CommonOptions.ConfigurationOption(), - CommonOptions.FrameworkOption(), - Create.Option( - "-p|--project", - LocalizableStrings.CommandOptionProjectDescription, - Accept.ExactlyOneArgument()), - Create.Option( - "--no-build", - LocalizableStrings.CommandOptionNoBuildDescription, - Accept.NoArguments().ForwardAs("/p:NoBuild=true"))); + treatUnmatchedTokensAsErrors: false, + arguments: Accept.ZeroOrMoreArguments() + .MaterializeAs(o => new RunCommand + { + Configuration = o.SingleArgumentOrDefault("--configuration"), + Framework = o.SingleArgumentOrDefault("--framework"), + Project = o.SingleArgumentOrDefault("--project"), + Args = o.Arguments + }), + options: new[] + { + CommonOptions.HelpOption(), + CommonOptions.ConfigurationOption(), + CommonOptions.FrameworkOption(), + Create.Option( + "-p|--project", + LocalizableStrings.CommandOptionProjectDescription, + Accept.ExactlyOneArgument()), + Create.Option( + "--no-build", + LocalizableStrings.CommandOptionNoBuildDescription, + Accept.NoArguments().ForwardAs("/p:NoBuild=true")) + }); } -} +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs index ce4865921..4be1ab9d6 100644 --- a/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs +++ b/src/dotnet/commands/dotnet-sln/SlnCommandParser.cs @@ -12,27 +12,14 @@ namespace Microsoft.DotNet.Cli public static Command Sln() => Create.Command( "sln", - ".NET modify solution file command", + LocalizableStrings.AppFullName, Accept.ExactlyOneArgument() .DefaultToCurrentDirectory() - .With(name: "SLN_FILE", + .With(name: CommonLocalizableStrings.CmdSlnFile, description: CommonLocalizableStrings.ArgumentsSolutionDescription), CommonOptions.HelpOption(), - Create.Command("add", - ".NET Add project(s) to a solution file Command", - Accept.OneOrMoreArguments(o => CommonLocalizableStrings.SpecifyAtLeastOneProjectToAdd) - .With(name: "args", - description: LocalizableStrings.AddSubcommandHelpText), - CommonOptions.HelpOption()), - Create.Command("list", - ".NET List project(s) in a solution file Command", - CommonOptions.HelpOption()), - Create.Command("remove", - ".NET Remove project(s) from a solution file Command", - Accept.OneOrMoreArguments(o => CommonLocalizableStrings.SpecifyAtLeastOneProjectToRemove) - .With(name: "args", - description: LocalizableStrings.RemoveSubcommandHelpText), - CommonOptions.HelpOption())); - + SlnAddParser.SlnAdd(), + SlnListParser.SlnList(), + SlnRemoveParser.SlnRemove()); } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-sln/add/SlnAddParser.cs b/src/dotnet/commands/dotnet-sln/add/SlnAddParser.cs new file mode 100644 index 000000000..63685fb93 --- /dev/null +++ b/src/dotnet/commands/dotnet-sln/add/SlnAddParser.cs @@ -0,0 +1,20 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Tools; +using LocalizableStrings = Microsoft.DotNet.Tools.Sln.LocalizableStrings; + +namespace Microsoft.DotNet.Cli +{ + public static class SlnAddParser + { + public static Command SlnAdd() => + Create.Command("add", + LocalizableStrings.AddAppFullName, + Accept.OneOrMoreArguments(o => CommonLocalizableStrings.SpecifyAtLeastOneProjectToAdd) + .With(name: "args", + description: LocalizableStrings.AddSubcommandHelpText), + CommonOptions.HelpOption()); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-sln/list/SlnListParser.cs b/src/dotnet/commands/dotnet-sln/list/SlnListParser.cs new file mode 100644 index 000000000..ea16b2efe --- /dev/null +++ b/src/dotnet/commands/dotnet-sln/list/SlnListParser.cs @@ -0,0 +1,16 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Cli.CommandLine; +using LocalizableStrings = Microsoft.DotNet.Tools.Sln.LocalizableStrings; + +namespace Microsoft.DotNet.Cli +{ + public static class SlnListParser + { + public static Command SlnList() => + Create.Command("list", + LocalizableStrings.ListAppFullName, + CommonOptions.HelpOption()); + } +} \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-sln/remove/SlnRemoveParser.cs b/src/dotnet/commands/dotnet-sln/remove/SlnRemoveParser.cs new file mode 100644 index 000000000..b650ba84c --- /dev/null +++ b/src/dotnet/commands/dotnet-sln/remove/SlnRemoveParser.cs @@ -0,0 +1,20 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Tools; +using LocalizableStrings = Microsoft.DotNet.Tools.Sln.LocalizableStrings; + +namespace Microsoft.DotNet.Cli +{ + public static class SlnRemoveParser + { + public static Command SlnRemove() => + Create.Command("remove", + LocalizableStrings.RemoveAppFullName, + Accept.OneOrMoreArguments(o => CommonLocalizableStrings.SpecifyAtLeastOneProjectToRemove) + .With(name: "args", + description: LocalizableStrings.RemoveSubcommandHelpText), + CommonOptions.HelpOption()); + } +} \ No newline at end of file From c85492bd48b0583fb66f03676e12a52c00c1bde3 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Sun, 19 Mar 2017 17:09:05 -0700 Subject: [PATCH 108/149] merge master --- CONTRIBUTING.md | 2 +- Documentation/README.md | 6 +- NuGet.Config | 1 + build.cmd | 2 +- build/DependencyVersions.props | 4 +- run-build.ps1 | 8 +- run-build.sh | 5 +- scripts/obtain/dotnet-install.sh | 125 +++++++++------- src/dotnet/BuiltInCommandMetadata.cs | 10 ++ src/dotnet/BuiltInCommandsCatalog.cs | 140 ++++++++++++++++++ src/dotnet/DotNetCommandFactory.cs | 4 +- src/dotnet/Program.cs | 12 +- src/dotnet/README.md | 2 +- .../dotnet-add-package/LocalizableStrings.cs | 12 +- .../xlf/LocalizableStrings.ko.xlf | 2 +- .../commands/dotnet-help/HelpCommand.cs | 67 ++++++++- .../dotnet-help/LocalizableStrings.cs | 13 ++ src/redist/redist.csproj | 16 -- .../LinuxOnlyFactAttribute.cs | 19 +++ .../MacOsOnlyFactAttribute.cs | 19 +++ ...ivenThatIWantToShowHelpForDotnetCommand.cs | 36 +++++ 21 files changed, 412 insertions(+), 93 deletions(-) create mode 100644 src/dotnet/BuiltInCommandMetadata.cs create mode 100644 src/dotnet/BuiltInCommandsCatalog.cs create mode 100644 test/Microsoft.DotNet.Tools.Tests.Utilities/LinuxOnlyFactAttribute.cs create mode 100644 test/Microsoft.DotNet.Tools.Tests.Utilities/MacOsOnlyFactAttribute.cs diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 47cd25353..9271b689e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,4 +6,4 @@ See [Contributing](https://github.com/dotnet/corefx/blob/master/Documentation/pr Developers ========== -See the [Developer Guide](Documentation/developer-guide.md) for details about developing in this repo. \ No newline at end of file +See the [Developer Guide](Documentation/project-docs/developer-guide.md) for details about developing in this repo. \ No newline at end of file diff --git a/Documentation/README.md b/Documentation/README.md index 3a88a00f6..94edbb417 100644 --- a/Documentation/README.md +++ b/Documentation/README.md @@ -3,8 +3,8 @@ Documents Index ## Overview and general information -- [Intro to .NET Core CLI](intro-to-cli.md) -- [CLI UX Guidelines](cli-ux-guidelines.md) +- [Intro to .NET Core CLI](general/intro-to-cli.md) +- [CLI UX Guidelines](general/cli-ux-guidelines.md) - [.NET Core native pre-requisities document](https://github.com/dotnet/core/blob/master/Documentation/prereqs.md) - [Roadmap and OS support](https://github.com/dotnet/core/blob/master/roadmap.md) - [Comprehensive CLI documentation](https://docs.microsoft.com/en-us/dotnet/articles/core/preview3/tools/) @@ -12,7 +12,7 @@ Documents Index ## Working with the CLI repo - [Developer Guide](project-docs/developer-guide.md) -- [How to file issues](project-docs/issue-filing.guide.md) +- [How to file issues](project-docs/issue-filing-guide.md) ## Troubleshooting and issues reporting diff --git a/NuGet.Config b/NuGet.Config index 556ee5919..f14a56c99 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -10,5 +10,6 @@ + diff --git a/build.cmd b/build.cmd index 013687943..ce681438b 100644 --- a/build.cmd +++ b/build.cmd @@ -3,5 +3,5 @@ REM Copyright (c) .NET Foundation and contributors. All rights reserved. REM Licensed under the MIT license. See LICENSE file in the project root for full license information. -powershell -NoProfile -NoLogo -Command "& \"%~dp0run-build.ps1\" %*; exit $LastExitCode;" +powershell -ExecutionPolicy Bypass -NoProfile -NoLogo -Command "& \"%~dp0run-build.ps1\" %*; exit $LastExitCode;" if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/build/DependencyVersions.props b/build/DependencyVersions.props index 72999d9c2..f75d0d022 100644 --- a/build/DependencyVersions.props +++ b/build/DependencyVersions.props @@ -1,13 +1,13 @@ - 2.0.0-beta-001728-00 + 2.0.0-beta-001791-00 15.2.0-preview-000047-02 2.0.0-rc4-61325-08 1.1.0-alpha-20170306-2 4.3.0-beta1-2342 1.0.0-alpha-20170130-3-281 - 15.0.0 + 15.1.0-preview-20170316-05 $(CLI_SharedFrameworkVersion) $(CLI_SharedFrameworkVersion) $(CLI_SharedFrameworkVersion) diff --git a/run-build.ps1 b/run-build.ps1 index 67ab3cd06..ea77e8983 100644 --- a/run-build.ps1 +++ b/run-build.ps1 @@ -29,7 +29,9 @@ if($Help) $env:CONFIGURATION = $Configuration; $RepoRoot = "$PSScriptRoot" -$env:NUGET_PACKAGES = "$RepoRoot\.nuget\packages" +if(!$env:NUGET_PACKAGES){ + $env:NUGET_PACKAGES = "$RepoRoot\.nuget\packages" +} if($NoPackage) { @@ -71,6 +73,10 @@ $env:VSTEST_TRACE_BUILD=1 # set the base tools directory $toolsLocalPath = Join-Path $PSScriptRoot "build_tools" +if($env:BOOTSTRAP_INSTALL_DIR) +{ + $toolsLocalPath = $env:BOOTSTRAP_INSTALL_DIR +} $bootStrapperPath = Join-Path $toolsLocalPath "bootstrap.ps1" # if the boot-strapper script doesn't exist then download it if ((Test-Path $bootStrapperPath) -eq 0) diff --git a/run-build.sh b/run-build.sh index f96f9d0c0..9c5c2beb4 100755 --- a/run-build.sh +++ b/run-build.sh @@ -59,7 +59,7 @@ LINUX_PORTABLE_INSTALL_ARGS= CUSTOM_BUILD_ARGS= # Set nuget package cache under the repo -export NUGET_PACKAGES="$REPOROOT/.nuget/packages" +[ -z $NUGET_PACKAGES ] && export NUGET_PACKAGES="$REPOROOT/.nuget/packages" args=( "$@" ) @@ -147,6 +147,9 @@ export VSTEST_TRACE_BUILD=1 DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 toolsLocalPath="$REPOROOT/build_tools" +if [ ! -z $BOOTSTRAP_INSTALL_DIR]; then + toolsLocalPath = $BOOTSTRAP_INSTALL_DIR +fi bootStrapperPath="$toolsLocalPath/bootstrap.sh" dotnetInstallPath="$toolsLocalPath/dotnet-install.sh" if [ ! -f $bootStrapperPath ]; then diff --git a/scripts/obtain/dotnet-install.sh b/scripts/obtain/dotnet-install.sh index af2b369a6..739b9d147 100755 --- a/scripts/obtain/dotnet-install.sh +++ b/scripts/obtain/dotnet-install.sh @@ -56,6 +56,59 @@ say_verbose() { fi } +get_os_download_name_from_platform() { + eval $invocation + + platform="$1" + case "$platform" in + "centos.7") + echo "centos" + return 0 + ;; + "debian.8") + echo "debian" + return 0 + ;; + "fedora.23") + echo "fedora.23" + return 0 + ;; + "fedora.24") + echo "fedora.24" + return 0 + ;; + "opensuse.13.2") + echo "opensuse.13.2" + return 0 + ;; + "opensuse.42.1") + echo "opensuse.42.1" + return 0 + ;; + "rhel.7"*) + echo "rhel" + return 0 + ;; + "ubuntu.14.04") + echo "ubuntu" + return 0 + ;; + "ubuntu.16.04") + echo "ubuntu.16.04" + return 0 + ;; + "ubuntu.16.10") + echo "ubuntu.16.10" + return 0 + ;; + "alpine.3.4.3") + echo "alpine" + return 0 + ;; + esac + return 1 +} + get_current_os_name() { eval $invocation @@ -66,56 +119,17 @@ get_current_os_name() { elif [ "$uname" = "Darwin" ]; then echo "osx" return 0 + elif [ -n "$runtime_id" ]; then + echo $(get_os_download_name_from_platform "${runtime_id%-*}" || echo "${runtime_id%-*}") + return 0 else if [ -e /etc/os-release ]; then . /etc/os-release - - case "$ID.$VERSION_ID" in - "centos.7") - echo "centos" - return 0 - ;; - "debian.8") - echo "debian" - return 0 - ;; - "fedora.23") - echo "fedora.23" - return 0 - ;; - "fedora.24") - echo "fedora.24" - return 0 - ;; - "opensuse.13.2") - echo "opensuse.13.2" - return 0 - ;; - "opensuse.42.1") - echo "opensuse.42.1" - return 0 - ;; - "rhel.7"*) - echo "rhel" - return 0 - ;; - "ubuntu.14.04") - echo "ubuntu" - return 0 - ;; - "ubuntu.16.04") - echo "ubuntu.16.04" - return 0 - ;; - "ubuntu.16.10") - echo "ubuntu.16.10" - return 0 - ;; - "alpine.3.4.3") - echo "alpine" - return 0 - ;; - esac + os=$(get_os_download_name_from_platform "$ID.$VERSION_ID" || echo "") + if [ -n "$os" ]; then + echo "$os" + return 0 + fi fi fi @@ -400,7 +414,7 @@ construct_download_link() { return 0 } -get_user_share_path() { +get_user_install_path() { eval $invocation if [ ! -z "${DOTNET_INSTALL_DIR:-}" ]; then @@ -418,9 +432,9 @@ resolve_installation_path() { local install_dir=$1 if [ "$install_dir" = "" ]; then - local user_share_path=$(get_user_share_path) - say_verbose "resolve_installation_path: share_path=$user_share_path" - echo "$user_share_path" + local user_install_path=$(get_user_install_path) + say_verbose "resolve_installation_path: user_install_path=$user_install_path" + echo "$user_install_path" return 0 fi @@ -588,6 +602,7 @@ uncached_feed="https://dotnetcli.blob.core.windows.net/dotnet" verbose=false shared_runtime=false linux_portable=false +runtime_id="" while [ $# -ne 0 ] do @@ -631,6 +646,10 @@ do --linux-portable|-[Ll]inux[Pp]ortable) linux_portable=true ;; + --runtime-id|-[Rr]untime[Ii]d) + shift + runtime_id="$1" + ;; -?|--?|-h|--help|-[Hh]elp) script_name="$(basename $0)" echo ".NET Tools Installer" @@ -657,13 +676,15 @@ do echo " --azure-feed,-AzureFeed Azure feed location. Defaults to $azure_feed" echo " --linux-portable Installs the Linux portable .NET Tools instead of a distro-specific version." echo " -LinuxPortable" + echo " --runtime-id Installs the .NET Tools for the given platform (such as linux-x64)." + echo " -RuntimeId" echo " -?,--?,-h,--help,-Help Shows this help message" echo "" echo "Install Location:" echo " Location is chosen in following order:" echo " - --install-dir option" echo " - Environmental variable DOTNET_INSTALL_DIR" - echo " - /usr/local/share/dotnet" + echo " - $HOME/.dotnet" exit 0 ;; *) diff --git a/src/dotnet/BuiltInCommandMetadata.cs b/src/dotnet/BuiltInCommandMetadata.cs new file mode 100644 index 000000000..bb2d48181 --- /dev/null +++ b/src/dotnet/BuiltInCommandMetadata.cs @@ -0,0 +1,10 @@ +using System; + +namespace Microsoft.DotNet.Cli +{ + public class BuiltInCommandMetadata + { + public Func Command { get; set; } + public string DocLink { get; set; } + } +} \ No newline at end of file diff --git a/src/dotnet/BuiltInCommandsCatalog.cs b/src/dotnet/BuiltInCommandsCatalog.cs new file mode 100644 index 000000000..16b0b5331 --- /dev/null +++ b/src/dotnet/BuiltInCommandsCatalog.cs @@ -0,0 +1,140 @@ +using System; +using System.Collections.Generic; +using Microsoft.DotNet.Tools.Add; +using Microsoft.DotNet.Tools.Build; +using Microsoft.DotNet.Tools.Clean; +using Microsoft.DotNet.Tools.Help; +using Microsoft.DotNet.Tools.List; +using Microsoft.DotNet.Tools.Migrate; +using Microsoft.DotNet.Tools.MSBuild; +using Microsoft.DotNet.Tools.New; +using Microsoft.DotNet.Tools.NuGet; +using Microsoft.DotNet.Tools.Pack; +using Microsoft.DotNet.Tools.Publish; +using Microsoft.DotNet.Tools.Remove; +using Microsoft.DotNet.Tools.Restore; +using Microsoft.DotNet.Tools.Run; +using Microsoft.DotNet.Tools.Sln; +using Microsoft.DotNet.Tools.Test; +using Microsoft.DotNet.Tools.VSTest; +using Microsoft.DotNet.Tools.Cache; + +namespace Microsoft.DotNet.Cli +{ + public static class BuiltInCommandsCatalog + { + public static Dictionary Commands = new Dictionary + { + ["add"] = new BuiltInCommandMetadata + { + Command = AddCommand.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-add-reference + DocLink = "https://aka.ms/dotnet-add" + }, + ["build"] = new BuiltInCommandMetadata + { + Command = BuildCommand.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-build + DocLink = "https://aka.ms/dotnet-build" + }, + ["cache"] = new BuiltInCommandMetadata + { + Command = CacheCommand.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-cache + DocLink = "https://aka.ms/dotnet-cache" + }, + ["clean"] = new BuiltInCommandMetadata + { + Command = CleanCommand.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-clean + DocLink = "https://aka.ms/dotnet-clean" + }, + ["help"] = new BuiltInCommandMetadata + { + Command = HelpCommand.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-help + DocLink = "https://aka.ms/dotnet-help" + }, + ["list"] = new BuiltInCommandMetadata + { + Command = ListCommand.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-list-reference + DocLink = "https://aka.ms/dotnet-list" + }, + ["migrate"] = new BuiltInCommandMetadata + { + Command = MigrateCommand.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-migrate + DocLink = "http://aka.ms/dotnet-migrate" + + }, + ["msbuild"] = new BuiltInCommandMetadata + { + Command = MSBuildCommand.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-msbuild + DocLink = "https://aka.ms/dotnet-msbuild" + }, + ["new"] = new BuiltInCommandMetadata + { + Command = NewCommandShim.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-new + DocLink = "https://aka.ms/dotnet-new" + }, + ["nuget"] = new BuiltInCommandMetadata + { + Command = NuGetCommand.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-nuget-locals + DocLink = "https://aka.ms/dotnet-nuget" + }, + ["pack"] = new BuiltInCommandMetadata + { + Command = PackCommand.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-pack + DocLink = "https://aka.ms/dotnet-pack" + }, + ["publish"] = new BuiltInCommandMetadata + { + Command = PublishCommand.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-publish + DocLink = "https://aka.ms/dotnet-publish" + }, + ["remove"] = new BuiltInCommandMetadata + { + Command = RemoveCommand.Run, + // aka.ms link: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-remove-reference + DocLink = "https://aka.ms/dotnet-remove" + }, + ["restore"] = new BuiltInCommandMetadata + { + Command = RestoreCommand.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-restore + DocLink = "https://aka.ms/dotnet-restore" + }, + ["run"] = new BuiltInCommandMetadata + { + Command = RunCommand.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-run + DocLink = "https://aka.ms/dotnet-run" + }, + ["sln"] = new BuiltInCommandMetadata + { + Command = SlnCommand.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-sln + DocLink = "https://aka.ms/dotnet-sln" + }, + ["test"] = new BuiltInCommandMetadata + { + Command = TestCommand.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-test + DocLink = "https://aka.ms/dotnet-test" + }, + ["vstest"] = new BuiltInCommandMetadata + { + Command = VSTestCommand.Run, + // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-vstest + DocLink = "https://aka.ms/dotnet-vstest" + } + }; + + } +} \ No newline at end of file diff --git a/src/dotnet/DotNetCommandFactory.cs b/src/dotnet/DotNetCommandFactory.cs index 8ead957d6..d9c17b639 100644 --- a/src/dotnet/DotNetCommandFactory.cs +++ b/src/dotnet/DotNetCommandFactory.cs @@ -24,13 +24,13 @@ namespace Microsoft.DotNet.Cli NuGetFramework framework = null, string configuration = Constants.DefaultConfiguration) { - Func builtInCommand; + BuiltInCommandMetadata builtInCommand; if (!_alwaysRunOutOfProc && Program.TryGetBuiltInCommand(commandName, out builtInCommand)) { Debug.Assert(framework == null, "BuiltInCommand doesn't support the 'framework' argument."); Debug.Assert(configuration == Constants.DefaultConfiguration, "BuiltInCommand doesn't support the 'configuration' argument."); - return new BuiltInCommand(commandName, args, builtInCommand); + return new BuiltInCommand(commandName, args, builtInCommand.Command); } return Command.CreateDotNet(commandName, args, framework, configuration); diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 9af50b56e..91859d715 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -34,6 +34,7 @@ namespace Microsoft.DotNet.Cli { public class Program { + private static Dictionary> s_builtIns = new Dictionary> { ["add"] = AddCommand.Run, @@ -58,6 +59,7 @@ namespace Microsoft.DotNet.Cli ["parse"] = ParseCommand.Run }; + public static int Main(string[] args) { DebugHelper.HandleDebugSwitch(ref args); @@ -188,10 +190,10 @@ namespace Microsoft.DotNet.Cli telemetryClient.TrackEvent(command, null, null); int exitCode; - Func builtIn; - if (s_builtIns.TryGetValue(command, out builtIn)) + BuiltInCommandMetadata builtIn; + if (BuiltInCommandsCatalog.Commands.TryGetValue(command, out builtIn)) { - exitCode = builtIn(appArgs.ToArray()); + exitCode = builtIn.Command(appArgs.ToArray()); } else { @@ -234,9 +236,9 @@ namespace Microsoft.DotNet.Cli Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); } - internal static bool TryGetBuiltInCommand(string commandName, out Func builtInCommand) + internal static bool TryGetBuiltInCommand(string commandName, out BuiltInCommandMetadata builtInCommand) { - return s_builtIns.TryGetValue(commandName, out builtInCommand); + return BuiltInCommandsCatalog.Commands.TryGetValue(commandName, out builtInCommand); } private static void PrintVersion() diff --git a/src/dotnet/README.md b/src/dotnet/README.md index 5729f3039..52204fbe6 100644 --- a/src/dotnet/README.md +++ b/src/dotnet/README.md @@ -74,7 +74,7 @@ Runs a portable app named `myapp.dll`. ## ENVIRONMENT -`DOTNET_PACKAGES` +`NUGET_PACKAGES` The primary package cache. If not set, it defaults to $HOME/.nuget/packages on Unix or %HOME%\NuGet\Packages on Windows. diff --git a/src/dotnet/commands/dotnet-add/dotnet-add-package/LocalizableStrings.cs b/src/dotnet/commands/dotnet-add/dotnet-add-package/LocalizableStrings.cs index 6713d6c64..a4514f2e0 100644 --- a/src/dotnet/commands/dotnet-add/dotnet-add-package/LocalizableStrings.cs +++ b/src/dotnet/commands/dotnet-add/dotnet-add-package/LocalizableStrings.cs @@ -9,21 +9,21 @@ namespace Microsoft.DotNet.Tools.Add.PackageReference public const string AppDescription = "Command to add package reference"; - public const string CmdPackageDescription = "Package reference to add"; + public const string CmdPackageDescription = "The package reference to add."; public const string SpecifyExactlyOnePackageReference = "Please specify one package reference to add."; - public const string CmdFrameworkDescription = "Add reference only when targeting a specific framework"; + public const string CmdFrameworkDescription = "Adds reference only when targeting a specific framework."; - public const string CmdNoRestoreDescription = "Add reference without performing restore preview and compatibility check."; + public const string CmdNoRestoreDescription = "Adds reference without performing restore preview and compatibility check."; - public const string CmdSourceDescription = "Use specific NuGet package sources to use during the restore."; + public const string CmdSourceDescription = "Specifies NuGet package sources to use during the restore."; - public const string CmdPackageDirectoryDescription = "Restore the packages to this Directory ."; + public const string CmdPackageDirectoryDescription = "Restores the packages to the specified directory."; public const string CmdVersionDescription = "Version for the package to be added."; - public const string CmdDGFileException = "Unable to Create Dependency graph file for project '{0}'. Cannot add package reference."; + public const string CmdDGFileException = "Unable to create dependency graph file for project '{0}'. Cannot add package reference."; public const string CmdPackage = "PACKAGE_NAME"; diff --git a/src/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.ko.xlf b/src/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.ko.xlf index e0988549e..8bdd3fce2 100644 --- a/src/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.ko.xlf +++ b/src/dotnet/commands/dotnet-add/dotnet-add-package/xlf/LocalizableStrings.ko.xlf @@ -35,7 +35,7 @@ Use specific NuGet package sources to use during the restore. - 복원 중 사용할 특정 NuGet 패키지 소스를 사용합니다. + 복원 중 사용할 특정 NuGet 패키지 원본을 사용합니다. diff --git a/src/dotnet/commands/dotnet-help/HelpCommand.cs b/src/dotnet/commands/dotnet-help/HelpCommand.cs index 1a14efe6b..7c12ac37d 100644 --- a/src/dotnet/commands/dotnet-help/HelpCommand.cs +++ b/src/dotnet/commands/dotnet-help/HelpCommand.cs @@ -1,8 +1,13 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; +using System.Diagnostics; using System.Reflection; +using System.Runtime.InteropServices; +using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.Cli; namespace Microsoft.DotNet.Tools.Help { @@ -49,6 +54,32 @@ Project modification commands: public static int Run(string[] args) { + + CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false); + app.Name = "dotnet help"; + app.FullName = LocalizableStrings.AppFullName; + app.Description = LocalizableStrings.AppDescription; + + CommandArgument commandNameArgument = app.Argument($"<{LocalizableStrings.CommandArgumentName}>", LocalizableStrings.CommandArgumentDescription); + + app.OnExecute(() => + { + BuiltInCommandMetadata builtIn; + if (BuiltInCommandsCatalog.Commands.TryGetValue(commandNameArgument.Value, out builtIn)) + { + var process = ConfigureProcess(builtIn.DocLink); + process.Start(); + process.WaitForExit(); + } + else + { + Reporter.Error.WriteLine(String.Format(LocalizableStrings.CommandDoesNotExist, commandNameArgument.Value)); + Reporter.Output.WriteLine(UsageText); + return 1; + } + return 0; + }); + if (args.Length == 0) { PrintHelp(); @@ -56,7 +87,7 @@ Project modification commands: } else { - return Cli.Program.Main(new[] { args[0], "--help" }); + return app.Execute(args); } } @@ -73,5 +104,39 @@ Project modification commands: $" ({Product.Version})"; Reporter.Output.WriteLine(Product.LongName + versionString); } + + public static Process ConfigureProcess(string docUrl) + { + ProcessStartInfo psInfo; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + psInfo = new ProcessStartInfo + { + FileName = "cmd", + Arguments = $"/c start {docUrl}" + }; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + psInfo = new ProcessStartInfo + { + FileName = "open", + Arguments = docUrl + }; + } + else + { + psInfo = new ProcessStartInfo + { + FileName = "xdg-open", + Arguments = docUrl + }; + } + + return new Process + { + StartInfo = psInfo + }; + } } } diff --git a/src/dotnet/commands/dotnet-help/LocalizableStrings.cs b/src/dotnet/commands/dotnet-help/LocalizableStrings.cs index 04a938ac8..b6c8cbb5d 100644 --- a/src/dotnet/commands/dotnet-help/LocalizableStrings.cs +++ b/src/dotnet/commands/dotnet-help/LocalizableStrings.cs @@ -66,5 +66,18 @@ namespace Microsoft.DotNet.Tools.Help public const string CleanDefinition = "Clean build output(s)."; public const string SlnDefinition = "Modify solution (SLN) files."; + + public const string CommandDoesNotExist = "Specified command '{0}' is not a valid CLI command. Please specify a valid CLI commands. For more information, run dotnet help."; + + public const string AppFullName = ".NET CLI help utility"; + + public const string AppDescription = "Utility to get more detailed help about each of the CLI commands."; + + public const string CommandArgumentName = "COMMAND_NAME"; + + public const string CommandArgumentDescription = "CLI command for which to view more detailed help."; + + + } } diff --git a/src/redist/redist.csproj b/src/redist/redist.csproj index 95aa96d4a..7c7ef6569 100644 --- a/src/redist/redist.csproj +++ b/src/redist/redist.csproj @@ -153,18 +153,6 @@ - - - - - - - @@ -195,10 +183,6 @@ PlatformAssemblyPaths="@(PlatformAssemblies); @(PublishDirSubDirectories); $(SharedFrameworkNameVersionPath)" /> - - - Date: Sun, 19 Mar 2017 18:48:16 -0700 Subject: [PATCH 109/149] fix merge issues --- src/dotnet/BuiltInCommandsCatalog.cs | 9 ++++++- src/dotnet/Program.cs | 40 +--------------------------- 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/src/dotnet/BuiltInCommandsCatalog.cs b/src/dotnet/BuiltInCommandsCatalog.cs index 16b0b5331..0e084971b 100644 --- a/src/dotnet/BuiltInCommandsCatalog.cs +++ b/src/dotnet/BuiltInCommandsCatalog.cs @@ -133,8 +133,15 @@ namespace Microsoft.DotNet.Cli Command = VSTestCommand.Run, // aka.ms target: https://docs.microsoft.com/dotnet/articles/core/tools/dotnet-vstest DocLink = "https://aka.ms/dotnet-vstest" + }, + ["complete"] = new BuiltInCommandMetadata + { + Command = CompleteCommand.Run + }, + ["parse"] = new BuiltInCommandMetadata + { + Command = ParseCommand.Run } }; - } } \ No newline at end of file diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 1db58de40..90142296a 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; @@ -9,20 +9,6 @@ using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Configurer; using Microsoft.DotNet.PlatformAbstractions; using Microsoft.DotNet.Tools.Help; -using Microsoft.DotNet.Tools.List; -using Microsoft.DotNet.Tools.Migrate; -using Microsoft.DotNet.Tools.MSBuild; -using Microsoft.DotNet.Tools.New; -using Microsoft.DotNet.Tools.NuGet; -using Microsoft.DotNet.Tools.Pack; -using Microsoft.DotNet.Tools.Publish; -using Microsoft.DotNet.Tools.Remove; -using Microsoft.DotNet.Tools.Restore; -using Microsoft.DotNet.Tools.Run; -using Microsoft.DotNet.Tools.Sln; -using Microsoft.DotNet.Tools.Test; -using Microsoft.DotNet.Tools.VSTest; -using Microsoft.DotNet.Tools.Cache; using NuGet.Frameworks; using Command = Microsoft.DotNet.Cli.Utils.Command; @@ -30,30 +16,6 @@ namespace Microsoft.DotNet.Cli { public class Program { - private static Dictionary> s_builtIns = new Dictionary> - { - ["add"] = AddCommand.Run, - ["build"] = BuildCommand.Run, - ["cache"] = CacheCommand.Run, - ["clean"] = CleanCommand.Run, - ["help"] = HelpCommand.Run, - ["list"] = ListCommand.Run, - ["migrate"] = MigrateCommand.Run, - ["msbuild"] = MSBuildCommand.Run, - ["new"] = NewCommandShim.Run, - ["nuget"] = NuGetCommand.Run, - ["pack"] = PackCommand.Run, - ["publish"] = PublishCommand.Run, - ["remove"] = RemoveCommand.Run, - ["restore"] = RestoreCommand.Run, - ["run"] = RunCommand.Run, - ["sln"] = SlnCommand.Run, - ["test"] = TestCommand.Run, - ["vstest"] = VSTestCommand.Run, - ["complete"] = CompleteCommand.Run, - ["parse"] = ParseCommand.Run - }; - public static int Main(string[] args) { DebugHelper.HandleDebugSwitch(ref args); From 1006b30f99bf987080786c0942060f558ce57d58 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Sun, 19 Mar 2017 19:16:27 -0700 Subject: [PATCH 110/149] user muxer path in ArgumentForwardingTests --- test/ArgumentForwardingTests/ArgumentForwardingTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/ArgumentForwardingTests/ArgumentForwardingTests.cs b/test/ArgumentForwardingTests/ArgumentForwardingTests.cs index 51128ab86..4cf6a22df 100644 --- a/test/ArgumentForwardingTests/ArgumentForwardingTests.cs +++ b/test/ArgumentForwardingTests/ArgumentForwardingTests.cs @@ -25,9 +25,9 @@ namespace Microsoft.DotNet.Tests.ArgumentForwarding public ArgumentForwardingTests() { - Environment.SetEnvironmentVariable( - Constants.MSBUILD_EXE_PATH, - Path.Combine(new RepoDirectoriesProvider().Stage2Sdk, "MSBuild.dll")); +// Environment.SetEnvironmentVariable( +// Constants.MSBUILD_EXE_PATH, +// Path.Combine(new RepoDirectoriesProvider().Stage2Sdk, "MSBuild.dll")); // This test has a dependency on an argument reflector // Make sure it's been binplaced properly @@ -255,7 +255,7 @@ namespace Microsoft.DotNet.Tests.ArgumentForwarding { StartInfo = new ProcessStartInfo { - FileName = Env.GetCommandPath("dotnet", ".exe", ""), + FileName = new Muxer().MuxerPath, Arguments = $"{ReflectorPath} {testUserArgument}", UseShellExecute = false, RedirectStandardOutput = true, From 800f19dfdc695ef2a5a5f9f36f95baf25da5a792 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Sun, 19 Mar 2017 20:28:38 -0700 Subject: [PATCH 111/149] use muxer in TestCommand --- .../Commands/TestCommand.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs index 67b8ac169..a71a2a9c3 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs @@ -134,6 +134,8 @@ namespace Microsoft.DotNet.Tools.Test.Utilities private Process CreateProcess(string executable, string args) { + Console.WriteLine("[CreateProcess] " + new {executable, args}); + var psi = new ProcessStartInfo { FileName = executable, @@ -207,7 +209,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities args = newArgs; - executable = "dotnet"; + executable = new Muxer().MuxerPath; } if (!Path.IsPathRooted(executable)) From 899d19a001af06bf914377a07dcaadb68b585ab2 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Mon, 20 Mar 2017 10:32:14 -0700 Subject: [PATCH 112/149] remove comment --- test/ArgumentForwardingTests/ArgumentForwardingTests.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/ArgumentForwardingTests/ArgumentForwardingTests.cs b/test/ArgumentForwardingTests/ArgumentForwardingTests.cs index 4cf6a22df..c4c01e644 100644 --- a/test/ArgumentForwardingTests/ArgumentForwardingTests.cs +++ b/test/ArgumentForwardingTests/ArgumentForwardingTests.cs @@ -25,10 +25,6 @@ namespace Microsoft.DotNet.Tests.ArgumentForwarding public ArgumentForwardingTests() { -// Environment.SetEnvironmentVariable( -// Constants.MSBUILD_EXE_PATH, -// Path.Combine(new RepoDirectoriesProvider().Stage2Sdk, "MSBuild.dll")); - // This test has a dependency on an argument reflector // Make sure it's been binplaced properly FindAndEnsureReflectorPresent(); From 3c90711938f89654a939ee98abd7e4811fba2abb Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 20 Mar 2017 13:45:37 -0700 Subject: [PATCH 113/149] remove console output --- .../Commands/TestCommand.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs index a71a2a9c3..ce6a01e3b 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs @@ -134,8 +134,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities private Process CreateProcess(string executable, string args) { - Console.WriteLine("[CreateProcess] " + new {executable, args}); - var psi = new ProcessStartInfo { FileName = executable, From 4425398fc8348a079999c8d4f2d419c77b21fc53 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Tue, 21 Mar 2017 11:41:09 -0700 Subject: [PATCH 114/149] set loc strings for parser-formatted help --- src/dotnet/Parser.cs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/dotnet/Parser.cs b/src/dotnet/Parser.cs index e47427316..fb15afd03 100644 --- a/src/dotnet/Parser.cs +++ b/src/dotnet/Parser.cs @@ -1,13 +1,33 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; using Microsoft.DotNet.Cli.CommandLine; +using static System.Environment; +using static Microsoft.DotNet.Cli.CommandLine.LocalizableStrings; +using LocalizableStrings = Microsoft.DotNet.Tools.Run.LocalizableStrings; namespace Microsoft.DotNet.Cli { public static class Parser { + static Parser() + { + ConfigureCommandLineLocalizedStrings(); + } + + private static void ConfigureCommandLineLocalizedStrings() + { + DefaultHelpViewText.AdditionalArgumentsSection = + $"{UsageCommandsAdditionalArgsHeader}:{NewLine} {LocalizableStrings.RunCommandAdditionalArgsHelpText}"; + DefaultHelpViewText.ArgumentsSection.Title = UsageArgumentsHeader; + DefaultHelpViewText.CommandsSection.Title = UsageCommandsHeader; + DefaultHelpViewText.OptionsSection.Title = UsageOptionsHeader; + DefaultHelpViewText.Synopsis.AdditionalArguments = UsageCommandAdditionalArgs; + DefaultHelpViewText.Synopsis.Command = UsageCommandToken; + DefaultHelpViewText.Synopsis.Options = UsageOptionsToken; + DefaultHelpViewText.Synopsis.Title = UsageHeader; + } + public static CommandLine.Parser Instance { get; } = new CommandLine.Parser( options: Create.Command("dotnet", ".NET Command Line Tools", @@ -28,7 +48,7 @@ namespace Microsoft.DotNet.Cli NuGetCommandParser.NuGet(), CacheCommandParser.Cache(), Create.Command("msbuild", ""), - Create.Command("vstest", ""), + Create.Command("vstest", ""), CompleteCommandParser.Complete(), CommonOptions.HelpOption(), Create.Option("--info", ""), From 55eb812664c5ce503974c170d8093f17cb05aeb5 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Tue, 21 Mar 2017 13:46:08 -0500 Subject: [PATCH 115/149] Port #4403 back into the main source code. This change was lost when we converted the MSBuild "run3" verb to just "run". Fix #6076 --- .../MSBuildAppWithMultipleFrameworks.csproj | 7 +-- .../commands/dotnet-run/LocalizableStrings.cs | 18 ++---- src/dotnet/commands/dotnet-run/Program.cs | 4 ++ src/dotnet/commands/dotnet-run/RunCommand.cs | 62 ++++++++++++------- .../GivenDotnetRunRunsCsProj.cs | 18 ++++++ 5 files changed, 71 insertions(+), 38 deletions(-) diff --git a/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworks/MSBuildAppWithMultipleFrameworks.csproj b/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworks/MSBuildAppWithMultipleFrameworks.csproj index 0df7ccb42..255d7f570 100644 --- a/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworks/MSBuildAppWithMultipleFrameworks.csproj +++ b/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworks/MSBuildAppWithMultipleFrameworks.csproj @@ -1,13 +1,10 @@ - + Exe net451;netcoreapp2.0 + $(CLI_SharedFrameworkVersion) - - - - \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-run/LocalizableStrings.cs b/src/dotnet/commands/dotnet-run/LocalizableStrings.cs index 6ecf87779..98e318bf8 100644 --- a/src/dotnet/commands/dotnet-run/LocalizableStrings.cs +++ b/src/dotnet/commands/dotnet-run/LocalizableStrings.cs @@ -15,25 +15,19 @@ namespace Microsoft.DotNet.Tools.Run public const string CommandOptionFrameworkDescription = "Build and run the app using the specified framework. The framework has to be specified in the project file. "; + public const string CommandOptionNoBuild = "Do not build the project before running."; + public const string CommandOptionProjectDescription = "The path to the project file to run (defaults to the current directory if there is only one project)."; public const string RunCommandException = "The build failed. Please fix the build errors and run again."; + public const string RunCommandExceptionUnableToRunSpecifyFramework = "Unable to run your project\nYour project targets multiple frameworks. Please specify which framework to run using '{0}'."; + public const string RunCommandExceptionUnableToRun = "Unable to run your project\nPlease ensure you have a runnable project type and ensure '{0}' supports this project.\nThe current {1} is '{2}'"; - public const string RunCommandExceptionUnableToRun1 = "Unable to run your project."; + public const string RunCommandExceptionNoProjects = "Couldn't find a project to run. Ensure a project exists in {0}, or pass the path to the project using {1}."; - public const string RunCommandExceptionUnableToRun2 = "Please ensure you have a runnable project type and ensure 'dotnet run' supports this project."; - - public const string RunCommandExceptionUnableToRun3 = "The current OutputType is "; - - public const string RunCommandInvalidOperationException1 = "Couldn't find a project to run. Ensure a project exists in "; - - public const string RunCommandInvalidOperationException2 = "Or pass the path to the project using --project"; - - public const string RunCommandInvalidOperationException3 = "Specify which project file to use because this "; - - public const string RunCommandInvalidOperationException4 = "contains more than one project file."; + public const string RunCommandExceptionMultipleProjects = "Specify which project file to use because {0} contains more than one project file."; public const string RunCommandAdditionalArgsHelpText = "Arguments passed to the application that is being run."; } diff --git a/src/dotnet/commands/dotnet-run/Program.cs b/src/dotnet/commands/dotnet-run/Program.cs index f608695eb..e93f00745 100644 --- a/src/dotnet/commands/dotnet-run/Program.cs +++ b/src/dotnet/commands/dotnet-run/Program.cs @@ -28,6 +28,9 @@ namespace Microsoft.DotNet.Tools.Run CommandOption framework = app.Option( $"-f|--framework <{LocalizableStrings.CommandOptionFramework}>", LocalizableStrings.CommandOptionFrameworkDescription, CommandOptionType.SingleValue); + CommandOption noBuild = app.Option( + "--no-build", LocalizableStrings.CommandOptionNoBuild, + CommandOptionType.BoolValue); CommandOption project = app.Option( "-p|--project", LocalizableStrings.CommandOptionProjectDescription, CommandOptionType.SingleValue); @@ -38,6 +41,7 @@ namespace Microsoft.DotNet.Tools.Run runCmd.Configuration = configuration.Value(); runCmd.Framework = framework.Value(); + runCmd.NoBuild = noBuild.BoolValue ?? false; runCmd.Project = project.Value(); runCmd.Args = app.RemainingArguments; diff --git a/src/dotnet/commands/dotnet-run/RunCommand.cs b/src/dotnet/commands/dotnet-run/RunCommand.cs index e9f0c8bdd..06a85cc0d 100644 --- a/src/dotnet/commands/dotnet-run/RunCommand.cs +++ b/src/dotnet/commands/dotnet-run/RunCommand.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using Microsoft.Build.Execution; +using Microsoft.Build.Evaluation; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; @@ -15,10 +15,12 @@ namespace Microsoft.DotNet.Tools.Run { public string Configuration { get; set; } public string Framework { get; set; } + public bool NoBuild { get; set; } public string Project { get; set; } public IReadOnlyList Args { get; set; } private List _args; + private bool ShouldBuild => !NoBuild; public RunCommand() { @@ -28,7 +30,10 @@ namespace Microsoft.DotNet.Tools.Run { Initialize(); - EnsureProjectIsBuilt(); + if (ShouldBuild) + { + EnsureProjectIsBuilt(); + } ICommand runCommand = GetRunCommand(); @@ -40,9 +45,9 @@ namespace Microsoft.DotNet.Tools.Run private void EnsureProjectIsBuilt() { List buildArgs = new List(); - - buildArgs.Add(Project); - + + buildArgs.Add(Project); + buildArgs.Add("/nologo"); buildArgs.Add("/verbosity:quiet"); @@ -82,23 +87,16 @@ namespace Microsoft.DotNet.Tools.Run globalProperties.Add("TargetFramework", Framework); } - ProjectInstance projectInstance = new ProjectInstance(Project, globalProperties, null); + Project project = new Project(Project, globalProperties, null); - string runProgram = projectInstance.GetPropertyValue("RunCommand"); + string runProgram = project.GetPropertyValue("RunCommand"); if (string.IsNullOrEmpty(runProgram)) { - string outputType = projectInstance.GetPropertyValue("OutputType"); - - throw new GracefulException( - string.Format( - LocalizableStrings.RunCommandExceptionUnableToRun, - "dotnet run", - "OutputType", - outputType)); + ThrowUnableToRunError(project); } - string runArguments = projectInstance.GetPropertyValue("RunArguments"); - string runWorkingDirectory = projectInstance.GetPropertyValue("RunWorkingDirectory"); + string runArguments = project.GetPropertyValue("RunArguments"); + string runWorkingDirectory = project.GetPropertyValue("RunWorkingDirectory"); string fullArguments = runArguments; if (_args.Any()) @@ -112,6 +110,30 @@ namespace Microsoft.DotNet.Tools.Run .WorkingDirectory(runWorkingDirectory); } + private void ThrowUnableToRunError(Project project) + { + string targetFrameworks = project.GetPropertyValue("TargetFrameworks"); + if (!string.IsNullOrEmpty(targetFrameworks)) + { + string targetFramework = project.GetPropertyValue("TargetFramework"); + if (string.IsNullOrEmpty(targetFramework)) + { + var framework = "--framework"; + + throw new GracefulException(LocalizableStrings.RunCommandExceptionUnableToRunSpecifyFramework, framework); + } + } + + string outputType = project.GetPropertyValue("OutputType"); + + throw new GracefulException( + string.Format( + LocalizableStrings.RunCommandExceptionUnableToRun, + "dotnet run", + "OutputType", + outputType)); + } + private void Initialize() { if (string.IsNullOrWhiteSpace(Project)) @@ -123,13 +145,11 @@ namespace Microsoft.DotNet.Tools.Run { var project = "--project"; - throw new InvalidOperationException( - $"Couldn't find a project to run. Ensure a project exists in {directory}, or pass the path to the project using {project}"); + throw new GracefulException(LocalizableStrings.RunCommandExceptionNoProjects, directory, project); } else if (projectFiles.Length > 1) { - throw new InvalidOperationException( - $"Specify which project file to use because {directory} contains more than one project file."); + throw new GracefulException(LocalizableStrings.RunCommandExceptionMultipleProjects, directory); } Project = projectFiles[0]; diff --git a/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs b/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs index f4e3913c9..466d0c650 100644 --- a/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs +++ b/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs @@ -145,5 +145,23 @@ namespace Microsoft.DotNet.Cli.Run.Tests .Should().Pass() .And.HaveStdOutContaining("Hello World"); } + + [Fact] + public void ItReportsAGoodErrorWhenProjectHasMultipleFrameworks() + { + var testAppName = "MSBuildAppWithMultipleFrameworks"; + var testInstance = TestAssets.Get(testAppName) + .CreateInstance() + .WithSourceFiles() + .WithRestoreFiles(); + + // use --no-build so this test can run on all platforms. + // the test app targets net451, which can't be built on non-Windows + new RunCommand() + .WithWorkingDirectory(testInstance.Root) + .ExecuteWithCapturedOutput("--no-build") + .Should().Fail() + .And.HaveStdErrContaining("--framework"); + } } } From 0eca6cb9cd890bd7f4db14bec783e9a8558ff482 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Tue, 21 Mar 2017 14:55:33 -0700 Subject: [PATCH 116/149] remove unused forwarded argument --- src/dotnet/commands/dotnet-run/RunCommandParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dotnet/commands/dotnet-run/RunCommandParser.cs b/src/dotnet/commands/dotnet-run/RunCommandParser.cs index aaadd8aa9..db6c64a70 100644 --- a/src/dotnet/commands/dotnet-run/RunCommandParser.cs +++ b/src/dotnet/commands/dotnet-run/RunCommandParser.cs @@ -35,7 +35,7 @@ namespace Microsoft.DotNet.Cli Create.Option( "--no-build", LocalizableStrings.CommandOptionNoBuildDescription, - Accept.NoArguments().ForwardAs("/p:NoBuild=true")) + Accept.NoArguments()) }); } } \ No newline at end of file From be86933ff824cea7692743e9bccb6452f4a59d6f Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Tue, 21 Mar 2017 14:55:56 -0700 Subject: [PATCH 117/149] use DotnetCommand instead of TestCommand --- test/dotnet.Tests/PackagedCommandTests.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/test/dotnet.Tests/PackagedCommandTests.cs b/test/dotnet.Tests/PackagedCommandTests.cs index 79e1604c5..4e9a75ba1 100644 --- a/test/dotnet.Tests/PackagedCommandTests.cs +++ b/test/dotnet.Tests/PackagedCommandTests.cs @@ -355,10 +355,9 @@ namespace Microsoft.DotNet.Tests p.Save(); } - class HelloCommand : TestCommand + class HelloCommand : DotnetCommand { public HelloCommand() - : base("dotnet") { } @@ -375,10 +374,9 @@ namespace Microsoft.DotNet.Tests } } - class PortableCommand : TestCommand + class PortableCommand : DotnetCommand { public PortableCommand() - : base("dotnet") { } @@ -395,12 +393,11 @@ namespace Microsoft.DotNet.Tests } } - class GenericCommand : TestCommand + class GenericCommand : DotnetCommand { private readonly string _commandName; public GenericCommand(string commandName) - : base("dotnet") { _commandName = commandName; } @@ -418,10 +415,9 @@ namespace Microsoft.DotNet.Tests } } - class DependencyContextTestCommand : TestCommand + class DependencyContextTestCommand : DotnetCommand { public DependencyContextTestCommand() - : base("dotnet") { } From 1b8b1d2b2cc82b6427846a259783f452a550583a Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Tue, 21 Mar 2017 14:56:12 -0700 Subject: [PATCH 118/149] use muxer path whenever invoking dotnet --- .../Commands/TestCommand.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs index ce6a01e3b..03ee56d6c 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/TestCommand.cs @@ -70,15 +70,11 @@ namespace Microsoft.DotNet.Tools.Test.Utilities ResolveCommand(ref resolvedCommand, ref args); - var commandPath = Env.GetCommandPath(resolvedCommand, ".exe", ".cmd", "") ?? - Env.GetCommandPathFromRootPath(_baseDirectory, resolvedCommand, ".exe", ".cmd", ""); - - Console.WriteLine($"Executing (Captured Output) - {commandPath} {args} - {WorkingDirectoryInfo()}"); + Console.WriteLine($"Executing (Captured Output) - {resolvedCommand} {args} - {WorkingDirectoryInfo()}"); return Task.Run(async () => await ExecuteAsyncInternal(resolvedCommand, args)).Result; } - private async Task ExecuteAsyncInternal(string executable, string args) { var stdOut = new List(); @@ -209,8 +205,11 @@ namespace Microsoft.DotNet.Tools.Test.Utilities executable = new Muxer().MuxerPath; } - - if (!Path.IsPathRooted(executable)) + else if ( executable == "dotnet") + { + executable = new Muxer().MuxerPath; + } + else if (!Path.IsPathRooted(executable)) { executable = Env.GetCommandPath(executable) ?? Env.GetCommandPathFromRootPath(_baseDirectory, executable); From bdfc7593509f7ea20943a81de3b3932b03d4f7e8 Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Tue, 21 Mar 2017 18:03:17 -0700 Subject: [PATCH 119/149] Don't write `\b` when output is redirected Fixes #6096 --- src/Microsoft.DotNet.Archive/ConsoleProgressReport.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.DotNet.Archive/ConsoleProgressReport.cs b/src/Microsoft.DotNet.Archive/ConsoleProgressReport.cs index 91e555c37..e8f6cd0df 100644 --- a/src/Microsoft.DotNet.Archive/ConsoleProgressReport.cs +++ b/src/Microsoft.DotNet.Archive/ConsoleProgressReport.cs @@ -29,9 +29,16 @@ namespace Microsoft.DotNet.Archive string line = $"{value.Phase} {progress}%"; if (value.Phase == _currentPhase) { - Console.Write(new string('\b', _lastLineLength)); + if (Console.IsOutputRedirected) + { + Console.Write($"...{progress}%"); + } + else + { + Console.Write(new string('\b', _lastLineLength)); + Console.Write(line); + } - Console.Write(line); _lastLineLength = line.Length; if (progress == 100) From a472daffb8b7b68c00cf19aac4cdd052f02c77ff Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Tue, 21 Mar 2017 16:52:21 -0700 Subject: [PATCH 120/149] Only restore crossgen for the current rid. Today we download crossgen for all supported runtime ids. This introduces a dependency on having builds for all supported platforms in order to build the CLI on a single platform. This is problematic for the build from source effort because we only build artifacts for a specific rid (the RID of the host/target). Update the CrossGen.Dependencies project to restore for only the RID we are building for. --- tools/CrossGen.Dependencies/CrossGen.Dependencies.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/CrossGen.Dependencies/CrossGen.Dependencies.csproj b/tools/CrossGen.Dependencies/CrossGen.Dependencies.csproj index 12b809970..a62dad12b 100644 --- a/tools/CrossGen.Dependencies/CrossGen.Dependencies.csproj +++ b/tools/CrossGen.Dependencies/CrossGen.Dependencies.csproj @@ -3,11 +3,11 @@ netcoreapp2.0 - linux-x64;win7-x64;win7-x86;osx.10.10-x64;osx.10.11-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;centos.7-x64;rhel.7.2-x64;debian.8-x64;fedora.24-x64;opensuse.42.1-x64 + $(Rid) - \ No newline at end of file + From 949fbd59dbe768f8a971f3e72d85b13dfb77c22e Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Tue, 21 Mar 2017 17:34:32 -0700 Subject: [PATCH 121/149] Remove dotnet-cli-build's dependency on CoreCLR dotnet-cli-build had a package reference to both CoreCLR and a new version of Microsoft.NETCore.App in order to pull down crossgen. Crossgen is now restored by a specific project that only deals will pulling down crossgen, so we can remove this code. Fixes #6093 --- .../dotnet-cli-build/dotnet-cli-build.csproj | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/build_projects/dotnet-cli-build/dotnet-cli-build.csproj b/build_projects/dotnet-cli-build/dotnet-cli-build.csproj index 952ebb548..abace8f08 100644 --- a/build_projects/dotnet-cli-build/dotnet-cli-build.csproj +++ b/build_projects/dotnet-cli-build/dotnet-cli-build.csproj @@ -7,9 +7,6 @@ true bin\$(Configuration) $(PackageTargetFallback);portable-net45+win8+wp8+wpa81 - - - $(CoreCLRRid) @@ -18,7 +15,6 @@ - @@ -33,9 +29,5 @@ - - - - - \ No newline at end of file + From fa3a4468117bced02b583ae770acaf19f3a80eb1 Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Tue, 21 Mar 2017 19:28:09 -0700 Subject: [PATCH 122/149] Fix crossgen step on win10 box --- tools/CrossGen.Dependencies/CrossGen.Dependencies.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/CrossGen.Dependencies/CrossGen.Dependencies.csproj b/tools/CrossGen.Dependencies/CrossGen.Dependencies.csproj index a62dad12b..5fd067694 100644 --- a/tools/CrossGen.Dependencies/CrossGen.Dependencies.csproj +++ b/tools/CrossGen.Dependencies/CrossGen.Dependencies.csproj @@ -3,7 +3,7 @@ netcoreapp2.0 - $(Rid) + $(CoreCLRRid) From 4abb4d97a914ba7c09359c3dbdd7f6f4dbf270ba Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Tue, 21 Mar 2017 20:21:34 -0700 Subject: [PATCH 123/149] Update dotnet/sdk version --- build/DependencyVersions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/DependencyVersions.props b/build/DependencyVersions.props index d2c6eedfe..dfacb08a6 100644 --- a/build/DependencyVersions.props +++ b/build/DependencyVersions.props @@ -4,7 +4,7 @@ 2.0.0-beta-001791-00 15.2.0-preview-000047-02 2.0.0-rc4-61325-08 - 2.0.0-alpha-20170320-1 + 2.0.0-alpha-20170322-1 4.3.0-beta1-2342 1.0.0-alpha-20170130-3-281 15.1.0-preview-20170316-05 From 53f9b4f427cc9f83a0f4bc1e0309c48f24fa225b Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Wed, 22 Mar 2017 13:04:58 -0700 Subject: [PATCH 124/149] fix spelling error --- src/dotnet/CommandLine/CommandLineApplication.cs | 2 +- src/dotnet/CommandLine/CommandParsingException.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dotnet/CommandLine/CommandLineApplication.cs b/src/dotnet/CommandLine/CommandLineApplication.cs index a22e77535..64b6b3d17 100644 --- a/src/dotnet/CommandLine/CommandLineApplication.cs +++ b/src/dotnet/CommandLine/CommandLineApplication.cs @@ -207,7 +207,7 @@ namespace Microsoft.DotNet.Cli.CommandLine throw new CommandParsingException( command, "Required command missing", - isRequireSubCommandMissing: true); + isRequiredSubCommandMissing: true); } return command.Invoke(); diff --git a/src/dotnet/CommandLine/CommandParsingException.cs b/src/dotnet/CommandLine/CommandParsingException.cs index 79e19e522..82c675f4b 100644 --- a/src/dotnet/CommandLine/CommandParsingException.cs +++ b/src/dotnet/CommandLine/CommandParsingException.cs @@ -8,7 +8,7 @@ namespace Microsoft.DotNet.Cli.CommandLine { internal class CommandParsingException : Exception { - private readonly bool _isRequireSubCommandMissing; + private readonly bool _isRequiredSubCommandMissing; public CommandParsingException( string message, @@ -21,11 +21,11 @@ namespace Microsoft.DotNet.Cli.CommandLine public CommandParsingException( CommandLineApplication command, string message, - bool isRequireSubCommandMissing = false) + bool isRequiredSubCommandMissing = false) : this(message) { Command = command; - _isRequireSubCommandMissing = isRequireSubCommandMissing; + _isRequiredSubCommandMissing = isRequiredSubCommandMissing; } public CommandLineApplication Command { get; } @@ -36,7 +36,7 @@ namespace Microsoft.DotNet.Cli.CommandLine { get { - return _isRequireSubCommandMissing + return _isRequiredSubCommandMissing ? CommonLocalizableStrings.RequiredCommandNotPassed : base.Message; } From 055523770a8bbd8decf0e1e4b4624cd5fb04b880 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Wed, 22 Mar 2017 13:51:09 -0700 Subject: [PATCH 125/149] update CliCommandLineParser version --- src/dotnet/dotnet.csproj | 2 +- test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index a9c9a6f86..a8d4472d7 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index c37528336..f9b8b2d07 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From c58b0b70a60e90f6c0bce0b31b1bc44cdd2beaa6 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Wed, 22 Mar 2017 13:51:32 -0700 Subject: [PATCH 126/149] add null propagation --- src/dotnet/commands/dotnet-complete/ParseCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dotnet/commands/dotnet-complete/ParseCommand.cs b/src/dotnet/commands/dotnet-complete/ParseCommand.cs index fb86c6300..90972e119 100644 --- a/src/dotnet/commands/dotnet-complete/ParseCommand.cs +++ b/src/dotnet/commands/dotnet-complete/ParseCommand.cs @@ -31,7 +31,7 @@ namespace Microsoft.DotNet.Cli Console.WriteLine(); foreach (var error in result.Errors) { - Console.WriteLine($"[{error?.Option?.Name ?? "???"}] {error.Message}"); + Console.WriteLine($"[{error?.Option?.Name ?? "???"}] {error?.Message}"); } } From 94bc781df730b2219c1af081e2e4539f833840d5 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Wed, 22 Mar 2017 13:51:45 -0700 Subject: [PATCH 127/149] remove debug file output --- src/dotnet/commands/dotnet-complete/CompleteCommand.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs index a8375687a..d188171ac 100644 --- a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs +++ b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs @@ -2,9 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; -using System.IO; using System.Linq; -using System.Text; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.Utils; @@ -28,11 +26,6 @@ namespace Microsoft.DotNet.Cli var suggestions = Suggestions(complete); - var log = new StringBuilder(); - log.AppendLine($"args: {string.Join(" ", args.Select(a => $"\"{a}\""))}"); - log.AppendLine("diagram: " + result.Diagram()); - File.WriteAllText("parse.log", log.ToString()); - foreach (var suggestion in suggestions) { Console.WriteLine(suggestion); @@ -40,8 +33,7 @@ namespace Microsoft.DotNet.Cli } catch (Exception e) { - File.WriteAllText("dotnet completion exception.log", e.ToString()); - throw; + return 1; } return 0; From 4a2c3932e7304dd54266d5850fad1ead1da03e90 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Wed, 22 Mar 2017 15:26:58 -0700 Subject: [PATCH 128/149] new parser version, adjust column spacing in tests --- .../dotnet-add-reference.Tests/GivenDotnetAddReference.cs | 8 ++++---- .../GivenDotnetListReference.cs | 4 ++-- .../dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs | 8 ++++---- test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs | 6 +++--- test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs | 4 ++-- test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs b/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs index 2192205d4..cac2a687d 100644 --- a/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs +++ b/test/dotnet-add-reference.Tests/GivenDotnetAddReference.cs @@ -19,12 +19,12 @@ namespace Microsoft.DotNet.Cli.Add.Reference.Tests Usage: dotnet add reference [options] Arguments: - The project file to operate on. If a file is not specified, the command will search the current directory for one. - Project to project references to add + The project file to operate on. If a file is not specified, the command will search the current directory for one. + Project to project references to add Options: - -h, --help Show help information - -f, --framework Add reference only when targeting a specific framework + -h, --help Show help information + -f, --framework Add reference only when targeting a specific framework "; const string FrameworkNet451Arg = "-f net451"; diff --git a/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs b/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs index f82c98700..e6205904d 100644 --- a/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs +++ b/test/dotnet-list-reference.Tests/GivenDotnetListReference.cs @@ -18,10 +18,10 @@ namespace Microsoft.DotNet.Cli.List.Reference.Tests Usage: dotnet list reference [options] Arguments: - The project file to operate on. If a file is not specified, the command will search the current directory for one. + The project file to operate on. If a file is not specified, the command will search the current directory for one. Options: - -h, --help Show help information + -h, --help Show help information "; const string FrameworkNet451Arg = "-f net451"; diff --git a/test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs b/test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs index 956d380d7..a098e9719 100644 --- a/test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs +++ b/test/dotnet-remove-reference.Tests/GivenDotnetRemoveP2P.cs @@ -18,12 +18,12 @@ namespace Microsoft.DotNet.Cli.Remove.Reference.Tests Usage: dotnet remove reference [options] Arguments: - The project file to operate on. If a file is not specified, the command will search the current directory for one. - Project to project references to remove + The project file to operate on. If a file is not specified, the command will search the current directory for one. + Project to project references to remove Options: - -h, --help Show help information - -f, --framework Remove reference only when targeting a specific framework + -h, --help Show help information + -f, --framework Remove reference only when targeting a specific framework "; const string FrameworkNet451Arg = "-f net451"; diff --git a/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs b/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs index 8ee3ca5c4..c022a8d1c 100644 --- a/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs +++ b/test/dotnet-sln-add.Tests/GivenDotnetSlnAdd.cs @@ -20,11 +20,11 @@ namespace Microsoft.DotNet.Cli.Sln.Add.Tests Usage: dotnet sln add [options] Arguments: - Solution file to operate on. If not specified, the command will search the current directory for one. - Add one or more specified projects to the solution. + Solution file to operate on. If not specified, the command will search the current directory for one. + Add one or more specified projects to the solution. Options: - -h, --help Show help information + -h, --help Show help information "; private ITestOutputHelper _output; diff --git a/test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs b/test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs index abaa51cea..781322e71 100644 --- a/test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs +++ b/test/dotnet-sln-list.Tests/GivenDotnetSlnList.cs @@ -18,10 +18,10 @@ namespace Microsoft.DotNet.Cli.Sln.List.Tests Usage: dotnet sln list [options] Arguments: - Solution file to operate on. If not specified, the command will search the current directory for one. + Solution file to operate on. If not specified, the command will search the current directory for one. Options: - -h, --help Show help information + -h, --help Show help information "; [Theory] diff --git a/test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs b/test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs index c0e51ff8a..f32bef616 100644 --- a/test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs +++ b/test/dotnet-sln-remove.Tests/GivenDotnetSlnRemove.cs @@ -18,11 +18,11 @@ namespace Microsoft.DotNet.Cli.Sln.Remove.Tests Usage: dotnet sln remove [options] Arguments: - Solution file to operate on. If not specified, the command will search the current directory for one. - Remove the specified project(s) from the solution. The project is not impacted. + Solution file to operate on. If not specified, the command will search the current directory for one. + Remove the specified project(s) from the solution. The project is not impacted. Options: - -h, --help Show help information + -h, --help Show help information "; private const string ExpectedSlnContentsAfterRemove = @" From a5051a0aff5b402cc9a3cddef280ca5d0256babc Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Tue, 21 Mar 2017 19:02:20 -0700 Subject: [PATCH 129/149] Generate bundled version props --- build/BundledVersions.targets | 67 +++++++++++++++++++++++++++++++++++ src/redist/redist.csproj | 1 + 2 files changed, 68 insertions(+) create mode 100644 build/BundledVersions.targets diff --git a/build/BundledVersions.targets b/build/BundledVersions.targets new file mode 100644 index 000000000..065eefe96 --- /dev/null +++ b/build/BundledVersions.targets @@ -0,0 +1,67 @@ + + + $(IntermediateDirectory)/GeneratedMSBuildImports + 15.0/Imports/Microsoft.Common.props/ImportBefore + Microsoft.NETCoreSdk.BundledVersions.props + + + + + + + <_NETStandardLibraryVersions Include="@(PackageDefinitions->'%(Version)')" + Condition="%(PackageDefinitions.Name) == 'NetStandard.Library'" /> + + + + + + <_NETCoreAppPackageVersion>$(CLI_SharedFrameworkVersion) + <_NETStandardPackageVersion>@(_NETStandardLibraryVersions->Distinct()) + + + <_NETCoreAppTargetFrameworkVersion>$(_NETCoreAppPackageVersion.Split('.')[0]).$(_NETCoreAppPackageVersion.Split('.')[1]) + <_NETStandardTargetFrameworkVersion>$(_NETStandardPackageVersion.Split('.')[0]).$(_NETStandardPackageVersion.Split('.')[1]) + + + + + + $(_NETCoreAppTargetFrameworkVersion) + $(_NETCoreAppPackageVersion) + $(_NETStandardTargetFrameworkVersion) + $(_NETStandardPackageVersion) + + +]]> + + + + + + + + + + + + diff --git a/src/redist/redist.csproj b/src/redist/redist.csproj index 7c7ef6569..5bf539615 100644 --- a/src/redist/redist.csproj +++ b/src/redist/redist.csproj @@ -2,6 +2,7 @@ + $(CliVersionPrefix) From 857df6a38400ec6fd284a236fb8244165e93a35f Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Wed, 22 Mar 2017 15:47:54 -0700 Subject: [PATCH 130/149] remove unused variable --- src/dotnet/commands/dotnet-complete/CompleteCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs index d188171ac..a6061d37d 100644 --- a/src/dotnet/commands/dotnet-complete/CompleteCommand.cs +++ b/src/dotnet/commands/dotnet-complete/CompleteCommand.cs @@ -31,7 +31,7 @@ namespace Microsoft.DotNet.Cli Console.WriteLine(suggestion); } } - catch (Exception e) + catch (Exception) { return 1; } From e1cb32a1f21790f7102a40622f1d36335a50e5ca Mon Sep 17 00:00:00 2001 From: Justin Emgarten Date: Wed, 22 Mar 2017 19:51:00 -0700 Subject: [PATCH 131/149] Updating CLI_NETSDK_Version and CLI_NuGet_Version --- build/DependencyVersions.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/DependencyVersions.props b/build/DependencyVersions.props index d2c6eedfe..a508a8c63 100644 --- a/build/DependencyVersions.props +++ b/build/DependencyVersions.props @@ -4,8 +4,8 @@ 2.0.0-beta-001791-00 15.2.0-preview-000047-02 2.0.0-rc4-61325-08 - 2.0.0-alpha-20170320-1 - 4.3.0-beta1-2342 + 2.0.0-alpha-20170323-1 + 4.3.0-beta1-2418 1.0.0-alpha-20170130-3-281 15.1.0-preview-20170316-05 $(CLI_SharedFrameworkVersion) From 149f292b6a66181ec74a7eb4f937e15932acc1a2 Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Thu, 23 Mar 2017 08:15:41 -0700 Subject: [PATCH 132/149] check for help in DotNetTopLevelCommandBase --- src/dotnet/DotNetTopLevelCommandBase.cs | 2 + src/dotnet/ParseResultExtensions.cs | 21 +++++---- .../GivenThatTheUserRequestsHelp.cs | 44 +++++++++++++++++++ 3 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 test/dotnet.Tests/GivenThatTheUserRequestsHelp.cs diff --git a/src/dotnet/DotNetTopLevelCommandBase.cs b/src/dotnet/DotNetTopLevelCommandBase.cs index 5e2850ee5..650a5fcbb 100644 --- a/src/dotnet/DotNetTopLevelCommandBase.cs +++ b/src/dotnet/DotNetTopLevelCommandBase.cs @@ -28,6 +28,8 @@ namespace Microsoft.DotNet.Cli ParseResult = parser.ParseFrom($"dotnet {CommandName}", args); + ParseResult.ShowHelpIfRequested(); + var subcommandName = ParseResult.Command().Name; try diff --git a/src/dotnet/ParseResultExtensions.cs b/src/dotnet/ParseResultExtensions.cs index 82932de0b..b662d9430 100644 --- a/src/dotnet/ParseResultExtensions.cs +++ b/src/dotnet/ParseResultExtensions.cs @@ -13,6 +13,19 @@ namespace Microsoft.DotNet.Cli Console.WriteLine(parseResult.Command().HelpView()); public static void ShowHelpOrErrorIfAppropriate(this ParseResult parseResult) + { + parseResult.ShowHelpIfRequested(); + + if (parseResult.Errors.Any()) + { + throw new CommandParsingException( + message: string.Join(Environment.NewLine, + parseResult.Errors.Select(e => e.Message)), + helpText: parseResult?.Command()?.HelpView()); + } + } + + public static void ShowHelpIfRequested(this ParseResult parseResult) { var appliedCommand = parseResult.AppliedCommand(); @@ -23,14 +36,6 @@ namespace Microsoft.DotNet.Cli // NOTE: this is a temporary stage in refactoring toward the ClicCommandLineParser being used at the CLI entry point. throw new HelpException(parseResult.Command().HelpView()); } - - if (parseResult.Errors.Any()) - { - throw new CommandParsingException( - message: string.Join(Environment.NewLine, - parseResult.Errors.Select(e => e.Message)), - helpText: parseResult?.Command()?.HelpView()); - } } } } \ No newline at end of file diff --git a/test/dotnet.Tests/GivenThatTheUserRequestsHelp.cs b/test/dotnet.Tests/GivenThatTheUserRequestsHelp.cs new file mode 100644 index 000000000..153a375d0 --- /dev/null +++ b/test/dotnet.Tests/GivenThatTheUserRequestsHelp.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using FluentAssertions; +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; + +namespace dotnet.Tests +{ + public class GivenThatTheUserRequestsHelp + { + [Theory] + [InlineData("-h")] + [InlineData("add -h")] + [InlineData("add package -h")] + [InlineData("add reference -h")] + [InlineData("build -h")] + [InlineData("cache -h")] + [InlineData("clean -h")] + [InlineData("list -h")] + [InlineData("migrate -h")] + [InlineData("msbuild -h")] + [InlineData("new -h")] + [InlineData("nuget -h")] + [InlineData("pack -h")] + [InlineData("publish -h")] + [InlineData("remove -h")] + [InlineData("restore -h")] + [InlineData("run -h")] + [InlineData("sln -h")] + [InlineData("sln add -h")] + [InlineData("sln list -h")] + [InlineData("sln remove -h")] + [InlineData("test -h")] + public void TheResponseIsNotAnError(string commandLine) + { + var result = new DotnetCommand() + .ExecuteWithCapturedOutput(commandLine); + + result.ExitCode.Should().Be(0); + } + } +} \ No newline at end of file From b4e21df4248c0248885ac5e9a93ab6c846f918af Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Thu, 23 Mar 2017 11:21:39 -0700 Subject: [PATCH 133/149] Add test coverage for bundled version props --- .../dotnet-new.Tests/GivenThatIWantANewApp.cs | 82 +++++++++++++++---- 1 file changed, 66 insertions(+), 16 deletions(-) diff --git a/test/dotnet-new.Tests/GivenThatIWantANewApp.cs b/test/dotnet-new.Tests/GivenThatIWantANewApp.cs index 649fa62ff..09454669b 100644 --- a/test/dotnet-new.Tests/GivenThatIWantANewApp.cs +++ b/test/dotnet-new.Tests/GivenThatIWantANewApp.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Xml.Linq; using FluentAssertions; using Microsoft.DotNet.Tools.Test.Utilities; +using Microsoft.Extensions.DependencyModel; using Xunit; namespace Microsoft.DotNet.New.Tests @@ -70,36 +71,85 @@ namespace Microsoft.DotNet.New.Tests .Should().Pass(); } - [Fact] - public void NewClassLibRestoresCorrectNetStandardLibraryVersion() + [Theory] + [InlineData("console", "RuntimeFrameworkVersion", "Microsoft.NETCore.App")] + [InlineData("classlib", "NetStandardImplicitPackageVersion", "NETStandard.Library")] + public void NewProjectRestoresCorrectPackageVersion(string type, string propertyName, string packageName) { - var rootPath = TestAssets.CreateTestDirectory().FullName; + // These will fail when templates stop including explicit version. + // Collapse back to one method and remove the explicit version handling when that happens. + NewProjectRestoresCorrectPackageVersion(type, propertyName, packageName, deleteExplicitVersion: true); + NewProjectRestoresCorrectPackageVersion(type, propertyName, packageName, deleteExplicitVersion: false); + } + + private void NewProjectRestoresCorrectPackageVersion(string type, string propertyName, string packageName, bool deleteExplicitVersion) + { + var rootPath = TestAssets.CreateTestDirectory(identifier: $"_{type}_{deleteExplicitVersion}").FullName; var packagesDirectory = Path.Combine(rootPath, "packages"); - var projectName = "Library"; - var projectFileName = $"{projectName}.csproj"; + var projectName = "Project"; + var expectedVersion = GetFrameworkPackageVersion(); new NewCommand() .WithWorkingDirectory(rootPath) - .Execute($"classlib --name {projectName} -o .") + .Execute($"{type} --name {projectName} -o .") .Should().Pass(); + ValidateAndRemoveExplicitVersion(); + new RestoreCommand() .WithWorkingDirectory(rootPath) .Execute($"--packages {packagesDirectory}") .Should().Pass(); - var expectedVersion = XDocument.Load(Path.Combine(rootPath, projectFileName)) - .Elements("Project") - .Elements("PropertyGroup") - .Elements("NetStandardImplicitPackageVersion") - .FirstOrDefault() - ?.Value; - - expectedVersion.Should().NotBeNullOrEmpty("Could not find NetStandardImplicitPackageVersion property in a new classlib."); - - new DirectoryInfo(Path.Combine(packagesDirectory, "netstandard.library")) + new DirectoryInfo(Path.Combine(packagesDirectory, packageName)) .Should().Exist() .And.HaveDirectory(expectedVersion); + + string GetFrameworkPackageVersion() + { + var dotnetDir = new FileInfo(DotnetUnderTest.FullName).Directory; + var sharedFxDir = dotnetDir + .GetDirectory("shared", "Microsoft.NETCore.App") + .EnumerateDirectories() + .Single(d => d.Name.StartsWith("2.0.0")); + + if (packageName == "Microsoft.NETCore.App") + { + return sharedFxDir.Name; + } + + var depsFile = Path.Combine(sharedFxDir.FullName, "Microsoft.NETCore.App.deps.json"); + using (var stream = File.OpenRead(depsFile)) + using (var reader = new DependencyContextJsonReader()) + { + var context = reader.Read(stream); + var dependency = context + .RuntimeLibraries + .Single(library => library.Name.Equals(packageName, StringComparison.OrdinalIgnoreCase)); + + return dependency.Version; + } + } + + // Remove when templates stop putting an explicit version + void ValidateAndRemoveExplicitVersion() + { + var projectFileName = $"{projectName}.csproj"; + var projectPath = Path.Combine(rootPath, projectFileName); + var projectDocument = XDocument.Load(projectPath); + var explicitVersionNode = projectDocument + .Elements("Project") + .Elements("PropertyGroup") + .Elements(propertyName) + .SingleOrDefault(); + + explicitVersionNode.Should().NotBeNull(); + if (deleteExplicitVersion) + { + explicitVersionNode.Remove(); + projectDocument.Save(projectPath); + } + } } } } From c00e84dd9be5f96038a9f16be167286e80be827a Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Thu, 23 Mar 2017 12:54:07 -0700 Subject: [PATCH 134/149] Fix test issue vs. case sensitive file systems --- test/dotnet-new.Tests/GivenThatIWantANewApp.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/dotnet-new.Tests/GivenThatIWantANewApp.cs b/test/dotnet-new.Tests/GivenThatIWantANewApp.cs index 09454669b..e95ff6644 100644 --- a/test/dotnet-new.Tests/GivenThatIWantANewApp.cs +++ b/test/dotnet-new.Tests/GivenThatIWantANewApp.cs @@ -72,8 +72,8 @@ namespace Microsoft.DotNet.New.Tests } [Theory] - [InlineData("console", "RuntimeFrameworkVersion", "Microsoft.NETCore.App")] - [InlineData("classlib", "NetStandardImplicitPackageVersion", "NETStandard.Library")] + [InlineData("console", "RuntimeFrameworkVersion", "microsoft.netcore.app")] + [InlineData("classlib", "NetStandardImplicitPackageVersion", "netstandard.library")] public void NewProjectRestoresCorrectPackageVersion(string type, string propertyName, string packageName) { // These will fail when templates stop including explicit version. @@ -113,7 +113,7 @@ namespace Microsoft.DotNet.New.Tests .EnumerateDirectories() .Single(d => d.Name.StartsWith("2.0.0")); - if (packageName == "Microsoft.NETCore.App") + if (packageName == "microsoft.netcore.app") { return sharedFxDir.Name; } @@ -125,7 +125,7 @@ namespace Microsoft.DotNet.New.Tests var context = reader.Read(stream); var dependency = context .RuntimeLibraries - .Single(library => library.Name.Equals(packageName, StringComparison.OrdinalIgnoreCase)); + .Single(library => library.Name == packageName); return dependency.Version; } From 15f171a5d77304fb5b11643c835b949fb90882b3 Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Thu, 23 Mar 2017 13:16:54 -0700 Subject: [PATCH 135/149] Add back extra test check on value of explicit version --- test/dotnet-new.Tests/GivenThatIWantANewApp.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/dotnet-new.Tests/GivenThatIWantANewApp.cs b/test/dotnet-new.Tests/GivenThatIWantANewApp.cs index e95ff6644..ac0610240 100644 --- a/test/dotnet-new.Tests/GivenThatIWantANewApp.cs +++ b/test/dotnet-new.Tests/GivenThatIWantANewApp.cs @@ -144,6 +144,8 @@ namespace Microsoft.DotNet.New.Tests .SingleOrDefault(); explicitVersionNode.Should().NotBeNull(); + explicitVersionNode.Value.Should().Be(expectedVersion); + if (deleteExplicitVersion) { explicitVersionNode.Remove(); From 815a33415e1515099b3e0059cbb1bc82614138a3 Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Thu, 23 Mar 2017 14:21:04 -0700 Subject: [PATCH 136/149] Unpin stage0 --- run-build.ps1 | 4 ++-- run-build.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/run-build.ps1 b/run-build.ps1 index c02a924cf..ea77e8983 100644 --- a/run-build.ps1 +++ b/run-build.ps1 @@ -101,8 +101,8 @@ if ($LastExitCode -ne 0) # install the post-PJnistic stage0 $dotnetInstallPath = Join-Path $toolsLocalPath "dotnet-install.ps1" -Write-Host "$dotnetInstallPath -Channel ""master"" -Version ""2.0.0-preview1-005390"" -InstallDir $env:DOTNET_INSTALL_DIR -Architecture ""$Architecture""" -Invoke-Expression "$dotnetInstallPath -Channel ""master"" -Version ""2.0.0-preview1-005390"" -InstallDir $env:DOTNET_INSTALL_DIR -Architecture ""$Architecture""" +Write-Host "$dotnetInstallPath -Channel ""master"" -InstallDir $env:DOTNET_INSTALL_DIR -Architecture ""$Architecture""" +Invoke-Expression "$dotnetInstallPath -Channel ""master"" -InstallDir $env:DOTNET_INSTALL_DIR -Architecture ""$Architecture""" if ($LastExitCode -ne 0) { Write-Output "The .NET CLI installation failed with exit code $LastExitCode" diff --git a/run-build.sh b/run-build.sh index 684fb8049..17c515902 100755 --- a/run-build.sh +++ b/run-build.sh @@ -167,8 +167,8 @@ if [ $? != 0 ]; then fi # now execute the script -echo "installing CLI: $dotnetInstallPath --channel \"master\" --version \"2.0.0-preview1-005165\" --install-dir $DOTNET_INSTALL_DIR --architecture \"$ARCHITECTURE\" $LINUX_PORTABLE_INSTALL_ARGS" -$dotnetInstallPath --channel "master" --version "2.0.0-preview1-005390" --install-dir $DOTNET_INSTALL_DIR --architecture "$ARCHITECTURE" $LINUX_PORTABLE_INSTALL_ARGS +echo "installing CLI: $dotnetInstallPath --channel \"master\" --install-dir $DOTNET_INSTALL_DIR --architecture \"$ARCHITECTURE\" $LINUX_PORTABLE_INSTALL_ARGS" +$dotnetInstallPath --channel "master" --install-dir $DOTNET_INSTALL_DIR --architecture "$ARCHITECTURE" $LINUX_PORTABLE_INSTALL_ARGS if [ $? != 0 ]; then echo "run-build: Error: Boot-strapping post-PJ stage0 with exit code $?." >&2 exit $? From 8b7d1c6e2a0cfa5ceab965a6086abc9a3b77920b Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Thu, 23 Mar 2017 13:18:22 -0700 Subject: [PATCH 137/149] Target update-dependencies to netstandard2.0 Previously, this was 1.0 app. Since stage0 no longer contains a 1.0.X shared framework, it would not run. Move to 2.0.0 (instead of 1.1.X since the 1.1.X shared framework will stop being in stage0 soon as well). --- build_projects/update-dependencies/update-dependencies.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_projects/update-dependencies/update-dependencies.csproj b/build_projects/update-dependencies/update-dependencies.csproj index 257638981..3b484b11f 100644 --- a/build_projects/update-dependencies/update-dependencies.csproj +++ b/build_projects/update-dependencies/update-dependencies.csproj @@ -4,7 +4,7 @@ Updates the repos dependencies Exe - netcoreapp1.0 + $(CliTargetFramework) @@ -12,7 +12,7 @@ - + From 438d9de6ce9cdc0fb35dde719a5a0a88d4a61469 Mon Sep 17 00:00:00 2001 From: dotnet-bot Date: Thu, 23 Mar 2017 23:58:21 +0000 Subject: [PATCH 138/149] Update CoreSetup to beta-001834 --- build/DependencyVersions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/DependencyVersions.props b/build/DependencyVersions.props index a508a8c63..c111a0e42 100644 --- a/build/DependencyVersions.props +++ b/build/DependencyVersions.props @@ -1,7 +1,7 @@ - 2.0.0-beta-001791-00 + 2.0.0-beta-001834-00 15.2.0-preview-000047-02 2.0.0-rc4-61325-08 2.0.0-alpha-20170323-1 From abfb877c5d7976282579193f7d6080c8005975fa Mon Sep 17 00:00:00 2001 From: jonsequitur Date: Thu, 23 Mar 2017 16:40:43 -0700 Subject: [PATCH 139/149] update Microsoft.DotNet.Cli.CommandLineParser version for more selective option splitting --- src/dotnet/commands/dotnet-complete/ParseCommand.cs | 7 +++++++ src/dotnet/dotnet.csproj | 2 +- test/dotnet-msbuild.Tests/GivenDotnetBuildInvocation.cs | 1 + test/dotnet.Tests/dotnet.Tests.csproj | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/dotnet/commands/dotnet-complete/ParseCommand.cs b/src/dotnet/commands/dotnet-complete/ParseCommand.cs index 90972e119..4a09e0468 100644 --- a/src/dotnet/commands/dotnet-complete/ParseCommand.cs +++ b/src/dotnet/commands/dotnet-complete/ParseCommand.cs @@ -24,6 +24,13 @@ namespace Microsoft.DotNet.Cli Console.WriteLine(result.Diagram()); + var optionValuesToBeForwarded = result.AppliedCommand() + .OptionValuesToBeForwarded(); + if (optionValuesToBeForwarded.Any()) + { + Console.WriteLine("Option values to be forwarded: "); + Console.WriteLine(string.Join(" ", optionValuesToBeForwarded)); + } if (result.Errors.Any()) { Console.WriteLine(); diff --git a/src/dotnet/dotnet.csproj b/src/dotnet/dotnet.csproj index a8d4472d7..1af752ea6 100644 --- a/src/dotnet/dotnet.csproj +++ b/src/dotnet/dotnet.csproj @@ -40,7 +40,7 @@ - + diff --git a/test/dotnet-msbuild.Tests/GivenDotnetBuildInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetBuildInvocation.cs index 687b13f2e..259d5e257 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetBuildInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetBuildInvocation.cs @@ -15,6 +15,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [Theory] [InlineData(new string[] { }, "/t:Build")] [InlineData(new string[] { "-o", "foo" }, "/t:Build /p:OutputPath=foo")] + [InlineData(new string[] { "-p:Verbosity=diag" }, "/t:Build -p:Verbosity=diag")] [InlineData(new string[] { "--output", "foo" }, "/t:Build /p:OutputPath=foo")] [InlineData(new string[] { "-o", "foo1 foo2" }, "/t:Build \"/p:OutputPath=foo1 foo2\"")] [InlineData(new string[] { "--no-incremental" }, "/t:Rebuild")] diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index f9b8b2d07..025e06c9c 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -42,6 +42,6 @@ - + From aeed60ded1ca1c2ea81cce54add77b876101a31b Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Thu, 23 Mar 2017 17:18:04 -0700 Subject: [PATCH 140/149] Update OSX CoreCLR RID Since Microsoft.NETCore.App 2.0 will only support 10.12 and later, the RID in the runtime package has changed to osx.10.12. We need to update so we pick up crossgen from the right place. --- build/Stage0.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/Stage0.props b/build/Stage0.props index 12905e100..30dff8536 100644 --- a/build/Stage0.props +++ b/build/Stage0.props @@ -7,7 +7,7 @@ True $(Rid) win7-$(Architecture) - osx.10.10-x64 + osx.10.12-x64 rhel.7-x64 From 608c7beeecf657d39c9876333574a660a336de48 Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Thu, 23 Mar 2017 22:16:47 -0700 Subject: [PATCH 141/149] Move CI to OSX 10.12 The shared framework now depends on OSX 10.12 or later. Move our jobs forward so we can update the shared framework. --- netci.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netci.groovy b/netci.groovy index 4f60f0db8..b8b8226e9 100644 --- a/netci.groovy +++ b/netci.groovy @@ -9,7 +9,7 @@ def project = GithubProject def branch = GithubBranchName def isPR = true -def platformList = ['Linux:x64:Release', 'Debian8.2:x64:Debug', 'Ubuntu:x64:Release', 'Ubuntu16.04:x64:Debug', 'Ubuntu16.10:x64:Debug', 'OSX:x64:Release', 'Windows_NT:x64:Release', 'Windows_NT:x86:Debug', 'RHEL7.2:x64:Release', 'CentOS7.1:x64:Debug', 'Fedora24:x64:Release', 'OpenSUSE42.1:x64:Debug'] +def platformList = ['Linux:x64:Release', 'Debian8.2:x64:Debug', 'Ubuntu:x64:Release', 'Ubuntu16.04:x64:Debug', 'Ubuntu16.10:x64:Debug', 'OSX10.12:x64:Release', 'Windows_NT:x64:Release', 'Windows_NT:x86:Debug', 'RHEL7.2:x64:Release', 'CentOS7.1:x64:Debug', 'Fedora24:x64:Release', 'OpenSUSE42.1:x64:Debug'] def static getBuildJobName(def configuration, def os, def architecture) { return configuration.toLowerCase() + '_' + os.toLowerCase() + '_' + architecture.toLowerCase() From a4cb3fdf8170fb2c3234eee15d37d55ff4ebe45b Mon Sep 17 00:00:00 2001 From: dasMulli Date: Fri, 24 Mar 2017 06:44:53 +0100 Subject: [PATCH 142/149] Allow directories as project arguments to run command. --- src/dotnet/commands/dotnet-run/RunCommand.cs | 39 ++++++++++++------- .../GivenDotnetRunRunsCsProj.cs | 18 +++++++++ 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/dotnet/commands/dotnet-run/RunCommand.cs b/src/dotnet/commands/dotnet-run/RunCommand.cs index c285a72ca..240b3971f 100644 --- a/src/dotnet/commands/dotnet-run/RunCommand.cs +++ b/src/dotnet/commands/dotnet-run/RunCommand.cs @@ -134,21 +134,12 @@ namespace Microsoft.DotNet.Tools.Run { if (string.IsNullOrWhiteSpace(Project)) { - string directory = Directory.GetCurrentDirectory(); - string[] projectFiles = Directory.GetFiles(directory, "*.*proj"); - - if (projectFiles.Length == 0) - { - var project = "--project"; - - throw new GracefulException(LocalizableStrings.RunCommandExceptionNoProjects, directory, project); - } - else if (projectFiles.Length > 1) - { - throw new GracefulException(LocalizableStrings.RunCommandExceptionMultipleProjects, directory); - } - - Project = projectFiles[0]; + Project = Directory.GetCurrentDirectory(); + } + + if (Directory.Exists(Project)) + { + Project = FindSingleProjectInDirectory(Project); } if (Args == null) @@ -160,5 +151,23 @@ namespace Microsoft.DotNet.Tools.Run _args = new List(Args); } } + + private static string FindSingleProjectInDirectory(string directory) + { + string[] projectFiles = Directory.GetFiles(directory, "*.*proj"); + + if (projectFiles.Length == 0) + { + var project = "--project"; + + throw new GracefulException(LocalizableStrings.RunCommandExceptionNoProjects, directory, project); + } + else if (projectFiles.Length > 1) + { + throw new GracefulException(LocalizableStrings.RunCommandExceptionMultipleProjects, directory); + } + + return projectFiles[0]; + } } } diff --git a/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs b/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs index 466d0c650..626fc65bb 100644 --- a/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs +++ b/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs @@ -118,6 +118,24 @@ namespace Microsoft.DotNet.Cli.Run.Tests .And.HaveStdOutContaining("Hello World!"); } + [Fact] + public void ItRunsPortableAppsFromADifferentPathSpecifyingOnlyTheDirectoryWithoutBuilding() + { + var testAppName = "MSBuildTestApp"; + var testInstance = TestAssets.Get(testAppName) + .CreateInstance() + .WithSourceFiles() + .WithRestoreFiles(); + + var testProjectDirectory = testInstance.Root.FullName; + + new RunCommand() + .WithWorkingDirectory(testInstance.Root.Parent) + .ExecuteWithCapturedOutput($"--project {testProjectDirectory}") + .Should().Pass() + .And.HaveStdOutContaining("Hello World!"); + } + [Fact] public void ItRunsAppWhenRestoringToSpecificPackageDirectory() { From 5e26d0f160e615fe5b07e0892606c81143cefa88 Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Thu, 23 Mar 2017 17:25:40 -0700 Subject: [PATCH 143/149] Package bundled version props in to a VS insertion nupkg --- ...ions.targets => MSBuildExtensions.targets} | 27 ++++++++++--------- build/OutputDirectories.props | 1 + build/package/Installer.MSI.targets | 19 +++++++++++++ ...mmon.Net.Core.SDK.MSBuildExtensions.nuspec | 18 +++++++++++++ .../VS.Redist.Common.Net.Core.SDK.x64.nuspec | 2 +- .../VS.Redist.Common.Net.Core.SDK.x86.nuspec | 2 +- packaging/windows/clisdk/generatenupkg.ps1 | 6 ++--- src/redist/redist.csproj | 3 ++- 8 files changed, 59 insertions(+), 19 deletions(-) rename build/{BundledVersions.targets => MSBuildExtensions.targets} (74%) create mode 100644 packaging/windows/clisdk/VS.Redist.Common.Net.Core.SDK.MSBuildExtensions.nuspec diff --git a/build/BundledVersions.targets b/build/MSBuildExtensions.targets similarity index 74% rename from build/BundledVersions.targets rename to build/MSBuildExtensions.targets index 065eefe96..edacdf01d 100644 --- a/build/BundledVersions.targets +++ b/build/MSBuildExtensions.targets @@ -1,12 +1,17 @@ - - $(IntermediateDirectory)/GeneratedMSBuildImports - 15.0/Imports/Microsoft.Common.props/ImportBefore - Microsoft.NETCoreSdk.BundledVersions.props - + - + + + + + + + + 15.0/Imports/Microsoft.Common.props/ImportBefore + Microsoft.NETCoreSdk.BundledVersions.props + - - - diff --git a/build/OutputDirectories.props b/build/OutputDirectories.props index 467b64964..3732acaaf 100644 --- a/build/OutputDirectories.props +++ b/build/OutputDirectories.props @@ -11,5 +11,6 @@ $(IntermediateDirectory)/sharedFrameworkPublish $(RepoRoot)/artifacts/testpackages/ $(OutputDirectory)/dotnet$(ExeExtension) + $(IntermediateDirectory)/GeneratedMSBuildExtensions diff --git a/build/package/Installer.MSI.targets b/build/package/Installer.MSI.targets index cc529d24b..ab2d0b8b3 100644 --- a/build/package/Installer.MSI.targets +++ b/build/package/Installer.MSI.targets @@ -19,6 +19,9 @@ $(RepoRoot)/packaging/windows/clisdk/VS.Redist.Common.Net.Core.SDK.$(Architecture).nuspec $(InstallerOutputDirectory)/VS.Redist.Common.Net.Core.SDK.$(Architecture).$(FullNugetVersion).nupkg + + $(RepoRoot)/packaging/windows/clisdk/VS.Redist.Common.Net.Core.SDK.MSBuildExtensions.nuspec + $(InstallerOutputDirectory)/VS.Redist.Common.Net.Core.SDK.MSBuildExtensions.$(FullNugetVersion).nupkg @@ -143,6 +146,21 @@ '$(SdkInstallerNupkgFile)'" /> + + + + + diff --git a/packaging/windows/clisdk/VS.Redist.Common.Net.Core.SDK.MSBuildExtensions.nuspec b/packaging/windows/clisdk/VS.Redist.Common.Net.Core.SDK.MSBuildExtensions.nuspec new file mode 100644 index 000000000..31f49a45a --- /dev/null +++ b/packaging/windows/clisdk/VS.Redist.Common.Net.Core.SDK.MSBuildExtensions.nuspec @@ -0,0 +1,18 @@ + + + + VS.Redist.Common.Net.Core.SDK.MSBuildExtensions + 1.0.0 + VS.Redist.Common.Net.Core.SDK.MSBuildExtensions + Microsoft + Microsoft + https://www.microsoft.com/net/dotnet_library_license.htm + https://github.com/dotnet/cli + true + MSBuild extensions bundled with .NET Core SDK insertions to VS + © Microsoft Corporation. All rights reserved. + + + + + \ No newline at end of file diff --git a/packaging/windows/clisdk/VS.Redist.Common.Net.Core.SDK.x64.nuspec b/packaging/windows/clisdk/VS.Redist.Common.Net.Core.SDK.x64.nuspec index 2e0701a6d..1e5f870e8 100644 --- a/packaging/windows/clisdk/VS.Redist.Common.Net.Core.SDK.x64.nuspec +++ b/packaging/windows/clisdk/VS.Redist.Common.Net.Core.SDK.x64.nuspec @@ -13,6 +13,6 @@ © Microsoft Corporation. All rights reserved. - + \ No newline at end of file diff --git a/packaging/windows/clisdk/VS.Redist.Common.Net.Core.SDK.x86.nuspec b/packaging/windows/clisdk/VS.Redist.Common.Net.Core.SDK.x86.nuspec index aa7055af7..c9b9f73cd 100644 --- a/packaging/windows/clisdk/VS.Redist.Common.Net.Core.SDK.x86.nuspec +++ b/packaging/windows/clisdk/VS.Redist.Common.Net.Core.SDK.x86.nuspec @@ -13,6 +13,6 @@ © Microsoft Corporation. All rights reserved. - + \ No newline at end of file diff --git a/packaging/windows/clisdk/generatenupkg.ps1 b/packaging/windows/clisdk/generatenupkg.ps1 index cca52bd7f..9297775a8 100644 --- a/packaging/windows/clisdk/generatenupkg.ps1 +++ b/packaging/windows/clisdk/generatenupkg.ps1 @@ -15,7 +15,7 @@ param( $RepoRoot = Convert-Path "$PSScriptRoot\..\..\.." $NuGetDir = Join-Path $RepoRoot ".nuget" $NuGetExe = Join-Path $NuGetDir "nuget.exe" -$OutputDirectory = [System.IO.Path]::GetDirectoryName($SdkBundlePath) +$OutputDirectory = [System.IO.Path]::GetDirectoryName($NupkgFile) function DownloadNugetExe { @@ -37,10 +37,10 @@ function GenerateNupkg Write-Host 'Error nuspec not found - $NuspecFile' } - $SdkBundleName = [System.IO.Path]::GetFileName($SdkBundlePath) + $SdkBundlePath = [System.IO.Path]::GetFullPath($SdkBundlePath) $NuspecFileName = [System.IO.Path]::GetFileName($NuspecFile) $TempNuspecFile = [System.IO.Path]::Combine($OutputDirectory, $NuspecFileName) - (Get-Content $NuspecFile) -replace '\[DOTNET_BUNDLE\]', $SdkBundleName | Set-Content $TempNuspecFile + (Get-Content $NuspecFile) -replace '\[DOTNET_BUNDLE\]', $SdkBundlePath | Set-Content $TempNuspecFile & $NuGetExe pack $TempNuspecFile -Version $NugetVersion -OutputDirectory $OutputDirectory } diff --git a/src/redist/redist.csproj b/src/redist/redist.csproj index 5bf539615..21668b585 100644 --- a/src/redist/redist.csproj +++ b/src/redist/redist.csproj @@ -2,7 +2,7 @@ - + $(CliVersionPrefix) @@ -79,6 +79,7 @@ From 6d25ee1f68044a9a71d1a23138a007e869fb4bb6 Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Fri, 24 Mar 2017 11:28:22 -0700 Subject: [PATCH 144/149] Add OSX.10.12 RID to some test assets --- TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj | 4 ++-- TestAssets/TestProjects/PJTestAppSimple/project.json | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj b/TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj index 67e9b56a0..a604faff2 100644 --- a/TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj +++ b/TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj @@ -4,7 +4,7 @@ Exe netcoreapp2.0 - win7-x64;win7-x86;osx.10.10-x64;osx.10.11-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;centos.7-x64;rhel.7.2-x64;debian.8-x64;fedora.24-x64;opensuse.42.1-x64 + win7-x64;win7-x86;osx.10.12-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;centos.7-x64;rhel.7.2-x64;debian.8-x64;fedora.24-x64;opensuse.42.1-x64 $(CLI_SharedFrameworkVersion) netcoreapp2.0 @@ -13,4 +13,4 @@ - \ No newline at end of file + diff --git a/TestAssets/TestProjects/PJTestAppSimple/project.json b/TestAssets/TestProjects/PJTestAppSimple/project.json index f94096150..1797b91c4 100755 --- a/TestAssets/TestProjects/PJTestAppSimple/project.json +++ b/TestAssets/TestProjects/PJTestAppSimple/project.json @@ -14,6 +14,7 @@ "win7-x86": {}, "osx.10.10-x64": {}, "osx.10.11-x64": {}, + "osx.10.12-x64": {}, "ubuntu.14.04-x64": {}, "ubuntu.16.04-x64": {}, "centos.7-x64": {}, @@ -22,4 +23,4 @@ "fedora.23-x64": {}, "opensuse.13.2-x64": {} } -} \ No newline at end of file +} From 7bfc51f2b153334d9e94636d114862dcbbc2230f Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 24 Mar 2017 14:22:34 -0500 Subject: [PATCH 145/149] Format BundledRuntimes.props to use consistent whitespace. --- build/BundledRuntimes.props | 193 ++++++++++++++++++------------------ 1 file changed, 96 insertions(+), 97 deletions(-) diff --git a/build/BundledRuntimes.props b/build/BundledRuntimes.props index a7d91de3d..c47b3caa4 100644 --- a/build/BundledRuntimes.props +++ b/build/BundledRuntimes.props @@ -1,117 +1,116 @@ - + + + dotnet-host-$(ProductMonikerRid).$(SharedHostVersion)$(InstallerExtension) + $(PackagesDirectory)/$(DownloadedSharedHostInstallerFileName) - - dotnet-host-$(ProductMonikerRid).$(SharedHostVersion)$(InstallerExtension) - $(PackagesDirectory)/$(DownloadedSharedHostInstallerFileName) + dotnet-hostfxr-$(ProductMonikerRid).$(HostFxrVersion)$(InstallerExtension) + $(PackagesDirectory)/$(DownloadedHostFxrInstallerFileName) - dotnet-hostfxr-$(ProductMonikerRid).$(HostFxrVersion)$(InstallerExtension) - $(PackagesDirectory)/$(DownloadedHostFxrInstallerFileName) + dotnet-sharedframework-$(ProductMonikerRid).$(SharedFrameworkVersion)$(InstallerExtension) + $(PackagesDirectory)/$(DownloadedSharedFrameworkInstallerFileName) - dotnet-sharedframework-$(ProductMonikerRid).$(SharedFrameworkVersion)$(InstallerExtension) - $(PackagesDirectory)/$(DownloadedSharedFrameworkInstallerFileName) + dotnet-$(ProductMonikerRid).$(SharedFrameworkVersion)$(ArchiveExtension) + - dotnet-$(ProductMonikerRid).$(SharedFrameworkVersion)$(ArchiveExtension) - + + + release/1.1.0 + 1.1.1 + 1.1.0 + 1.1.0 - - - release/1.1.0 - 1.1.1 - 1.1.0 - 1.1.0 + + dotnet-host-$(ProductMonikerRid).$(AdditionalSharedHostVersion)$(InstallerExtension) + $(PackagesDirectory)/$(AdditionalDownloadedSharedHostInstallerFileName) - - dotnet-host-$(ProductMonikerRid).$(AdditionalSharedHostVersion)$(InstallerExtension) - $(PackagesDirectory)/$(AdditionalDownloadedSharedHostInstallerFileName) + dotnet-hostfxr-$(ProductMonikerRid).$(AdditionalHostFxrVersion)$(InstallerExtension) + $(PackagesDirectory)/$(AdditionalDownloadedHostFxrInstallerFileName) - dotnet-hostfxr-$(ProductMonikerRid).$(AdditionalHostFxrVersion)$(InstallerExtension) - $(PackagesDirectory)/$(AdditionalDownloadedHostFxrInstallerFileName) + dotnet-sharedframework-$(ProductMonikerRid).$(AdditionalSharedFrameworkVersion)$(InstallerExtension) + $(PackagesDirectory)/$(AdditionalDownloadedSharedFrameworkInstallerFileName) - dotnet-sharedframework-$(ProductMonikerRid).$(AdditionalSharedFrameworkVersion)$(InstallerExtension) - $(PackagesDirectory)/$(AdditionalDownloadedSharedFrameworkInstallerFileName) + dotnet-$(ProductMonikerRid).$(AdditionalSharedFrameworkVersion)$(ArchiveExtension) + - dotnet-$(ProductMonikerRid).$(AdditionalSharedFrameworkVersion)$(ArchiveExtension) - + + master + https://dotnetcli.azureedge.net/dotnet/ + $(CoreSetupBlobRootUrl)$(CoreSetupChannel) + $(CoreSetupBlobRootUrlWithChannel)/Binaries/$(SharedFrameworkVersion) + $(CoreSetupBlobRootUrlWithChannel)/Installers + $(IntermediateDirectory)/coreSetupDownload/$(SharedFrameworkVersion) + $(CoreSetupDownloadDirectory)/combinedSharedHostAndFrameworkArchive + - - master - https://dotnetcli.azureedge.net/dotnet/ - $(CoreSetupBlobRootUrl)$(CoreSetupChannel) - $(CoreSetupBlobRootUrlWithChannel)/Binaries/$(SharedFrameworkVersion) - $(CoreSetupBlobRootUrlWithChannel)/Installers - $(IntermediateDirectory)/coreSetupDownload/$(SharedFrameworkVersion) - $(CoreSetupDownloadDirectory)/combinedSharedHostAndFrameworkArchive - + + <_DownloadAndExtractItem Include="CombinedSharedHostAndFrameworkArchive" + Condition="!Exists('$(CombinedSharedHostAndFrameworkArchive)')"> + $(SharedFrameworkArchiveBlobRootUrl)/$(CombinedFrameworkHostCompressedFileName) + $(CombinedSharedHostAndFrameworkArchive) + $(SharedFrameworkPublishDirectory) + - - <_DownloadAndExtractItem Include="CombinedSharedHostAndFrameworkArchive" - Condition="!Exists('$(CombinedSharedHostAndFrameworkArchive)')"> - $(SharedFrameworkArchiveBlobRootUrl)/$(CombinedFrameworkHostCompressedFileName) - $(CombinedSharedHostAndFrameworkArchive) - $(SharedFrameworkPublishDirectory) - + <_DownloadAndExtractItem Include="DownloadedSharedFrameworkInstallerFile" + Condition="'$(SkipBuildingInstallers)' != 'true' And !Exists('$(DownloadedSharedFrameworkInstallerFile)') And '$(InstallerExtension)' != ''"> + $(CoreSetupInstallerBlobRootUrl)/$(SharedFrameworkVersion)/$(DownloadedSharedFrameworkInstallerFileName) + $(DownloadedSharedFrameworkInstallerFile) + + - <_DownloadAndExtractItem Include="DownloadedSharedFrameworkInstallerFile" - Condition="'$(SkipBuildingInstallers)' != 'true' And !Exists('$(DownloadedSharedFrameworkInstallerFile)') And '$(InstallerExtension)' != ''"> - $(CoreSetupInstallerBlobRootUrl)/$(SharedFrameworkVersion)/$(DownloadedSharedFrameworkInstallerFileName) - $(DownloadedSharedFrameworkInstallerFile) - - + <_DownloadAndExtractItem Include="DownloadedSharedHostInstallerFile" + Condition="'$(SkipBuildingInstallers)' != 'true' And !Exists('$(DownloadedSharedHostInstallerFile)') And '$(InstallerExtension)' != ''"> + $(CoreSetupInstallerBlobRootUrl)/$(SharedHostVersion)/$(DownloadedSharedHostInstallerFileName) + $(DownloadedSharedHostInstallerFile) + + - <_DownloadAndExtractItem Include="DownloadedSharedHostInstallerFile" - Condition="'$(SkipBuildingInstallers)' != 'true' And !Exists('$(DownloadedSharedHostInstallerFile)') And '$(InstallerExtension)' != ''"> - $(CoreSetupInstallerBlobRootUrl)/$(SharedHostVersion)/$(DownloadedSharedHostInstallerFileName) - $(DownloadedSharedHostInstallerFile) - - + <_DownloadAndExtractItem Include="DownloadedHostFxrInstallerFile" + Condition="'$(SkipBuildingInstallers)' != 'true' And !Exists('$(DownloadedHostFxrInstallerFile)') And '$(InstallerExtension)' != ''"> + $(CoreSetupInstallerBlobRootUrl)/$(HostFxrVersion)/$(DownloadedHostFxrInstallerFileName) + $(DownloadedHostFxrInstallerFile) + + + - <_DownloadAndExtractItem Include="DownloadedHostFxrInstallerFile" - Condition="'$(SkipBuildingInstallers)' != 'true' And !Exists('$(DownloadedHostFxrInstallerFile)') And '$(InstallerExtension)' != ''"> - $(CoreSetupInstallerBlobRootUrl)/$(HostFxrVersion)/$(DownloadedHostFxrInstallerFileName) - $(DownloadedHostFxrInstallerFile) - - - + + + $(CoreSetupBlobRootUrl)$(AdditionalCoreSetupChannel) + $(AdditionalCoreSetupBlobRootUrlWithChannel)/Binaries/$(AdditionalSharedFrameworkVersion) + $(AdditionalCoreSetupBlobRootUrlWithChannel)/Installers + $(IntermediateDirectory)/coreSetupDownload/$(AdditionalSharedFrameworkVersion) + $(AdditionalCoreSetupDownloadDirectory)/combinedSharedHostAndFrameworkArchive + - - - $(CoreSetupBlobRootUrl)$(AdditionalCoreSetupChannel) - $(AdditionalCoreSetupBlobRootUrlWithChannel)/Binaries/$(AdditionalSharedFrameworkVersion) - $(AdditionalCoreSetupBlobRootUrlWithChannel)/Installers - $(IntermediateDirectory)/coreSetupDownload/$(AdditionalSharedFrameworkVersion) - $(AdditionalCoreSetupDownloadDirectory)/combinedSharedHostAndFrameworkArchive - + + <_DownloadAndExtractItem Include="AdditionalCombinedSharedHostAndFrameworkArchive" + Condition="!Exists('$(AdditionalCombinedSharedHostAndFrameworkArchive)')"> + $(AdditionalSharedFrameworkArchiveBlobRootUrl)/$(AdditionalCombinedFrameworkHostCompressedFileName) + $(AdditionalCombinedSharedHostAndFrameworkArchive) + $(SharedFrameworkPublishDirectory) + + False + - - <_DownloadAndExtractItem Include="AdditionalCombinedSharedHostAndFrameworkArchive" - Condition="!Exists('$(AdditionalCombinedSharedHostAndFrameworkArchive)')"> - $(AdditionalSharedFrameworkArchiveBlobRootUrl)/$(AdditionalCombinedFrameworkHostCompressedFileName) - $(AdditionalCombinedSharedHostAndFrameworkArchive) - $(SharedFrameworkPublishDirectory) - - False - + <_DownloadAndExtractItem Include="AdditionalDownloadedSharedFrameworkInstallerFile" + Condition="'$(SkipBuildingInstallers)' != 'true' And !Exists('$(AdditionalDownloadedSharedFrameworkInstallerFile)') And '$(InstallerExtension)' != ''"> + $(AdditionalCoreSetupInstallerBlobRootUrl)/$(AdditionalSharedFrameworkVersion)/$(AdditionalDownloadedSharedFrameworkInstallerFileName) + $(AdditionalDownloadedSharedFrameworkInstallerFile) + + - <_DownloadAndExtractItem Include="AdditionalDownloadedSharedFrameworkInstallerFile" - Condition="'$(SkipBuildingInstallers)' != 'true' And !Exists('$(AdditionalDownloadedSharedFrameworkInstallerFile)') And '$(InstallerExtension)' != ''"> - $(AdditionalCoreSetupInstallerBlobRootUrl)/$(AdditionalSharedFrameworkVersion)/$(AdditionalDownloadedSharedFrameworkInstallerFileName) - $(AdditionalDownloadedSharedFrameworkInstallerFile) - - + <_DownloadAndExtractItem Include="AdditionalDownloadedSharedHostInstallerFile" + Condition="'$(SkipBuildingInstallers)' != 'true' And !Exists('$(AdditionalDownloadedSharedHostInstallerFile)') And '$(InstallerExtension)' != ''"> + $(AdditionalCoreSetupInstallerBlobRootUrl)/$(AdditionalSharedHostVersion)/$(AdditionalDownloadedSharedHostInstallerFileName) + $(AdditionalDownloadedSharedHostInstallerFile) + + - <_DownloadAndExtractItem Include="AdditionalDownloadedSharedHostInstallerFile" - Condition="'$(SkipBuildingInstallers)' != 'true' And !Exists('$(AdditionalDownloadedSharedHostInstallerFile)') And '$(InstallerExtension)' != ''"> - $(AdditionalCoreSetupInstallerBlobRootUrl)/$(AdditionalSharedHostVersion)/$(AdditionalDownloadedSharedHostInstallerFileName) - $(AdditionalDownloadedSharedHostInstallerFile) - - - - <_DownloadAndExtractItem Include="AdditionalDownloadedHostFxrInstallerFile" - Condition="'$(SkipBuildingInstallers)' != 'true' And !Exists('$(AdditionalDownloadedHostFxrInstallerFile)') And '$(InstallerExtension)' != ''"> - $(AdditionalCoreSetupInstallerBlobRootUrl)/$(AdditionalHostFxrVersion)/$(AdditionalDownloadedHostFxrInstallerFileName) - $(AdditionalDownloadedHostFxrInstallerFile) - - - + <_DownloadAndExtractItem Include="AdditionalDownloadedHostFxrInstallerFile" + Condition="'$(SkipBuildingInstallers)' != 'true' And !Exists('$(AdditionalDownloadedHostFxrInstallerFile)') And '$(InstallerExtension)' != ''"> + $(AdditionalCoreSetupInstallerBlobRootUrl)/$(AdditionalHostFxrVersion)/$(AdditionalDownloadedHostFxrInstallerFileName) + $(AdditionalDownloadedHostFxrInstallerFile) + + + From c3a6999392bbab91593bdb1eb90b5691ce421689 Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Fri, 24 Mar 2017 13:14:07 -0700 Subject: [PATCH 146/149] Skip flaky test --- test/dotnet.Tests/PackagedCommandTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dotnet.Tests/PackagedCommandTests.cs b/test/dotnet.Tests/PackagedCommandTests.cs index 4e9a75ba1..42370e312 100644 --- a/test/dotnet.Tests/PackagedCommandTests.cs +++ b/test/dotnet.Tests/PackagedCommandTests.cs @@ -287,7 +287,7 @@ namespace Microsoft.DotNet.Tests result.Should().Fail(); } - [Fact] + [Fact(Skip = "https://github.com/dotnet/cli/issues/6144")] public void WhenToolAssetsFileIsInUseThenCLIRetriesLaunchingTheCommandForAtLeastOneSecond() { var testInstance = TestAssets.Get("AppWithToolDependency") From ac0fa56039ec2c0d0a71a35d7a77fc99cfa018d4 Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Fri, 24 Mar 2017 13:29:07 -0700 Subject: [PATCH 147/149] Remove Fedora24 from CI for now --- netci.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netci.groovy b/netci.groovy index b8b8226e9..bb47c2d8a 100644 --- a/netci.groovy +++ b/netci.groovy @@ -9,7 +9,7 @@ def project = GithubProject def branch = GithubBranchName def isPR = true -def platformList = ['Linux:x64:Release', 'Debian8.2:x64:Debug', 'Ubuntu:x64:Release', 'Ubuntu16.04:x64:Debug', 'Ubuntu16.10:x64:Debug', 'OSX10.12:x64:Release', 'Windows_NT:x64:Release', 'Windows_NT:x86:Debug', 'RHEL7.2:x64:Release', 'CentOS7.1:x64:Debug', 'Fedora24:x64:Release', 'OpenSUSE42.1:x64:Debug'] +def platformList = ['Linux:x64:Release', 'Debian8.2:x64:Debug', 'Ubuntu:x64:Release', 'Ubuntu16.04:x64:Debug', 'Ubuntu16.10:x64:Debug', 'OSX10.12:x64:Release', 'Windows_NT:x64:Release', 'Windows_NT:x86:Debug', 'RHEL7.2:x64:Release', 'CentOS7.1:x64:Debug', 'OpenSUSE42.1:x64:Debug'] def static getBuildJobName(def configuration, def os, def architecture) { return configuration.toLowerCase() + '_' + os.toLowerCase() + '_' + architecture.toLowerCase() From dff66c1acb11f1b2748246e45abf69b801b417e5 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 24 Mar 2017 16:11:29 -0500 Subject: [PATCH 148/149] Update the .sln file to contain all the build logic in an organized way. --- Microsoft.DotNet.Cli.sln | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Microsoft.DotNet.Cli.sln b/Microsoft.DotNet.Cli.sln index fa47e7ccf..073ed9822 100644 --- a/Microsoft.DotNet.Cli.sln +++ b/Microsoft.DotNet.Cli.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26228.0 +VisualStudioVersion = 15.0.26228.9 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{ED2FE3E2-F7E7-4389-8231-B65123F2076F}" EndProject @@ -27,12 +27,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{89905EC4 build\BranchInfo.props = build\BranchInfo.props build\Branding.props = build\Branding.props build\BuildDefaults.props = build\BuildDefaults.props + build\BuildInfo.targets = build\BuildInfo.targets build\BundledRuntimes.props = build\BundledRuntimes.props build\BundledSdks.proj = build\BundledSdks.proj build\BundledSdks.props = build\BundledSdks.props build\BundledTemplates.proj = build\BundledTemplates.proj build\BundledTemplates.props = build\BundledTemplates.props build\BundledTools.props = build\BundledTools.props + build\BundledVersions.targets = build\BundledVersions.targets build\Compile.targets = build\Compile.targets build\CrossGen.props = build\CrossGen.props build\DependencyVersions.props = build\DependencyVersions.props @@ -43,6 +45,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{89905EC4 build\InitRepo.targets = build\InitRepo.targets build\InputDirectories.props = build\InputDirectories.props build\InstallerInfo.props = build\InstallerInfo.props + build\Microsoft.DotNet.Cli.tasks = build\Microsoft.DotNet.Cli.tasks build\MSBuildExtensions.props = build\MSBuildExtensions.props build\OutputDirectories.props = build\OutputDirectories.props build\Package.targets = build\Package.targets @@ -50,9 +53,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{89905EC4 build\ProjectsToPublish.props = build\ProjectsToPublish.props build\Publish.targets = build\Publish.targets build\Run.targets = build\Run.targets + build\sdks\sdks.csproj = build\sdks\sdks.csproj build\Signing.proj = build\Signing.proj build\Stage0.props = build\Stage0.props - build\tasks = build\tasks build\Test.targets = build\Test.targets build\Version.props = build\Version.props build\VersionBadge.props = build\VersionBadge.props @@ -209,6 +212,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Cli.Sln.In EndProject Project("{13B669BE-BB05-4DDF-9536-439F39A36129}") = "dotnet-cache.Tests", "test\dotnet-cache.Tests\dotnet-cache.Tests.csproj", "{CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sdk", "sdk", "{3275D006-54C8-4C64-A537-B9941C5D2F0C}" + ProjectSection(SolutionItems) = preProject + build\sdks\sdks.csproj = build\sdks\sdks.csproj + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "templates", "templates", "{DE4D1AEB-871B-4E7C-945A-453F9A490C06}" + ProjectSection(SolutionItems) = preProject + build\templates\templates.csproj = build\templates\templates.csproj + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1503,7 +1516,12 @@ Global EndGlobalSection GlobalSection(NestedProjects) = preSolution {1AB5B24B-B317-4142-A5D1-A6E84F15BA34} = {ADA7052B-884B-4776-8B8D-D04191D0AA70} + {FD7D515A-D10F-4F49-B8AE-21CF7ED071AE} = {89905EC4-BC0F-443B-8ADF-691321F10108} + {8E3354BD-827F-41B7-9EE6-6BE1F1EDD8E9} = {89905EC4-BC0F-443B-8ADF-691321F10108} + {FF498306-2DE2-47F6-8C35-3CF0589CF2B8} = {89905EC4-BC0F-443B-8ADF-691321F10108} + {27B12960-ABB0-4903-9C60-5E9157E659C8} = {89905EC4-BC0F-443B-8ADF-691321F10108} {8A2FA2D8-0DA1-4814-B5C1-2ECEAA613EB1} = {88278B81-7649-45DC-8A6A-D3A645C5AFC3} + {2BDC1BC2-867E-47C0-BAD0-ADE897F07F78} = {89905EC4-BC0F-443B-8ADF-691321F10108} {48A62BA4-D798-46A2-AB49-8A8471CF8165} = {1AB5B24B-B317-4142-A5D1-A6E84F15BA34} {7C3D62C6-1D71-4C45-872F-7583F2AB304A} = {1AB5B24B-B317-4142-A5D1-A6E84F15BA34} {79B4932C-3D57-494B-95AF-E5624F9D2F01} = {1AB5B24B-B317-4142-A5D1-A6E84F15BA34} @@ -1558,5 +1576,7 @@ Global {C98C7C2E-2C29-4A40-958C-60561ED77791} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} {56F1E090-B80F-4BDF-8991-4B0F9B5B8C9A} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} {CACA427D-5A71-45E6-88DC-3E2DB6C4D52D} = {FF498306-2DE2-47F6-8C35-3CF0589CF2B8} + {3275D006-54C8-4C64-A537-B9941C5D2F0C} = {89905EC4-BC0F-443B-8ADF-691321F10108} + {DE4D1AEB-871B-4E7C-945A-453F9A490C06} = {89905EC4-BC0F-443B-8ADF-691321F10108} EndGlobalSection EndGlobal From a97b572e49a31747cddd3892086311abdc02d6bb Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 24 Mar 2017 15:07:54 -0500 Subject: [PATCH 149/149] Use the portable `linux-x64` runtime when building on Linux. --- build/BuildDefaults.props | 1 + build/BuildInfo.targets | 3 +++ build/BundledRuntimes.props | 6 +++++- .../dotnet-cli-build/GetCurrentRuntimeInformation.cs | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/build/BuildDefaults.props b/build/BuildDefaults.props index 463e421fc..c78a5c0d9 100644 --- a/build/BuildDefaults.props +++ b/build/BuildDefaults.props @@ -7,5 +7,6 @@ false true false + true diff --git a/build/BuildInfo.targets b/build/BuildInfo.targets index 6df905670..6972a864e 100644 --- a/build/BuildInfo.targets +++ b/build/BuildInfo.targets @@ -5,12 +5,14 @@ + $(HostRid) x64 $(HostOSName) + $(HostOSPlatform) <Project ToolsVersion="15.0"> @@ -18,6 +20,7 @@ <Rid>$(Rid)</Rid> <Architecture>$(Architecture)</Architecture> <OSName>$(OSName)</OSName> + <OSPlatform>$(OSPlatform)</OSPlatform> </PropertyGroup> </Project> diff --git a/build/BundledRuntimes.props b/build/BundledRuntimes.props index c47b3caa4..7122b7c8f 100644 --- a/build/BundledRuntimes.props +++ b/build/BundledRuntimes.props @@ -10,7 +10,11 @@ dotnet-sharedframework-$(ProductMonikerRid).$(SharedFrameworkVersion)$(InstallerExtension) $(PackagesDirectory)/$(DownloadedSharedFrameworkInstallerFileName) - dotnet-$(ProductMonikerRid).$(SharedFrameworkVersion)$(ArchiveExtension) + + $(ProductMonikerRid) + linux-x64 + dotnet-$(SharedFrameworkRid).$(SharedFrameworkVersion)$(ArchiveExtension) diff --git a/build_projects/dotnet-cli-build/GetCurrentRuntimeInformation.cs b/build_projects/dotnet-cli-build/GetCurrentRuntimeInformation.cs index 352a225cf..7506491f2 100644 --- a/build_projects/dotnet-cli-build/GetCurrentRuntimeInformation.cs +++ b/build_projects/dotnet-cli-build/GetCurrentRuntimeInformation.cs @@ -16,10 +16,14 @@ namespace Microsoft.DotNet.Cli.Build [Output] public string OSName { get; set; } + [Output] + public string OSPlatform { get; set; } + public override bool Execute() { Rid = RuntimeEnvironment.GetRuntimeIdentifier(); OSName = GetOSShortName(); + OSPlatform = RuntimeEnvironment.OperatingSystemPlatform.ToString().ToLower(); return true; }