From 6448d6be7feea5c9487c968e181cf743bae28500 Mon Sep 17 00:00:00 2001 From: Joey Holtzman <89617856+jdholtz@users.noreply.github.com> Date: Sat, 26 Sep 2026 14:52:36 -0700 Subject: [PATCH] fix(help): print description on newlines for long flags (#2978) Follow-up to #2944. When flags are over 21 characters, the description is printed on a new line to avoid the flag from intersecting with the description and keeping everything aligned. This mimics what pacman does for long flags like `--disable-sandbox`. I decided to add logic to solve this instead of just adding a newline to the `--completioninterval` description (the only flag currently over 21 characters) so any future long flags added will automatically be aligned too. --- cmd.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd.go b/cmd.go index 7d90738b..fd54ef15 100644 --- a/cmd.go +++ b/cmd.go @@ -92,6 +92,8 @@ func findYayOperationHelp(operation string) *operationHelp { } func printUsageOptions(logger *text.Logger, title string, options []usageOption) { + flagWidth := 21 + logger.Println("\n" + title) for _, option := range options { if option.flags == "" && option.description == "" { @@ -100,9 +102,15 @@ func printUsageOptions(logger *text.Logger, title string, options []usageOption) } descriptionLines := strings.Split(option.description, "\n") - logger.Printf(" %-21s %s\n", option.flags, descriptionLines[0]) + if len(option.flags) > flagWidth { + // Print the description on the next line if the flags are too long + logger.Printf(" %s\n", option.flags) + logger.Printf(" %-*s %s\n", flagWidth, "", descriptionLines[0]) + } else { + logger.Printf(" %-*s %s\n", flagWidth, option.flags, descriptionLines[0]) + } for _, line := range descriptionLines[1:] { - logger.Printf(" %-21s %s\n", "", line) + logger.Printf(" %-*s %s\n", flagWidth, "", line) } } }