cobra
cobra copied to clipboard
formatting of help message with a really long flags descriptions
Hi, and thanks for a wonderful library!
To jump right into action, this is a help message I'm getting now:
This is a script to generate some random (but sane) stat events for the raw_logs table in ClickHouse.
All generated events will have user_id "dummy".
Required flags are --count and --time_from, --time_to will be by default set to current time.
So, --count events would be generated in time window between --time_from and --time_to.
Usage:
fill_raw_log [flags]
Flags:
-a, --account_ids --account_ids 3,5 --account_ids 4 comma-separated list of ids (--account_ids 3,5 --account_ids 4 => 3,4,5); optionally it is possible to provide probabilities of each id (`--account_ids 3=60,5=40`); in the first case probabilities will be ~equal, in the second they must add up to exactly 100
--configdir strings list directories with config files
-c, --count int number of events to generate
-h, --help help for fill_raw_log
--mode string run mode (default "development")
--time_from string format is YYYY-MM-DD HH:MM:SS
--time_to string format is YYYY-MM-DD HH:MM:SS; minutes and seconds are truncated
--version prints git commit hash of the binary and exits
Well, github here creates a long horizontal scroll. What happens in a real terminal - usage wraps to next row like that:
-a, --account_ids --account_ids 3,5 --account_ids 4 comma-separated list of ids (--account_ids 3,5 --account_ids
4` => 3,4,5); optionally it is possible to provide probabilities of each id (`--account_ids 3=60,5=40`); in the first case
probabilities will be ~equal, in the second they must add up to exactly 100
--configdir strings list directories with config files
And this is does not look great and makes scanning over available flags harder than necessary.
Usage string for --account_ids
flag is "comma-separated list of ids (--account_ids 3,5 --account_ids 4
=> 3,4,5); optionally it is possible to provide probabilities of each id (--account_ids 3=60,5=40
); in the first case probabilities will be ~equal, in the second they must add up to exactly 100".
Also, funny how it took examples out of usage... I'm not sure this is documented. Note that it was taken from the first set of the backticks inside usage, and that set of backticks was removed from usage. Following sets of backticks remained in their places.
What I would prefer instead is:
This is a script to generate some random (but sane) stat events for the raw_logs table in ClickHouse.
All generated events will have user_id "dummy".
Required flags are --count and --time_from, --time_to will be by default set to current time.
So, --count events would be generated in time window between --time_from and --time_to.
Usage:
fill_raw_log [flags]
Flags:
-a, --account_ids --account_ids 3,5 --account_ids 4 comma-separated list of ids (--account_ids 3,5 --account_ids 4 => 3,4,5);
optionally it is possible to provide probabilities of each id (`--account_ids 3=60,5=40`);
in the first case probabilities will be ~equal, in the second they must add up to exactly 100
--configdir strings list directories with config files
-c, --count int number of events to generate
-h, --help help for fill_raw_log
--mode string run mode (default "development")
--time_from string format is YYYY-MM-DD HH:MM:SS
--time_to string format is YYYY-MM-DD HH:MM:SS; minutes and seconds are truncated
--version prints git commit hash of the binary and exits
Or something like that. Ideally, length of the usage line before wrapping should depend on a terminal width. Calculating indent level myself and manipulating the usage to achieve similar effect would be tedious and hard to do in a robust way (for example, seeing how my examples got extracted from the usage).
And this is does not look great and makes scanning over available flags harder than necessary.
This is not functionality cobra provides out of the box but is a common extension: you need to introspect the width of the user's terminal in a function and use that function in a new usage template you define
I looked into your link just now, because I really didn't like the idea to do it manually, lol. But it turns out, that all I need to do manually is just call FlagUsagesWrapped method on a FlagSet, and the rest will happen automatically?
The Cobra project currently lacks enough contributors to adequately respond to all issues. This bot triages issues and PRs according to the following rules:
- After 60d of inactivity, lifecycle/stale is applied. - After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied and the issue is closed. You can:
- Make a comment to remove the stale label and show your support. The 60 days reset. - If an issue has lifecycle/rotten and is closed, comment and ask maintainers if they'd be interested in reopening