~emersion/hut

3c1f0b0291216ad01b14527389c962ce1fb919db — Thorben Günther 3 months ago 453ebed
builds cancel, paste delete: Improve completion

For commands that support multiple args, it does not make sense to
offer completions which contain items that are already selected.
3 files changed, 18 insertions(+), 0 deletions(-)

M builds.go
M main.go
M paste.go
M builds.go => builds.go +4 -0
@@ 651,6 651,10 @@ func completeJobs(cmd *cobra.Command, onlyRunning bool) ([]string, cobra.ShellCo
			continue
		}

		if cmd.Name() == "cancel" && hasCmdArg(cmd, strconv.Itoa(int(job.Id))) {
			continue
		}

		str := fmt.Sprintf("%d\t", job.Id)
		if tagString := formatJobTags(&job); tagString != "" {
			str += tagString

M main.go => main.go +10 -0
@@ 201,3 201,13 @@ func stripProtocol(s string) string {

	return s
}

func hasCmdArg(cmd *cobra.Command, arg string) bool {
	for _, v := range cmd.Flags().Args() {
		if v == arg {
			return true
		}
	}

	return false
}

M paste.go => paste.go +4 -0
@@ 255,6 255,10 @@ func completePasteID(cmd *cobra.Command, args []string, toComplete string) ([]st
	}

	for _, paste := range pastes.Results {
		if cmd.Name() == "delete" && hasCmdArg(cmd, paste.Id) {
			continue
		}

		str := paste.Id
		var files string