2017-03-07 04:53:26 +00:00
|
|
|
// 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 FluentAssertions;
|
|
|
|
using Microsoft.DotNet.Cli;
|
|
|
|
using Microsoft.DotNet.Cli.CommandLine;
|
|
|
|
using Xunit;
|
|
|
|
using static Microsoft.DotNet.Cli.CommandLine.Accept;
|
|
|
|
using static Microsoft.DotNet.Cli.CommandLine.Create;
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tests.ParserTests
|
|
|
|
{
|
|
|
|
public class ArgumentForwardingExtensionsTests
|
|
|
|
{
|
|
|
|
[Fact]
|
|
|
|
public void An_outgoing_command_line_can_be_generated_based_on_a_parse_result()
|
|
|
|
{
|
|
|
|
var command = Command("the-command", "",
|
|
|
|
Option("-o|--one", "",
|
|
|
|
ZeroOrOneArgument.ForwardAs("/i:{0}")),
|
|
|
|
Option("-t|--two", "",
|
|
|
|
ZeroOrOneArgument.ForwardAs("/s:{0}")));
|
|
|
|
|
|
|
|
var result = command.Parse("the-command -t argument-two-value -o 123");
|
|
|
|
|
|
|
|
result["the-command"]
|
2017-03-09 15:35:06 +00:00
|
|
|
.OptionValuesToBeForwarded()
|
2017-03-07 04:53:26 +00:00
|
|
|
.Should()
|
|
|
|
.BeEquivalentTo("/i:123", "/s:argument-two-value");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void MultipleArgumentsCanBeJoinedWhenForwarding()
|
|
|
|
{
|
|
|
|
var command = Command("the-command", "",
|
|
|
|
Option("-x", "",
|
|
|
|
ZeroOrMoreArguments.ForwardAs(o => $"/x:{string.Join("&", o.Arguments)}")));
|
|
|
|
|
|
|
|
var result = command.Parse("the-command -x one -x two");
|
|
|
|
|
|
|
|
result["the-command"]
|
2017-03-09 15:35:06 +00:00
|
|
|
.OptionValuesToBeForwarded()
|
2017-03-07 04:53:26 +00:00
|
|
|
.Should()
|
|
|
|
.BeEquivalentTo("/x:one&two");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|