cli: render command groups, inherited flags, examples and learn-more in --help#27124
Open
davlgd wants to merge 2 commits into
Open
cli: render command groups, inherited flags, examples and learn-more in --help#27124davlgd wants to merge 2 commits into
davlgd wants to merge 2 commits into
Conversation
Member
|
Btw to enforce our "one way" policy I'll be keeping only flag in vlib. cli will be moved to |
Contributor
Author
|
Got it — happy to help with that move. Two questions:
|
Member
|
I'll merge it before the extraction. I'll do the extraction myself. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR teaches
vlib/cli's--helprendering about four extra sections. Three are unlocked by new optional fields onCommand(none of which render anything unless populated):group stringon a sub-command — its parent's listing splits into one section per group, named after thegroupstring verbatim followed by:. Sub-commands without a group keep falling back to the defaultCommands:block. Helpful for CLI with lots of commands.examples []string— rendered under a newExamples:section, one entry per indented line.learn_more string— rendered under a newLearn more:section, with newlines splitting the block into separate lines.The fourth uses the existing
Flag.globalfield to split inherited flags into their own section: any ancestor declared withFlag.global = truenow move out of the localFlags:block into a separateInherited flags:section, so a sub-command's own surface stays readable.The motivation is to bring
vlib/clicloser to widely-used CLI conventions (named sections, grouped sub-commands, examples, inherited flags), as recommended by the Command Line Interface Guidelines for example, while keeping V's existingUsage:/Flags:/Commands:visual style so adopting the new fields never feels like a different tool.Rendering
Running
examples/cli_groups.vwith--helpproduces:Drilling into a sub-command surfaces the new
Inherited flags:block:A
Commandwith none of the new fields populated and no inherited globals renders exactly like before:Usage:line, optional description,Flags:,Commands:. No new sections appear unless they have content.How to try it
The example exercises every new code path: groups (
Core commands/Additional commands), an inherited global flag (-c, --config), anexamplesblock and a multi-linelearn_moreblock.Tests
I've added four cases to
vlib/cli/help_test.v:test_help_message_groups_commands_by_group_fieldtest_help_message_renders_group_title_verbatim(UTF-8 safety: agroupstring starting with a multi-byte character renders without mojibake)test_help_message_separates_inherited_flags_from_localstest_help_message_renders_examples_and_learn_moretest_help_message_omits_empty_optional_sectionsThe two pre-existing assertions in
test_help_messagestill pass unchanged, which is the strongest evidence that apps without the new fields see identical output.Run with:
v -enable-globals test vlib/cli/