From 6da45ca170ab3f8a4cee1646a4854d46a041d292 Mon Sep 17 00:00:00 2001 From: Andre Gleichner Date: Mon, 18 Nov 2019 21:37:31 +0100 Subject: [PATCH 1/2] Issue 303: Fixed usage help to display [command] first then [options]. 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. --- .../HelpText/DefaultHelpTextGenerator.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CommandLineUtils/HelpText/DefaultHelpTextGenerator.cs b/src/CommandLineUtils/HelpText/DefaultHelpTextGenerator.cs index c8343900..f26e39ce 100644 --- a/src/CommandLineUtils/HelpText/DefaultHelpTextGenerator.cs +++ b/src/CommandLineUtils/HelpText/DefaultHelpTextGenerator.cs @@ -145,6 +145,11 @@ protected virtual void GenerateUsage( output.Write(stack.Pop()); } + if (visibleCommands.Any()) + { + output.Write(" [command]"); + } + if (visibleOptions.Any()) { output.Write(" [options]"); @@ -157,11 +162,6 @@ protected virtual void GenerateUsage( output.Write(">"); } - if (visibleCommands.Any()) - { - output.Write(" [command]"); - } - if (application.AllowArgumentSeparator) { output.Write(" [[--] ...]"); From be913fbda61b2ebaba31acc63b4e794bd6a3485b Mon Sep 17 00:00:00 2001 From: Andre Gleichner Date: Tue, 19 Nov 2019 21:38:28 +0100 Subject: [PATCH 2/2] Fixing tests --- test/CommandLineUtils.Tests/CommandLineApplicationTests.cs | 2 +- test/CommandLineUtils.Tests/HelpOptionAttributeTests.cs | 6 +++--- test/CommandLineUtils.Tests/SubcommandAttributeTests.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/CommandLineUtils.Tests/CommandLineApplicationTests.cs b/test/CommandLineUtils.Tests/CommandLineApplicationTests.cs index cbcc346c..5a5d3054 100644 --- a/test/CommandLineUtils.Tests/CommandLineApplicationTests.cs +++ b/test/CommandLineUtils.Tests/CommandLineApplicationTests.cs @@ -800,7 +800,7 @@ public void HelpOptionIsInherited(string helpOptionString) outData = outWriter.ToString(); Assert.True(helpOption.HasValue()); - Assert.Contains("Usage: lvl1 [options]", outData); + Assert.Contains("Usage: lvl1 [command] [options]", outData); } } diff --git a/test/CommandLineUtils.Tests/HelpOptionAttributeTests.cs b/test/CommandLineUtils.Tests/HelpOptionAttributeTests.cs index df167410..08b032c6 100644 --- a/test/CommandLineUtils.Tests/HelpOptionAttributeTests.cs +++ b/test/CommandLineUtils.Tests/HelpOptionAttributeTests.cs @@ -181,9 +181,9 @@ public void HelpOptionIsInherited() [InlineData(new[] { "get", "--help" }, "Usage: updater get [options]")] [InlineData(new[] { "get", "-h" }, "Usage: updater get [options]")] [InlineData(new[] { "get", "-?" }, "Usage: updater get [options]")] - [InlineData(new[] { "--help" }, "Usage: updater [options] [command]")] - [InlineData(new[] { "-h" }, "Usage: updater [options] [command]")] - [InlineData(new[] { "-?" }, "Usage: updater [options] [command]")] + [InlineData(new[] { "--help" }, "Usage: updater [command] [options]")] + [InlineData(new[] { "-h" }, "Usage: updater [command] [options]")] + [InlineData(new[] { "-?" }, "Usage: updater [command] [options]")] public void NestedHelpOptionsChoosesHelpOptionNearestSelectedCommand(string[] args, string helpNeedle) { var sb = new StringBuilder(); diff --git a/test/CommandLineUtils.Tests/SubcommandAttributeTests.cs b/test/CommandLineUtils.Tests/SubcommandAttributeTests.cs index 987edc14..3fb941e5 100755 --- a/test/CommandLineUtils.Tests/SubcommandAttributeTests.cs +++ b/test/CommandLineUtils.Tests/SubcommandAttributeTests.cs @@ -140,7 +140,7 @@ public void HandlesHelp_Middle() }; var rc = CommandLineApplication.Execute(console, "level1", "--help"); Assert.Equal(0, rc); - Assert.Contains("Usage: master level1 [options]", sb.ToString()); + Assert.Contains("Usage: master level1 [command] [options]", sb.ToString()); } [Fact] @@ -154,7 +154,7 @@ public void HandlesHelp_Top() }; var rc = CommandLineApplication.Execute(console, "--help"); Assert.Equal(0, rc); - Assert.Contains("Usage: master [options]", sb.ToString()); + Assert.Contains("Usage: master [command] [options]", sb.ToString()); } [Fact]