Skip to content

Commit 45cc113

Browse files
committed
Add support for dashdash in unparser for issue #254.
1 parent 5452c33 commit 45cc113

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Diff for: src/CommandLine/UnParserExtensions.cs

+6
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ orderby v.Index
148148
.Append(FormatOption((OptionSpecification)opt.Specification, opt.Value, settings))
149149
.Append(' ')
150150
);
151+
152+
if (valSpecs.Any() && parser.Settings.EnableDashDash)
153+
{
154+
builder.Append("-- ");
155+
}
156+
151157
valSpecs.ForEach(
152158
val => builder.Append(FormatValue(val.Specification, val.Value)).Append(' '));
153159

Diff for: tests/CommandLine.Tests/Unit/UnParserExtensionsTests.cs

+27
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,33 @@ public static void UnParsing_instance_with_equal_token_returns_command_line_with
6565
.ShouldBeEquivalentTo("-i 1 2 3 --stringvalue=nospaces -x 123456789");
6666
}
6767

68+
[Fact]
69+
public static void UnParsing_instance_with_dash_in_value_and_dashdash_enabled_returns_command_line_with_value_prefixed_with_dash_dash()
70+
{
71+
var options = new Simple_Options_With_Values { StringSequence = new List<string> { "-something", "with", "dash" } };
72+
new Parser((setting) => setting.EnableDashDash = true)
73+
.FormatCommandLine(options)
74+
.ShouldBeEquivalentTo("-- -something with dash");
75+
}
76+
77+
[Fact]
78+
public static void UnParsing_instance_with_no_values_and_dashdash_enabled_returns_command_line_without_dash_dash()
79+
{
80+
var options = new Simple_Options_With_Values();
81+
new Parser((setting) => setting.EnableDashDash = true)
82+
.FormatCommandLine(options)
83+
.ShouldBeEquivalentTo("");
84+
}
85+
86+
[Fact]
87+
public static void UnParsing_instance_with_dash_in_value_and_dashdash_disabled_returns_command_line_with_value()
88+
{
89+
var options = new Simple_Options_With_Values { StringSequence = new List<string> { "-something", "with", "dash" } };
90+
new Parser()
91+
.FormatCommandLine(options)
92+
.ShouldBeEquivalentTo("-something with dash");
93+
}
94+
6895
public static IEnumerable<object> UnParseData
6996
{
7097
get

0 commit comments

Comments
 (0)