fix: correct usage display to show [command] instead of [flags]#4733
Merged
Conversation
When running nerdctl without any command, the usage text incorrectly showed "Usage: nerdctl [flags]" instead of "Usage: nerdctl [command]". This happened because the usage function checked c.Runnable() to decide the format, but the root command has RunE set (for handling unknown subcommands), making it "runnable" even though it semantically requires a subcommand. The fix prioritizes checking HasSubCommands() first, which correctly displays "[command]" for commands that have subcommands, regardless of whether they also have a Run function defined. Fixes #3185 Signed-off-by: Nivesh Dandyan <niveshdandyan@gmail.com>
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.
Summary
Fix the usage display when running
nerdctlwithout any command.Fixes #3185
Problem
When running
nerdctlwithout any arguments, the usage text showed:But it should show:
Root Cause
The
usage()function usedc.Runnable()to decide whether to show[flags]or[command]. However, the root command hasRunEset tohelpers.UnknownSubcommandAction(for handling unknown subcommands), which makes it "runnable" from cobra's perspective.Solution
Changed the logic to prioritize checking
HasSubCommands()first. Commands with subcommands should always show[command]in their usage, regardless of whether they have a Run function.Testing