mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01: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
@@ -228,7 +228,7 @@ $ tea run view 34 --json jobs --jq '.jobs[] | {name, conclusion}'`,
|
||||
cmd.Flags().BoolVar(&noJobs, "no-jobs", false, "Leave out the jobs")
|
||||
cmd.Flags().BoolVarP(&web, "web", "w", false, "Open the run in the browser")
|
||||
cmd.Flags().BoolVar(&log, "log", false, "Print the logs of every job instead, like tea run logs")
|
||||
cmd.ValidArgsFunction = a.completeRunArg()
|
||||
cmd.ValidArgsFunction = firstArg(a.completeRuns())
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -459,17 +459,6 @@ func (a *application) runPicker() (terminal.Chooser, bool) {
|
||||
return chooser, err == nil && a.policy(s).CanPrompt(a.deps.Streams)
|
||||
}
|
||||
|
||||
// completeRunArg completes the run argument of a run command with recent runs.
|
||||
func (a *application) completeRunArg() cobra.CompletionFunc {
|
||||
runs := a.completeRuns()
|
||||
return func(cmd *cobra.Command, args []string, toComplete string) ([]cobra.Completion, cobra.ShellCompDirective) {
|
||||
if len(args) > 0 {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
return runs(cmd, args, toComplete)
|
||||
}
|
||||
}
|
||||
|
||||
// accountNote reminds people who pass the global --user, which selects the account tea acts as,
|
||||
// of the flag they may have meant, as gh's --user means something else.
|
||||
func (a *application) accountNote(cmd *cobra.Command, t target, hint string) {
|
||||
@@ -507,7 +496,7 @@ $ tea run watch 34 --timeout 10m && echo deployed`,
|
||||
}
|
||||
cmd.Flags().DurationVarP(&interval, "interval", "i", 3*time.Second, "Refresh interval")
|
||||
cmd.Flags().DurationVar(&timeout, "timeout", time.Hour, "Maximum time to wait")
|
||||
cmd.ValidArgsFunction = a.completeRunArg()
|
||||
cmd.ValidArgsFunction = firstArg(a.completeRuns())
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -622,7 +611,7 @@ $ tea run cancel 34 --force`,
|
||||
},
|
||||
}
|
||||
cmd.Flags().BoolVar(&force, "force", false, "Cancel without waiting for the runner to acknowledge")
|
||||
cmd.ValidArgsFunction = a.completeRunArg()
|
||||
cmd.ValidArgsFunction = firstArg(a.completeRuns())
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -681,7 +670,7 @@ $ tea run rerun 34 --job build`,
|
||||
}
|
||||
cmd.Flags().BoolVar(&failed, "failed", false, "Rerun only the failed jobs")
|
||||
cmd.Flags().StringVarP(&job, "job", "j", "", "Rerun only this job, by `name or ID`")
|
||||
cmd.ValidArgsFunction = a.completeRunArg()
|
||||
cmd.ValidArgsFunction = firstArg(a.completeRuns())
|
||||
_ = cmd.RegisterFlagCompletionFunc("job", a.completeJobs())
|
||||
return cmd
|
||||
}
|
||||
@@ -736,7 +725,7 @@ $ tea run delete 34 --yes`,
|
||||
return nil
|
||||
},
|
||||
}
|
||||
cmd.ValidArgsFunction = a.completeRunArg()
|
||||
cmd.ValidArgsFunction = firstArg(a.completeRuns())
|
||||
return cmd
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user