diff --git a/src/CommandLine/UnParserExtensions.cs b/src/CommandLine/UnParserExtensions.cs index bc51fe5b..0e150c02 100644 --- a/src/CommandLine/UnParserExtensions.cs +++ b/src/CommandLine/UnParserExtensions.cs @@ -148,6 +148,12 @@ orderby v.Index .Append(FormatOption((OptionSpecification)opt.Specification, opt.Value, settings)) .Append(' ') ); + + if (valSpecs.Any() && parser.Settings.EnableDashDash) + { + builder.Append("-- "); + } + valSpecs.ForEach( val => builder.Append(FormatValue(val.Specification, val.Value)).Append(' ')); diff --git a/tests/CommandLine.Tests/Unit/UnParserExtensionsTests.cs b/tests/CommandLine.Tests/Unit/UnParserExtensionsTests.cs index c716bcd3..da32a342 100644 --- a/tests/CommandLine.Tests/Unit/UnParserExtensionsTests.cs +++ b/tests/CommandLine.Tests/Unit/UnParserExtensionsTests.cs @@ -65,6 +65,33 @@ public static void UnParsing_instance_with_equal_token_returns_command_line_with .ShouldBeEquivalentTo("-i 1 2 3 --stringvalue=nospaces -x 123456789"); } + [Fact] + public static void UnParsing_instance_with_dash_in_value_and_dashdash_enabled_returns_command_line_with_value_prefixed_with_dash_dash() + { + var options = new Simple_Options_With_Values { StringSequence = new List { "-something", "with", "dash" } }; + new Parser((setting) => setting.EnableDashDash = true) + .FormatCommandLine(options) + .ShouldBeEquivalentTo("-- -something with dash"); + } + + [Fact] + public static void UnParsing_instance_with_no_values_and_dashdash_enabled_returns_command_line_without_dash_dash() + { + var options = new Simple_Options_With_Values(); + new Parser((setting) => setting.EnableDashDash = true) + .FormatCommandLine(options) + .ShouldBeEquivalentTo(""); + } + + [Fact] + public static void UnParsing_instance_with_dash_in_value_and_dashdash_disabled_returns_command_line_with_value() + { + var options = new Simple_Options_With_Values { StringSequence = new List { "-something", "with", "dash" } }; + new Parser() + .FormatCommandLine(options) + .ShouldBeEquivalentTo("-something with dash"); + } + public static IEnumerable UnParseData { get