refresh enumerator when moving to next subcommand (#5533)
This commit is contained in:
parent
626c8983c2
commit
6990c71e84
2 changed files with 45 additions and 6 deletions
|
@ -136,7 +136,7 @@ namespace Microsoft.DotNet.Cli.CommandLine
|
||||||
public int Execute(params string[] args)
|
public int Execute(params string[] args)
|
||||||
{
|
{
|
||||||
CommandLineApplication command = this;
|
CommandLineApplication command = this;
|
||||||
IEnumerator<CommandArgument> arguments = null;
|
CommandArgumentEnumerator arguments = null;
|
||||||
|
|
||||||
if (HandleResponseFiles)
|
if (HandleResponseFiles)
|
||||||
{
|
{
|
||||||
|
@ -181,9 +181,9 @@ namespace Microsoft.DotNet.Cli.CommandLine
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (arguments == null)
|
if (arguments == null || arguments.CommandName != command.Name)
|
||||||
{
|
{
|
||||||
arguments = new CommandArgumentEnumerator(command.Arguments.GetEnumerator());
|
arguments = new CommandArgumentEnumerator(command.Arguments.GetEnumerator(), command.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arguments.MoveNext())
|
if (arguments.MoveNext())
|
||||||
|
@ -629,11 +629,16 @@ namespace Microsoft.DotNet.Cli.CommandLine
|
||||||
{
|
{
|
||||||
private readonly IEnumerator<CommandArgument> _enumerator;
|
private readonly IEnumerator<CommandArgument> _enumerator;
|
||||||
|
|
||||||
public CommandArgumentEnumerator(IEnumerator<CommandArgument> enumerator)
|
public CommandArgumentEnumerator(
|
||||||
|
IEnumerator<CommandArgument> enumerator,
|
||||||
|
string commandName)
|
||||||
{
|
{
|
||||||
|
CommandName = commandName;
|
||||||
_enumerator = enumerator;
|
_enumerator = enumerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string CommandName { get; }
|
||||||
|
|
||||||
public CommandArgument Current
|
public CommandArgument Current
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
@ -2,18 +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 FluentAssertions;
|
using FluentAssertions;
|
||||||
using Microsoft.Build.Construction;
|
|
||||||
using Microsoft.DotNet.Cli.Sln.Internal;
|
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Package.Add.Tests
|
namespace Microsoft.DotNet.Cli.Package.Add.Tests
|
||||||
{
|
{
|
||||||
public class GivenDotnetPackageAdd : TestBase
|
public class GivenDotnetPackageAdd : TestBase
|
||||||
{
|
{
|
||||||
|
private readonly ITestOutputHelper _output;
|
||||||
|
|
||||||
|
public GivenDotnetPackageAdd(ITestOutputHelper output)
|
||||||
|
{
|
||||||
|
_output = output;
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenValidPackageIsPassedBeforeVersionItGetsAdded()
|
public void WhenValidPackageIsPassedBeforeVersionItGetsAdded()
|
||||||
|
@ -37,6 +42,35 @@ namespace Microsoft.DotNet.Cli.Package.Add.Tests
|
||||||
cmd.StdErr.Should().BeEmpty();
|
cmd.StdErr.Should().BeEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void
|
||||||
|
WhenValidProjectAndPackageArePassedItGetsAdded()
|
||||||
|
{
|
||||||
|
var testAsset = "TestAppSimple";
|
||||||
|
var projectDirectory = TestAssets
|
||||||
|
.Get(testAsset)
|
||||||
|
.CreateInstance()
|
||||||
|
.WithSourceFiles()
|
||||||
|
.Root
|
||||||
|
.FullName;
|
||||||
|
|
||||||
|
var csproj = $"{projectDirectory + Path.DirectorySeparatorChar + testAsset}.csproj";
|
||||||
|
var packageName = "Newtonsoft.Json";
|
||||||
|
var packageVersion = "9.0.1";
|
||||||
|
var cmd = new DotnetCommand()
|
||||||
|
.WithWorkingDirectory(projectDirectory)
|
||||||
|
.ExecuteWithCapturedOutput($"add {csproj} package {packageName} --version {packageVersion}");
|
||||||
|
|
||||||
|
_output.WriteLine($"[STDOUT] {cmd.StdOut}\n[STDERR]{cmd.StdErr}\n");
|
||||||
|
|
||||||
|
cmd.Should().Pass();
|
||||||
|
|
||||||
|
cmd.StdOut.Should()
|
||||||
|
.Contain($"PackageReference for package \'{packageName}\' version \'{packageVersion}\' added to file '{csproj}'.");
|
||||||
|
|
||||||
|
cmd.StdErr.Should().BeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenValidPackageIsPassedAfterVersionItGetsAdded()
|
public void WhenValidPackageIsPassedAfterVersionItGetsAdded()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue