Skip to content

Commit f73a053

Browse files
committed
fix(commandlinehelp): Ignore hidden commands
Do not generate documentation for commands when the option class is marked as hidden Closes #20
1 parent 4c54460 commit f73a053

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/MdDocs.CommandLineHelp.Test/Model/_Application/MultiCommandApplicationDocumentationTest.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,31 @@ public class Command1Options
167167
Assert.NotNull(sut.Usage);
168168
Assert.Empty(sut.Usage);
169169
}
170+
171+
[Fact]
172+
public void Hidden_option_classes_are_ignored()
173+
{
174+
// ARRANGE
175+
var cs = @"
176+
using CommandLine;
177+
178+
[Verb(""command1"")]
179+
public class Command1Options
180+
{ }
181+
182+
[Verb(""command2"", Hidden = true)]
183+
public class Command2Options
184+
{ }
185+
";
186+
187+
using var assembly = Compile(cs);
188+
189+
// ACT
190+
var sut = MultiCommandApplicationDocumentation.FromAssemblyDefinition(assembly, NullLogger.Instance);
191+
192+
// ASSERT
193+
var command = Assert.Single(sut.Commands);
194+
Assert.Equal("command1", command.Name);
195+
}
170196
}
171197
}

src/MdDocs.CommandLineHelp/Model/_Application/MultiCommandApplicationDocumentation.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ private IReadOnlyList<CommandDocumentation> LoadCommands(AssemblyDefinition defi
4343
return definition.MainModule.Types
4444
.Where(x => !x.IsAbstract)
4545
.WithAttribute(Constants.VerbAttributeFullName)
46+
.Where(x => !x.GetAttribute(Constants.VerbAttributeFullName).GetPropertyValueOrDefault<bool>("Hidden"))
4647
.Select(type => CommandDocumentation.FromTypeDefinition(this, type, logger))
4748
.ToArray();
4849
}

0 commit comments

Comments
 (0)