From 8327080fe0e503252ed54b34b84f0aca59729a78 Mon Sep 17 00:00:00 2001 From: Stephen Sherratt Date: Fri, 5 Sep 2025 02:11:19 +1000 Subject: [PATCH] Print repeated positional arg doc after fixed Signed-off-by: Stephen Sherratt --- CHANGES.md | 1 + src/climate/help.ml | 32 +++++++++++++++++------------- tests/usage_tests/help_messages.ml | 2 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3258473..d0e9363 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ ### Fixed - Fix alignment of doc text of positional arguments (#21) +- Print repeated positional argument docs below fixed positionalargument docs ## 0.8.2 diff --git a/src/climate/help.ml b/src/climate/help.ml index b16ca39..2445525 100644 --- a/src/climate/help.ml +++ b/src/climate/help.ml @@ -201,20 +201,24 @@ module Positional_args = struct let to_print_section { fixed; repeated } = let entries = - List.map fixed ~f:(fun { Command_doc_spec.Positional_arg.value; doc } -> - { Print.Entry.names = Print.Names.empty - ; value = Some value - ; doc - ; repeated = false - }) - |> List.append - (Option.map repeated ~f:(fun { Command_doc_spec.Positional_arg.value; doc } -> - { Print.Entry.names = Print.Names.empty - ; value = Some value - ; doc - ; repeated = true - }) - |> Option.to_list) + let fixed = + List.map fixed ~f:(fun { Command_doc_spec.Positional_arg.value; doc } -> + { Print.Entry.names = Print.Names.empty + ; value = Some value + ; doc + ; repeated = false + }) + in + let repeated = + Option.map repeated ~f:(fun { Command_doc_spec.Positional_arg.value; doc } -> + { Print.Entry.names = Print.Names.empty + ; value = Some value + ; doc + ; repeated = true + }) + |> Option.to_list + in + fixed @ repeated in { Print.Section.section_heading = "Arguments:"; entries } ;; diff --git a/tests/usage_tests/help_messages.ml b/tests/usage_tests/help_messages.ml index 062e89a..7056a31 100644 --- a/tests/usage_tests/help_messages.ml +++ b/tests/usage_tests/help_messages.ml @@ -462,9 +462,9 @@ let%expect_test "positional arguments" = Usage: foo.exe [OPTION]… [REST]… Arguments: - [REST]... rest doc first doc second doc + [REST]... rest doc Options: -h, --help Show this help message.