refactor(completion): name path arguments explicitly and share firstArg

The six commands that take a file or directory argument set their
completer directly instead of a Use-line parser wrapping every
command, the first-argument-only wrappers become one firstArg helper,
and only the bash completion help keeps a custom text.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-12 10:50:37 +02:00
1 parent 1f4b5f868f
commit 9ac5b79e9e
22 files changed
+75 -212

No files matched your search

+2 -14
View File
@@ -187,22 +187,10 @@ $ tea issue view https://gitea.com/OWNER/REPO/issues/12 --web`, Annotations: map
}}
cmd.Flags().BoolVarP(&web, "web", "w", false, "Open the issue in the browser")
cmd.Flags().BoolVarP(&comments, "comments", "c", false, "View issue comments")
cmd.ValidArgsFunction = a.completeIssueArgs("open", false)
cmd.ValidArgsFunction = firstArg(a.completeIssues("open"))
return cmd
}
// completeIssueArgs completes issue numbers in state for the first argument, or for every
// argument when variadic.
func (a *application) completeIssueArgs(state string, variadic bool) cobra.CompletionFunc {
complete := a.completeIssues(state)
return func(cmd *cobra.Command, args []string, toComplete string) ([]cobra.Completion, cobra.ShellCompDirective) {
if len(args) > 0 && !variadic {
return nil, cobra.ShellCompDirectiveNoFileComp
}
return complete(cmd, args, toComplete)
}
}
func (a *application) issueCreateCommand() *cobra.Command {
var title, body, bodyFile, deadline, templateName, ref, milestone string
var useEditor, web bool
@@ -446,7 +434,7 @@ $ tea issue %[1]s 12 13 --comment "Done in #14"`, verb), Annotations: map[string
return errors.Join(append(failures, writeBatchJSON(a, cmd, len(numbers), results))...)
}}
cmd.Flags().StringVarP(&comment, "comment", "c", "", "Leave a comment before the issue is "+state)
cmd.ValidArgsFunction = a.completeIssueArgs(completeState, true)
cmd.ValidArgsFunction = a.completeIssues(completeState)
return cmd
}