Skip to content

Commit 2cede51

Browse files
committed
Update helptext to show Default Verb
1 parent 4bed343 commit 2cede51

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/CommandLine/Text/HelpText.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ private IEnumerable<Specification> AdaptVerbsToSpecifications(IEnumerable<Type>
853853
string.Empty,
854854
verbTuple.Item1.Name,
855855
false,
856-
verbTuple.Item1.HelpText,
856+
verbTuple.Item1.IsDefault? "(Default Verb) "+verbTuple.Item1.HelpText: verbTuple.Item1.HelpText, //Default verb
857857
string.Empty,
858858
verbTuple.Item1.Hidden);
859859
if (autoHelp)

tests/CommandLine.Tests/Fakes/Verb_Fakes.cs

+13
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,20 @@ public class Add_Verb
1818
[Value(0)]
1919
public string FileName { get; set; }
2020
}
21+
[Verb("add", isDefault:true,HelpText = "Add file contents to the index.")]
22+
public class Add_Verb_As_Default
23+
{
24+
[Option('p', "patch", SetName = "mode-p",
25+
HelpText = "Interactively choose hunks of patch between the index and the work tree and add them to the index.")]
26+
public bool Patch { get; set; }
2127

28+
[Option('f', "force", SetName = "mode-f",
29+
HelpText = "Allow adding otherwise ignored files.")]
30+
public bool Force { get; set; }
31+
32+
[Value(0)]
33+
public string FileName { get; set; }
34+
}
2235
[Verb("commit", HelpText = "Record changes to the repository.")]
2336
public class Commit_Verb
2437
{

tests/CommandLine.Tests/Unit/ParserTests.cs

+23
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,30 @@ public void Implicit_help_screen_in_verb_scenario()
370370
lines[8].Should().BeEquivalentTo("version Display version information.");
371371
// Teardown
372372
}
373+
374+
[Fact]
375+
public void Help_screen_in_default_verb_scenario()
376+
{
377+
// Fixture setup
378+
var help = new StringWriter();
379+
var sut = new Parser(config => config.HelpWriter = help);
373380

381+
// Exercise system
382+
sut.ParseArguments<Add_Verb_As_Default, Commit_Verb, Clone_Verb>(new string[] {"--help" });
383+
var result = help.ToString();
384+
385+
// Verify outcome
386+
result.Length.Should().BeGreaterThan(0);
387+
var lines = result.ToNotEmptyLines().TrimStringArray();
388+
lines[0].Should().Be(HeadingInfo.Default.ToString());
389+
lines[1].Should().Be(CopyrightInfo.Default.ToString());
390+
lines[2].Should().BeEquivalentTo("add (Default Verb) Add file contents to the index.");
391+
lines[3].Should().BeEquivalentTo("commit Record changes to the repository.");
392+
lines[4].Should().BeEquivalentTo("clone Clone a repository into a new directory.");
393+
lines[5].Should().BeEquivalentTo("help Display more information on a specific command.");
394+
lines[6].Should().BeEquivalentTo("version Display version information.");
395+
396+
}
374397
[Fact]
375398
public void Double_dash_help_dispalys_verbs_index_in_verbs_scenario()
376399
{

0 commit comments

Comments
 (0)