From b9a4abc7ef7fec7053a00e75c46c39ef4dc6daf8 Mon Sep 17 00:00:00 2001 From: Andrew Khoury Date: Thu, 18 Apr 2024 19:50:04 +0300 Subject: [PATCH 1/2] Align the short and long forms into their own columns in the help output. This makes displaying a mixed set of parameters cleaner and easier to understand. This is in line with the behavior of common GNU tools such as rsync. Old way: ``` Options: -i, --init Creates a skeleton config file in the current working directory -v, --verbose Enables verbose output. Twice will enable very-verbose output (good for logging) -y, --yes Assume 'yes' to all questions for headless execution --yaml= Specify a yaml file to load -h, --help Show this message ``` New way: ``` Options: -i, --init Creates a skeleton config file in the current working directory -v, --verbose Enables verbose output. Twice will enable very-verbose output (good for logging) -y, --yes Assume 'yes' to all questions for headless execution --yaml= Specify a yaml file to load -h, --help Show this message ``` --- lib/optimist.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/optimist.rb b/lib/optimist.rb index 9aa8962..73ef909 100644 --- a/lib/optimist.rb +++ b/lib/optimist.rb @@ -636,7 +636,7 @@ def parse(_paramlist, _neg_given) def type_format ; "" ; end def educate - (short? ? "-#{short}, " : "") + "--#{long}" + type_format + (flag? && default ? ", --no-#{long}" : "") + (short? ? "-#{short}, " : " ") + "--#{long}" + type_format + (flag? && default ? ", --no-#{long}" : "") end ## Format the educate-line description including the default-value(s) From 5284dd04e06820be8c3f38332d252b5d734a7be6 Mon Sep 17 00:00:00 2001 From: Andrew Khoury Date: Thu, 18 Apr 2024 20:25:46 +0300 Subject: [PATCH 2/2] Fixed tests for new alignment --- test/optimist/parser_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/optimist/parser_test.rb b/test/optimist/parser_test.rb index fbb3b4a..8fd4fce 100644 --- a/test/optimist/parser_test.rb +++ b/test/optimist/parser_test.rb @@ -471,8 +471,8 @@ def test_multi_line_description @p.educate(out) assert_equal <<-EOM, out.string Options: - --arg= This is an arg - with a multi-line description + --arg= This is an arg + with a multi-line description EOM end