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()