git-bug/commands/push.go
Johannes Altmanninger bc6ba02bd8
Add command-specific argument completions
Complete bug IDs, bridges, users, labels where appropriate.

This works in bash and fish. ZSH is not yet supported by Cobra.
In fish, descriptions (the part of a completion after the "\t") are shown
as completion label, and can be searched with Ctrl+S.

Reproduce with

	fish -C 'source misc/fish_completion/git-bug'
	git bug select ^I

(tested with fish version 3.3.1)

Also works with bash, but only for "git-bug" (with the dash)

	bash --rcfile <(echo source misc/bash_completion/git-bug)
	git-bug select ^I

Closes #493
2022-05-01 10:54:13 +02:00

44 lines
748 B
Go

package commands
import (
"errors"
"github.com/spf13/cobra"
)
func newPushCommand() *cobra.Command {
env := newEnv()
cmd := &cobra.Command{
Use: "push [REMOTE]",
Short: "Push bugs update to a git remote.",
PreRunE: loadBackend(env),
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
return runPush(env, args)
}),
ValidArgsFunction: completeGitRemote(env),
}
return cmd
}
func runPush(env *Env, args []string) error {
if len(args) > 1 {
return errors.New("Only pushing to one remote at a time is supported")
}
remote := "origin"
if len(args) == 1 {
remote = args[0]
}
stdout, err := env.backend.Push(remote)
if err != nil {
return err
}
env.out.Println(stdout)
return nil
}