You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FlagUsagesWrapped stops wrapping the rest of a usage string after a word wider than the description column #501
When a usage string contains a word too wide to fit the remaining space, wrapN returns the entire rest of the string unwrapped — not just the over-wide word. Everything after it lands on one long line.
flag.go, in wrapN:
w := strings.LastIndexAny(s[:i], " \t\n")
if w <= 0 {
return s, "" // <- gives up on the whole remainder, not just this word
}
package main
import (
"fmt"
"github.com/spf13/pflag"
)
func main() {
fs := pflag.NewFlagSet("example", pflag.ContinueOnError)
fs.String("mount", "", "a mount specification e.g. 'type=bind,source=/opt,destination=/hostopt'. The rethis description is never wrapped.")
fmt.Print(fs.FlagUsagesWrapped(60))
}
Actual — the second line is 116 columns:
--mount string a mount specification e.g.
'type=bind,source=/opt,destination=/hostopt'. The rest of this description is never wrapped.
Expected — the unbreakable word overflows on a line of its own, and wrapping resumes:
--mount string a mount specification e.g.
'type=bind,source=/opt,destination=/hostopt'.
The rest of this description is
never wrapped.
I'll try to draft a quick PR, but before that would like @spf13 to confirm we agree on the "Expected" behavior.
Activity
AzazelSensei commentedon Aug 13, 2026
Opened #503