mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
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:
22 files changed
+75
-212
No files matched your search
+3
-14
@@ -128,7 +128,7 @@ $ tea workflow view ci --web`,
|
||||
cmd.Flags().BoolVar(&showYAML, "yaml", false, "Print the workflow file")
|
||||
cmd.Flags().StringVarP(&ref, "ref", "r", "", "Branch, tag or commit of the workflow file that --yaml prints (default: the default branch)")
|
||||
cmd.Flags().BoolVarP(&web, "web", "w", false, "Open the workflow file in the browser")
|
||||
cmd.ValidArgsFunction = a.completeWorkflowArg()
|
||||
cmd.ValidArgsFunction = firstArg(a.completeWorkflows())
|
||||
_ = cmd.RegisterFlagCompletionFunc("ref", a.completeBranches())
|
||||
return cmd
|
||||
}
|
||||
@@ -269,7 +269,7 @@ $ tea workflow run nightly --follow`,
|
||||
cmd.Flags().BoolVar(&follow, "follow", false, "Follow the logs of the run's jobs after dispatching it")
|
||||
cmd.Flags().DurationVar(&interval, "interval", 2*time.Second, "Polling interval with --follow")
|
||||
cmd.Flags().DurationVar(&timeout, "timeout", 30*time.Minute, "Maximum time to follow")
|
||||
cmd.ValidArgsFunction = a.completeWorkflowArg()
|
||||
cmd.ValidArgsFunction = firstArg(a.completeWorkflows())
|
||||
_ = cmd.RegisterFlagCompletionFunc("ref", a.completeBranches())
|
||||
_ = cmd.RegisterFlagCompletionFunc("field", a.completeWorkflowInputs())
|
||||
_ = cmd.RegisterFlagCompletionFunc("input", a.completeWorkflowInputs())
|
||||
@@ -445,7 +445,7 @@ func (a *application) workflowStateCommand(enable bool) *cobra.Command {
|
||||
$ tea workflow %s Nightly`, verb, verb),
|
||||
Args: argsExact(1),
|
||||
Annotations: map[string]string{"tea.arguments": workflowArguments},
|
||||
ValidArgsFunction: a.completeWorkflowArg(),
|
||||
ValidArgsFunction: firstArg(a.completeWorkflows()),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
t, err := a.resolve(cmd.Context(), true)
|
||||
if err != nil {
|
||||
@@ -472,17 +472,6 @@ $ tea workflow %s Nightly`, verb, verb),
|
||||
}
|
||||
}
|
||||
|
||||
// completeWorkflowArg completes the workflow argument with workflow files.
|
||||
func (a *application) completeWorkflowArg() cobra.CompletionFunc {
|
||||
workflows := a.completeWorkflows()
|
||||
return func(cmd *cobra.Command, args []string, toComplete string) ([]cobra.Completion, cobra.ShellCompDirective) {
|
||||
if len(args) > 0 {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
return workflows(cmd, args, toComplete)
|
||||
}
|
||||
}
|
||||
|
||||
// completeWorkflowInputs completes the inputs of the workflow given as the first argument as
|
||||
// name=, then the values of a choice or boolean input.
|
||||
func (a *application) completeWorkflowInputs() cobra.CompletionFunc {
|
||||
|
||||
Reference in new issue
Block a user