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
}
Reproducer (similar to apptainer/apptainer#3668 )
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.
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:
Reproducer (similar to apptainer/apptainer#3668 )
Actual — the second line is 116 columns:
Expected — the unbreakable word overflows on a line of its own, and wrapping resumes:
I'll try to draft a quick PR, but before that would like @spf13 to confirm we agree on the "Expected" behavior.