-
Notifications
You must be signed in to change notification settings - Fork 1.6k
✨ feat(cli): Show hint message when file completion not applicable to subcommand #5587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -69,6 +69,20 @@ If no output directory is provided, the current working directory will be cleane | |||||||||
| }, | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Show hint message on how to list flags instead of showing file completion for | ||||||||||
| // commands that don't take files as arguments | ||||||||||
| scaffoldCmd.ValidArgsFunction = func( | ||||||||||
| _ *cobra.Command, | ||||||||||
| args []string, | ||||||||||
| toComplete string, | ||||||||||
| ) ([]cobra.Completion, cobra.ShellCompDirective) { | ||||||||||
| completions := []cobra.Completion{} | ||||||||||
| if len(args) == 0 && toComplete == "" { | ||||||||||
| completions = cobra.AppendActiveHelp(completions, "Type '--' and press TAB to list flags") | ||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or we could do something like:
Suggested change
Or:
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, if possible we need to check how to solve in the CLI without need to implement each command.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There may be way to work around this and make it global, but I don't think that's very idiomatic and will possibly have side-effects. |
||||||||||
| } | ||||||||||
| return completions, cobra.ShellCompDirectiveNoFileComp | ||||||||||
| } | ||||||||||
|
|
||||||||||
| scaffoldCmd.Flags().StringVar(&opts.InputDir, "input-dir", "", | ||||||||||
| "Path to the directory containing the PROJECT file. "+ | ||||||||||
| "Defaults to the current working directory. WARNING: delete existing files (except .git and PROJECT).") | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -144,6 +144,20 @@ Defaults: | |||||
| }, | ||||||
| } | ||||||
|
|
||||||
| // Show hint message on how to list flags instead of showing file completion for | ||||||
| // commands that don't take files as arguments | ||||||
| updateCmd.ValidArgsFunction = func( | ||||||
| _ *cobra.Command, | ||||||
| args []string, | ||||||
| toComplete string, | ||||||
| ) ([]cobra.Completion, cobra.ShellCompDirective) { | ||||||
| completions := []cobra.Completion{} | ||||||
| if len(args) == 0 && toComplete == "" { | ||||||
|
||||||
| if len(args) == 0 && toComplete == "" { | |
| if len(args) == 0 && (toComplete == "" || toComplete[0] != '-') { |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -37,6 +37,20 @@ func (c CLI) newCreateAPICmd() *cobra.Command { | |||||
| ), | ||||||
| } | ||||||
|
|
||||||
| // Show hint message on how to list flags instead of showing file completion for | ||||||
| // commands that don't take files as arguments | ||||||
| cmd.ValidArgsFunction = func( | ||||||
| _ *cobra.Command, | ||||||
| args []string, | ||||||
| toComplete string, | ||||||
| ) ([]cobra.Completion, cobra.ShellCompDirective) { | ||||||
| completions := []cobra.Completion{} | ||||||
| if len(args) == 0 && toComplete == "" { | ||||||
|
||||||
| if len(args) == 0 && toComplete == "" { | |
| if len(args) == 0 && (toComplete == "" || toComplete[0] != '-') { |
Copilot
AI
Apr 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This same ValidArgsFunction block (including the literal hint string) is duplicated across multiple commands/files in this PR. To keep behavior and wording consistent over time, consider extracting this into a small helper (e.g. a function that sets the ValidArgsFunction) and/or a shared const for the hint message.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -37,6 +37,20 @@ func (c CLI) newEditCmd() *cobra.Command { | |||||
| ), | ||||||
| } | ||||||
|
|
||||||
| // Show hint message on how to list flags instead of showing file completion for | ||||||
| // commands that don't take files as arguments | ||||||
| cmd.ValidArgsFunction = func( | ||||||
| _ *cobra.Command, | ||||||
| args []string, | ||||||
| toComplete string, | ||||||
| ) ([]cobra.Completion, cobra.ShellCompDirective) { | ||||||
| completions := []cobra.Completion{} | ||||||
| if len(args) == 0 && toComplete == "" { | ||||||
|
||||||
| if len(args) == 0 && toComplete == "" { | |
| if len(args) == 0 && (toComplete == "" || toComplete[0] != '-') { |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -42,6 +42,20 @@ For further help about a specific plugin, set --plugins. | |||||
| Run: func(_ *cobra.Command, _ []string) {}, | ||||||
| } | ||||||
|
|
||||||
| // Show hint message on how to list flags instead of showing file completion for | ||||||
| // commands that don't take files as arguments | ||||||
| cmd.ValidArgsFunction = func( | ||||||
| _ *cobra.Command, | ||||||
| args []string, | ||||||
| toComplete string, | ||||||
| ) ([]cobra.Completion, cobra.ShellCompDirective) { | ||||||
| completions := []cobra.Completion{} | ||||||
| if len(args) == 0 && toComplete == "" { | ||||||
|
||||||
| if len(args) == 0 && toComplete == "" { | |
| if len(args) == 0 && (toComplete == "" || !strings.HasPrefix(toComplete, "-")) { |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -33,5 +33,20 @@ func (c CLI) newVersionCmd() *cobra.Command { | |||||
| return nil | ||||||
| }, | ||||||
| } | ||||||
|
|
||||||
| // Show hint message on how to list flags instead of showing file completion for | ||||||
| // commands that don't take files as arguments | ||||||
| cmd.ValidArgsFunction = func( | ||||||
| _ *cobra.Command, | ||||||
| args []string, | ||||||
| toComplete string, | ||||||
| ) ([]cobra.Completion, cobra.ShellCompDirective) { | ||||||
| completions := []cobra.Completion{} | ||||||
| if len(args) == 0 && toComplete == "" { | ||||||
|
||||||
| if len(args) == 0 && toComplete == "" { | |
| if len(args) == 0 && (toComplete == "" || toComplete[0] != '-') { |
Copilot
AI
Apr 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR description lists the subcommands being updated, but version is also modified here. Either include version in the description (if intended) or drop this change to keep the scope aligned with the PR narrative.
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,6 +37,20 @@ func (c CLI) newCreateWebhookCmd() *cobra.Command { | |||||||||||
| ), | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // Show hint message on how to list flags instead of showing file completion for | ||||||||||||
| // commands that don't take files as arguments | ||||||||||||
| cmd.ValidArgsFunction = func( | ||||||||||||
| _ *cobra.Command, | ||||||||||||
| args []string, | ||||||||||||
| toComplete string, | ||||||||||||
| ) ([]cobra.Completion, cobra.ShellCompDirective) { | ||||||||||||
| completions := []cobra.Completion{} | ||||||||||||
| if len(args) == 0 && toComplete == "" { | ||||||||||||
|
Comment on lines
+47
to
+48
|
||||||||||||
| completions := []cobra.Completion{} | |
| if len(args) == 0 && toComplete == "" { | |
| _ = toComplete | |
| completions := []cobra.Completion{} | |
| if len(args) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ActiveHelp hint is only appended when
toComplete == "". If the user types a partial token before TAB, this will return no completions +ShellCompDirectiveNoFileCompand show nothing. Consider appending ActiveHelp wheneverlen(args) == 0(or when the token isn't a flag) so guidance is still shown.