Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .paket/paket.bootstrapper.exe
Binary file not shown.
17 changes: 14 additions & 3 deletions src/CommandLine/UnParserExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class UnParserSettings
private bool preferShortName;
private bool groupSwitches;
private bool useEqualToken;
private bool showHidden;

/// <summary>
/// Gets or sets a value indicating whether unparsing process shall prefer short or long names.
Expand Down Expand Up @@ -46,6 +47,14 @@ public bool UseEqualToken
set { PopsicleSetter.Set(Consumed, ref useEqualToken, value); }
}

/// <summary>
/// Gets or sets a value indicating whether unparsing process shall expose hidden options.
/// </summary>
public bool ShowHidden
{
get { return showHidden; }
set { PopsicleSetter.Set(Consumed, ref showHidden, value); }
}
/// <summary>
/// Factory method that creates an instance of <see cref="CommandLine.UnParserSettings"/> with GroupSwitches set to true.
/// </summary>
Expand Down Expand Up @@ -119,6 +128,7 @@ public static string FormatCommandLine<T>(this Parser parser, T options, Action<
var allOptSpecs = from info in specs.Where(i => i.Specification.Tag == SpecificationType.Option)
let o = (OptionSpecification)info.Specification
where o.TargetType != TargetType.Switch || (o.TargetType == TargetType.Switch && ((bool)info.Value))
where !o.Hidden || settings.ShowHidden
orderby o.UniqueName()
select info;

Expand Down Expand Up @@ -206,9 +216,10 @@ private static string FormatOption(OptionSpecification spec, object value, UnPar

private static string FormatName(this OptionSpecification optionSpec, UnParserSettings settings)
{
var longName =
optionSpec.LongName.Length > 0
&& !settings.PreferShortName;
// Have a long name and short name not preferred? Go with long!
// No short name? Has to be long!
var longName = (optionSpec.LongName.Length > 0 && !settings.PreferShortName)
|| optionSpec.ShortName.Length == 0;

return
new StringBuilder(longName
Expand Down
1 change: 1 addition & 0 deletions tests/CommandLine.Tests/CommandLine.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="CultureInfoExtensions.cs" />
<Compile Include="Fakes\Hidden_Option.cs" />
<Compile Include="Fakes\Options_With_Default_Set_To_Sequence.cs" />
<Compile Include="Fakes\Options_With_Guid.cs" />
<Compile Include="Fakes\Options_With_Option_And_Value_Of_String_Type.cs" />
Expand Down
14 changes: 14 additions & 0 deletions tests/CommandLine.Tests/Fakes/Hidden_Option.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommandLine.Tests.Fakes
{
public class Hidden_Option
{
[Option('h', "hiddenOption", Default="hidden", Hidden = true)]
public string HiddenOption { get; set; }
}
}
17 changes: 17 additions & 0 deletions tests/CommandLine.Tests/Unit/UnParserExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public static void UnParsing_immutable_instance_returns_command_line(Immutable_S
.ShouldBeEquivalentTo(result);
}

[Theory]
[MemberData("UnParseDataHidden")]
public static void Unparsing_hidden_option_returns_command_line(Hidden_Option options, bool showHidden, string result)
{
new Parser()
.FormatCommandLine(options, config => config.ShowHidden = showHidden)
.ShouldBeEquivalentTo(result);
}

#if !SKIP_FSHARP
[Theory]
[MemberData("UnParseDataFSharpOption")]
Expand Down Expand Up @@ -141,6 +150,14 @@ public static IEnumerable<object> UnParseDataImmutable
}
}

public static IEnumerable<object> UnParseDataHidden
{
get
{
yield return new object[] { new Hidden_Option { HiddenOption = "hidden" }, true, "--hiddenOption hidden" };
yield return new object[] { new Hidden_Option { HiddenOption = "hidden" }, false, ""};
}
}
#if !SKIP_FSHARP
public static IEnumerable<object> UnParseDataFSharpOption
{
Expand Down