don't split on : or = in restore command parse

This commit is contained in:
Jon Sequeira 2017-03-07 11:28:35 -08:00
parent c176b5953f
commit 1ed5b420a9
10 changed files with 80 additions and 55 deletions

View file

@ -16,6 +16,8 @@
<TemplateEngineTemplate2_0Version>1.0.0-beta1-20170209-117</TemplateEngineTemplate2_0Version> <TemplateEngineTemplate2_0Version>1.0.0-beta1-20170209-117</TemplateEngineTemplate2_0Version>
<PlatformAbstractionsVersion>1.0.3</PlatformAbstractionsVersion> <PlatformAbstractionsVersion>1.0.3</PlatformAbstractionsVersion>
<DependencyModelVersion>1.0.3</DependencyModelVersion> <DependencyModelVersion>1.0.3</DependencyModelVersion>
<CliCommandLineParserVersion>0.1.0-alpha-74</CliCommandLineParserVersion>
</PropertyGroup> </PropertyGroup>
<!-- infrastructure and test only dependencies --> <!-- infrastructure and test only dependencies -->

View file

@ -1,7 +1,7 @@
# PowerShell parameter completion shim for the dotnet CLI # PowerShell parameter completion shim for the dotnet CLI
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock { Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition) 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', $_) [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
} }
} }

View file

@ -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())));
}
}

View file

@ -80,7 +80,7 @@ namespace Microsoft.DotNet.Cli
UseShellExecute = false UseShellExecute = false
}; };
Reporter.Verbose.WriteLine($"[Forwarding] {processInfo.FileName} {processInfo.Arguments}"); Reporter.Output.WriteLine($"[Forwarding] {processInfo.FileName} {processInfo.Arguments}");
if (_environmentVariables != null) if (_environmentVariables != null)
{ {

View file

@ -8,32 +8,49 @@ namespace Microsoft.DotNet.Cli
internal static class BuildCommandParser internal static class BuildCommandParser
{ {
public static Command Build() => public static Command Build() =>
Create.Command("build", Create.Command(
".NET Builder", "build",
CommonOptions.HelpOption(), ".NET Builder",
Create.Option("-o|--output", Accept.ZeroOrOneArgument
"Output directory in which to place built artifacts.", .ForwardAs("{0}"),
Accept.ExactlyOneArgument CommonOptions.HelpOption(),
.With(name: "OUTPUT_DIR")), Create.Option(
Create.Option("-f|--framework", "-o|--output",
"Target framework to build for. The target framework has to be specified in the project file.", "Output directory in which to place built artifacts.",
Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile)), Accept.ExactlyOneArgument
Create.Option("-r|--runtime", .With(name: "OUTPUT_DIR")
"Target runtime to build for. The default is to build a portable application.", .ForwardAs("/p:OutputPath={0}")),
Accept.AnyOneOf(Suggest.RunTimesFromProjectFile)), Create.Option(
Create.Option("-c|--configuration", "-f|--framework",
"Configuration to use for building the project. Default for most projects is \"Debug\".", "Target framework to build for. The target framework has to be specified in the project file.",
Accept.ExactlyOneArgument Accept.AnyOneOf(Suggest.TargetFrameworksFromProjectFile)
.With(name: "CONFIGURATION") .ForwardAs("/p:TargetFramework={0}")),
.WithSuggestionsFrom("DEBUG", "RELEASE")), Create.Option(
Create.Option("--version-suffix", "-r|--runtime",
"Defines the value for the $(VersionSuffix) property in the project", "Target runtime to build for. The default is to build a portable application.",
Accept.ExactlyOneArgument Accept.AnyOneOf(Suggest.RunTimesFromProjectFile)
.With(name: "VERSION_SUFFIX")), .ForwardAs("/p:RuntimeIdentifier={0}")),
Create.Option("--no-incremental", Create.Option(
"Disables incremental build."), "-c|--configuration",
Create.Option("--no-dependencies", "Configuration to use for building the project. Default for most projects is \"Debug\".",
"Set this flag to ignore project-to-project references and only build the root project"), Accept.ExactlyOneArgument
CommonOptions.VerbosityOption()); .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());
} }
} }

View file

@ -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")));
}
}

View file

@ -1,6 +1,7 @@
// 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. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
@ -21,10 +22,14 @@ namespace Microsoft.DotNet.Tools.Restore
{ {
DebugHelper.HandleDebugSwitch(ref args); DebugHelper.HandleDebugSwitch(ref args);
var parser = Parser.DotnetCommand["restore"]; var parser = new Cli.CommandLine.Parser(
delimiters: Array.Empty<char>(),
options: Parser.DotnetCommand["restore"]);
var result = parser.Parse(args); var result = parser.Parse(args);
Reporter.Verbose.WriteLine(result.Diagram());
var restore = result["restore"]; var restore = result["restore"];
var msbuildArgs = new List<string> var msbuildArgs = new List<string>

View file

@ -8,9 +8,10 @@ namespace Microsoft.DotNet.Cli
internal static class RestoreCommandParser internal static class RestoreCommandParser
{ {
public static Command Restore() => public static Command Restore() =>
Create.Command("restore", Create.Command(
"restore",
".NET dependency restorer", ".NET dependency restorer",
Accept.OneOrMoreArguments, Accept.ExactlyOneArgument,
CommonOptions.HelpOption(), CommonOptions.HelpOption(),
Create.Option( Create.Option(
"-s|--source", "-s|--source",

View file

@ -40,7 +40,7 @@
<PackageReference Include="Microsoft.Win32.Registry" Version="4.3.0" /> <PackageReference Include="Microsoft.Win32.Registry" Version="4.3.0" />
<PackageReference Include="Microsoft.Build" Version="$(CLI_MSBuild_Version)" /> <PackageReference Include="Microsoft.Build" Version="$(CLI_MSBuild_Version)" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" /> <PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" />
<PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="0.1.0-alpha-74" /> <PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="0.1.0-alpha-76" />
<PackageReference Include="Microsoft.TemplateEngine.Abstractions" Version="$(TemplateEngineVersion)" /> <PackageReference Include="Microsoft.TemplateEngine.Abstractions" Version="$(TemplateEngineVersion)" />
<PackageReference Include="Microsoft.TemplateEngine.Cli" Version="$(TemplateEngineVersion)" /> <PackageReference Include="Microsoft.TemplateEngine.Cli" Version="$(TemplateEngineVersion)" />
<PackageReference Include="Microsoft.TemplateEngine.Orchestrator.RunnableProjects" Version="$(TemplateEngineVersion)" /> <PackageReference Include="Microsoft.TemplateEngine.Orchestrator.RunnableProjects" Version="$(TemplateEngineVersion)" />

View file

@ -42,6 +42,6 @@
<PackageReference Include="xunit" Version="2.2.0-beta4-build3444" /> <PackageReference Include="xunit" Version="2.2.0-beta4-build3444" />
<PackageReference Include="xunit.netcore.extensions" Version="1.0.0-prerelease-00206" /> <PackageReference Include="xunit.netcore.extensions" Version="1.0.0-prerelease-00206" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" /> <PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" />
<PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="[0.1.0-alpha-74,)" /> <PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="0.1.0-alpha-76" />
</ItemGroup> </ItemGroup>
</Project> </Project>