Skip to content

Commit e93a7fc

Browse files
AndreGleichnernatemcmaster
authored andcommitted
fix: update generated help to display [command] first then [options] (#308)
Should be: Usage: mytool [command] [options] instead of: Usage: mytool [options] [command] Having any options in front of the command verb fails, so the usage help should reflect this.
1 parent 1724fd2 commit e93a7fc

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/CommandLineUtils/HelpText/DefaultHelpTextGenerator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ protected virtual void GenerateUsage(
145145
output.Write(stack.Pop());
146146
}
147147

148+
if (visibleCommands.Any())
149+
{
150+
output.Write(" [command]");
151+
}
152+
148153
if (visibleOptions.Any())
149154
{
150155
output.Write(" [options]");
@@ -157,11 +162,6 @@ protected virtual void GenerateUsage(
157162
output.Write(">");
158163
}
159164

160-
if (visibleCommands.Any())
161-
{
162-
output.Write(" [command]");
163-
}
164-
165165
if (application.AllowArgumentSeparator)
166166
{
167167
output.Write(" [[--] <arg>...]");

test/CommandLineUtils.Tests/CommandLineApplicationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ public void HelpOptionIsInherited(string helpOptionString)
800800
outData = outWriter.ToString();
801801

802802
Assert.True(helpOption.HasValue());
803-
Assert.Contains("Usage: lvl1 [options]", outData);
803+
Assert.Contains("Usage: lvl1 [command] [options]", outData);
804804
}
805805
}
806806

test/CommandLineUtils.Tests/HelpOptionAttributeTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ public void HelpOptionIsInherited()
181181
[InlineData(new[] { "get", "--help" }, "Usage: updater get [options]")]
182182
[InlineData(new[] { "get", "-h" }, "Usage: updater get [options]")]
183183
[InlineData(new[] { "get", "-?" }, "Usage: updater get [options]")]
184-
[InlineData(new[] { "--help" }, "Usage: updater [options] [command]")]
185-
[InlineData(new[] { "-h" }, "Usage: updater [options] [command]")]
186-
[InlineData(new[] { "-?" }, "Usage: updater [options] [command]")]
184+
[InlineData(new[] { "--help" }, "Usage: updater [command] [options]")]
185+
[InlineData(new[] { "-h" }, "Usage: updater [command] [options]")]
186+
[InlineData(new[] { "-?" }, "Usage: updater [command] [options]")]
187187
public void NestedHelpOptionsChoosesHelpOptionNearestSelectedCommand(string[] args, string helpNeedle)
188188
{
189189
var sb = new StringBuilder();

test/CommandLineUtils.Tests/SubcommandAttributeTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void HandlesHelp_Middle()
140140
};
141141
var rc = CommandLineApplication.Execute<MasterApp>(console, "level1", "--help");
142142
Assert.Equal(0, rc);
143-
Assert.Contains("Usage: master level1 [options]", sb.ToString());
143+
Assert.Contains("Usage: master level1 [command] [options]", sb.ToString());
144144
}
145145

146146
[Fact]
@@ -154,7 +154,7 @@ public void HandlesHelp_Top()
154154
};
155155
var rc = CommandLineApplication.Execute<MasterApp>(console, "--help");
156156
Assert.Equal(0, rc);
157-
Assert.Contains("Usage: master [options]", sb.ToString());
157+
Assert.Contains("Usage: master [command] [options]", sb.ToString());
158158
}
159159

160160
[Fact]

0 commit comments

Comments
 (0)