From a8b075aafa18ca3db441a234cde7fff3ec4fdf5e Mon Sep 17 00:00:00 2001 From: Daniel Gilchrist Date: Sun, 17 Sep 2023 20:55:16 +0100 Subject: [PATCH] Fix: --help summary for subcommands shows parents summary --- spec/formatter_spec.cr | 17 +++++++++++++++++ src/cling/formatter.cr | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/spec/formatter_spec.cr b/spec/formatter_spec.cr index 4165b71..d829f74 100644 --- a/spec/formatter_spec.cr +++ b/spec/formatter_spec.cr @@ -15,7 +15,18 @@ private class GreetCommand < Cling::MainCommand end end +class WelcomeCommand < Cling::Command + def setup : Nil + @name = "welcome" + @summary = @description = "sends a friendly welcome message" + end + + def run(arguments : Cling::Arguments, options : Cling::Options) : Nil + end +end + command = GreetCommand.new +command.add_command WelcomeCommand.new formatter = Cling::Formatter.new describe Cling::Formatter do @@ -26,6 +37,9 @@ describe Cling::Formatter do Usage: \tgreet [options] + Commands: + \twelcome sends a friendly welcome message + Arguments: \tname the name of the person (required) @@ -45,6 +59,9 @@ describe Cling::Formatter do Usage: \tgreet [options] + Commands: + \twelcome sends a friendly welcome message + Arguments: \tname the name of the person (required) diff --git a/src/cling/formatter.cr b/src/cling/formatter.cr index 65edc43..b5800bc 100644 --- a/src/cling/formatter.cr +++ b/src/cling/formatter.cr @@ -97,7 +97,7 @@ module Cling io << "Commands:" commands.each do |cmd| io << "\n\t" - if summary = command.summary + if summary = cmd.summary cmd.name.ljust(io, max_space, ' ') io << summary else