From a3f536c2488eea7161bf496c9691a13bdd498885 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Fri, 10 Mar 2017 16:43:44 -0800 Subject: [PATCH 1/2] 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 2/2] 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 @@ - +