Skip to content

Commit

Permalink
git: cherry
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Feb 26, 2023
1 parent 870f611 commit 0f66561
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
43 changes: 43 additions & 0 deletions completers/git_completer/cmd/cherry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package cmd

import (
"strings"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
"github.com/spf13/cobra"
)

var cherryCmd = &cobra.Command{
Use: "cherry",
Short: "Find commits yet to be applied to upstream",
Run: func(cmd *cobra.Command, args []string) {},
GroupID: groups[group_low_level_interrogator].ID,
}

func init() {
carapace.Gen(cherryCmd).Standalone()

cherryCmd.Flags().String("abbrev", "", "use <n> digits to display object names")
cherryCmd.Flags().BoolP("verbose", "v", false, "be verbose")
rootCmd.AddCommand(cherryCmd)

cherryCmd.Flag("abbrev").NoOptDefVal = " "

carapace.Gen(cherryCmd).PositionalCompletion(
git.ActionRefs(git.RefOption{}.Default()),
git.ActionRefs(git.RefOption{}.Default()),
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.ActionExecCommand("git", "cherry", "--abbrev", "--verbose", c.Args[0], c.Args[1])(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
vals := make([]string, 0)
for _, line := range lines {
if fields := strings.Fields(line); len(fields) > 2 {
vals = append(vals, fields[1], strings.Join(fields[2:], " "))
}
}
return carapace.ActionValuesDescribed(vals...)
})
}),
)
}
18 changes: 0 additions & 18 deletions completers/git_completer/cmd/cherry_generated.go

This file was deleted.

0 comments on commit 0f66561

Please sign in to comment.