git-bug/commands/pull.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

60 lines
1.1 KiB
Go

package commands
import (
"errors"
"github.com/spf13/cobra"
"github.com/MichaelMure/git-bug/entity"
)
func newPullCommand() *cobra.Command {
env := newEnv()
cmd := &cobra.Command{
Use: "pull [REMOTE]",
Short: "Pull bugs update from a git remote.",
PreRunE: loadBackend(env),
RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error {
return runPull(env, args)
}),
ValidArgsFunction: completeGitRemote(env),
}
return cmd
}
func runPull(env *Env, args []string) error {
if len(args) > 1 {
return errors.New("Only pulling from one remote at a time is supported")
}
remote := "origin"
if len(args) == 1 {
remote = args[0]
}
env.out.Println("Fetching remote ...")
stdout, err := env.backend.Fetch(remote)
if err != nil {
return err
}
env.out.Println(stdout)
env.out.Println("Merging data ...")
for result := range env.backend.MergeAll(remote) {
if result.Err != nil {
env.err.Println(result.Err)
}
if result.Status != entity.MergeStatusNothing {
env.out.Printf("%s: %s\n", result.Id.Human(), result)
}
}
return nil
}