Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove extra newline when message contains trailing newlines #387

Merged
merged 1 commit into from
Jul 5, 2024

Conversation

mitar
Copy link
Contributor

@mitar mitar commented Oct 17, 2023

If there is trailing newline, strings.Split creates an empty last line in lines, making this function output an extra empty line at the end. Trimming trailing newlines fixes that.

@@ -373,7 +373,7 @@ func (k *Kong) applyHookToDefaultFlags(ctx *Context, node *Node, name string) er
}

func formatMultilineMessage(w io.Writer, leaders []string, format string, args ...interface{}) {
lines := strings.Split(fmt.Sprintf(format, args...), "\n")
lines := strings.Split(strings.TrimRight(fmt.Sprintf(format, args...), "\n"), "\n")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be changed to TrimSuffix if we want to remove one and only one newline at the end.

@alecthomas alecthomas merged commit 5f9c5cc into alecthomas:master Jul 5, 2024
2 checks passed
@alecthomas
Copy link
Owner

Seems reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants