From f889aae5e147dab87f6a219f1d2a3a93c0689743 Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Wed, 12 Aug 2026 12:56:59 -0500 Subject: [PATCH] added dynamic resizing of description for flag & the like --- src/cligen/template/cmd_help.ecr | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cligen/template/cmd_help.ecr b/src/cligen/template/cmd_help.ecr index e11e62b..aa84e15 100644 --- a/src/cligen/template/cmd_help.ecr +++ b/src/cligen/template/cmd_help.ecr @@ -3,13 +3,15 @@ Command: <%= @name %> Description: <%= @description %> <%- end -%> +<%- len = @flags.map{|f| f.short.nil? ? f.long.size : "#{f.short},#{f.long}".size}.max + 5 -%> + Flags: --------------------------------------------------------------- <%- @flags.each do |flag| -%> <%- unless flag.short.nil? -%> - <%= "%-30s %s" % ["#{flag.short.not_nil!.strip},#{flag.long.strip}", flag.description.strip] %> + <%= "%-#{len}s %s" % ["#{flag.short.not_nil!.strip},#{flag.long.strip}", flag.description.strip] %> <%- else -%> - <%= "%-30s %s" % [flag.long.strip, flag.description.strip] %> + <%= "%-#{len}s %s" % [flag.long.strip, flag.description.strip] %> <%- end -%> <%- end -%> @@ -17,7 +19,7 @@ Flags: Other Commands --------------------------------------------------------------- <%- @commands.each do |command| -%> - <%= "%-30s %s" % [ command.name, command.description ] %> + <%= "%-#{len}s %s" % [ command.name, command.description ] %> <%- end -%> <%- end -%> @@ -25,7 +27,7 @@ Other Commands SubCommands of <%= @name %>: --------------------------------------------------------------- <%- subcommands.each do |cmd| -%> - <%= "%-30s %s" % [cmd.name, cmd.description] %> + <%= "%-#{len}s %s" % [cmd.name, cmd.description] %> <%- end -%> <%- cmds = subcommands.select{|c| ! c.examples.nil? } -%>