This commit is contained in:
Jon Sequeira 2017-03-08 16:02:24 -08:00
parent 30480fa189
commit fd6f7e48b5
5 changed files with 24 additions and 13 deletions

View file

@ -2,13 +2,23 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System; using System;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.CommandLine;
namespace Microsoft.DotNet.Cli 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 class ParseResultExtensions
{ {
public static void ShowHelp(this ParseResult parseResult) => public static void ShowHelp(this ParseResult parseResult) =>
Console.WriteLine(parseResult.Command().HelpView()); Console.WriteLine(parseResult.Command().HelpView());
} }
} }

View file

@ -19,10 +19,10 @@ namespace Microsoft.DotNet.Cli
DebugHelper.HandleDebugSwitch(ref args); DebugHelper.HandleDebugSwitch(ref args);
// get the parser for the current subcommand // get the parser for the current subcommand
var parser = Parser.Instance["dotnet"]["complete"]; var parser = Parser.Instance;
// parse the arguments // parse the arguments
var result = parser.Parse(args); var result = parser.ParseFrom("dotnet complete", args);
var complete = result["complete"]; var complete = result["complete"];

View file

@ -12,10 +12,10 @@ namespace Microsoft.DotNet.Cli
Create.Command( Create.Command(
"complete", "", "complete", "",
Accept.ExactlyOneArgument Accept.ExactlyOneArgument
.With(name: "path") .With(name: "path"),
.MaterializeAs(o => int.Parse(o.Arguments.Single())),
Create.Option("--position", "", Create.Option("--position", "",
Accept.ExactlyOneArgument Accept.ExactlyOneArgument
.With(name: "command"))); .With(name: "command")
.MaterializeAs(o => int.Parse(o.Arguments.Single()))));
} }
} }

View file

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.MSBuild; using Microsoft.DotNet.Tools.MSBuild;
@ -22,9 +23,9 @@ namespace Microsoft.DotNet.Tools.Restore
{ {
DebugHelper.HandleDebugSwitch(ref args); 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()); Reporter.Verbose.WriteLine(result.Diagram());

View file

@ -22,9 +22,9 @@ namespace Microsoft.DotNet.Tests.ParserTests
[Fact] [Fact]
public void RestoreCapturesArgumentsToForwardToMSBuildWhenTargetIsSpecified() 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()); output.WriteLine(result.Diagram());
@ -37,9 +37,9 @@ namespace Microsoft.DotNet.Tests.ParserTests
[Fact] [Fact]
public void RestoreCapturesArgumentsToForwardToMSBuildWhenTargetIsNotSpecified() 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()); output.WriteLine(result.Diagram());