Open farnasirim opened 5 years ago
This issue is being marked as stale due to a long period of inactivity
Having worked on a few different tools I agree that the general text-wrapping problem is frustrating for every dev to handle and if cobra could do it for the help/usage it would make a lot of sense.
The main issue is that there are lots of different approaches/libraries that help so it may be a bit opinionated. Open to a PR for sure though.
kubectl
has a printer here that might be a useful starting point: https://github.com/kubernetes/kubernetes/pull/104736
If someone wants something quick and dirty:
width, _, _ := term.GetSize(int(os.Stdout.Fd()))
usageTemplate := rootCmd.UsageTemplate()
usageTemplate = strings.ReplaceAll(usageTemplate, ".FlagUsages", fmt.Sprintf(".FlagUsagesWrapped %d", width))
rootCmd.SetUsageTemplate(usageTemplate)
I had a look around the code and figured that this is not supported. Was wondering if you would accept a patch.
This is not very trivial to do right now as the padding that comes before the command descriptions is dependent on the longest flag name + type and calculating the padding and repadding subsequent lines is cumbersome for the user.
Therefore I think it makes more sense to handle this inside cobra.