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

+3 -15
View File
@@ -161,7 +161,7 @@ $ tea milestone view 3 --web`, Annotations: map[string]string{"tea.arguments": m
}}
cmd.Flags().BoolVar(&byName, "by-name", false, "Match a numeric argument as a milestone title rather than an ID")
cmd.Flags().BoolVarP(&web, "web", "w", false, "Open the milestone in the browser")
cmd.ValidArgsFunction = a.completeMilestoneArgs(false)
cmd.ValidArgsFunction = firstArg(a.completeMilestones())
return cmd
}
@@ -340,7 +340,7 @@ $ tea milestone edit 3 --editor`, Annotations: map[string]string{"tea.arguments"
}}
fields.register(cmd)
cmd.Flags().BoolVar(&byName, "by-name", false, "Match a numeric argument as a milestone title rather than an ID")
cmd.ValidArgsFunction = a.completeMilestoneArgs(false)
cmd.ValidArgsFunction = firstArg(a.completeMilestones())
return cmd
}
@@ -367,7 +367,7 @@ $ tea milestone delete 7 --yes`, Annotations: map[string]string{"tea.confirm": "
return a.jsonResult(cmd, item)
}}
cmd.Flags().BoolVar(&byName, "by-name", false, "Match a numeric argument as a milestone title rather than an ID")
cmd.ValidArgsFunction = a.completeMilestoneArgs(false)
cmd.ValidArgsFunction = firstArg(a.completeMilestones())
return cmd
}
@@ -378,15 +378,3 @@ func findMilestone(cmd *cobra.Command, s services.Milestones, raw string, byName
}
return s.FindOne(cmd.Context(), raw, byName)
}
// completeMilestoneArgs completes milestone titles for the first argument, or for every argument
// when variadic.
func (a *application) completeMilestoneArgs(variadic bool) cobra.CompletionFunc {
complete := a.completeMilestones()
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)
}
}