From f309a97b8bc830782810b2f94b51f22474870856 Mon Sep 17 00:00:00 2001 From: rsteube Date: Fri, 7 May 2021 00:38:17 +0200 Subject: [PATCH] git: added switch --- .../cmd/{switch_generated.go => switch.go} | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) rename completers/git_completer/cmd/{switch_generated.go => switch.go} (60%) diff --git a/completers/git_completer/cmd/switch_generated.go b/completers/git_completer/cmd/switch.go similarity index 60% rename from completers/git_completer/cmd/switch_generated.go rename to completers/git_completer/cmd/switch.go index 3dfcb33d..74bd4cbe 100644 --- a/completers/git_completer/cmd/switch_generated.go +++ b/completers/git_completer/cmd/switch.go @@ -1,23 +1,26 @@ package cmd import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/git" "github.com/spf13/cobra" ) var switchCmd = &cobra.Command{ Use: "switch", Short: "Switch branches", - Run: func(cmd *cobra.Command, args []string) { - }, + Run: func(cmd *cobra.Command, args []string) {}, } func init() { + carapace.Gen(switchCmd).Standalone() + switchCmd.Flags().String("conflict", "", "conflict style (merge or diff3)") - switchCmd.Flags().BoolP("create", "c", false, " create and switch to a new branch") + switchCmd.Flags().StringP("create", "c", "", "create and switch to a new branch") switchCmd.Flags().BoolP("detach", "d", false, "detach HEAD at named commit") switchCmd.Flags().Bool("discard-changes", false, "throw away local modifications") switchCmd.Flags().BoolP("force", "f", false, "force checkout (throw away local modifications)") - switchCmd.Flags().BoolP("force-create", "C", false, " create/reset and switch to a branch") + switchCmd.Flags().StringP("force-create", "C", "", "create/reset and switch to a branch") switchCmd.Flags().Bool("guess", false, "second guess 'git switch '") switchCmd.Flags().Bool("ignore-other-worktrees", false, "do not check if another worktree is holding the given ref") switchCmd.Flags().BoolP("merge", "m", false, "perform a 3-way merge with the new branch") @@ -28,4 +31,17 @@ func init() { switchCmd.Flags().String("recurse-submodules", "", "control recursive updating of submodules") switchCmd.Flags().BoolP("track", "t", false, "set upstream info for new branch") rootCmd.AddCommand(switchCmd) + + switchCmd.Flag("recurse-submodules").NoOptDefVal = " " + + carapace.Gen(switchCmd).FlagCompletion(carapace.ActionMap{ + "create": git.ActionRefs(git.RefOption{LocalBranches: true}), + "force-create": git.ActionRefs(git.RefOption{LocalBranches: true}), + "conflict": carapace.ActionValues("merge", "diff3"), + "orphan": git.ActionRefs(git.RefOption{LocalBranches: true}), + }) + + carapace.Gen(switchCmd).PositionalCompletion( + git.ActionRefs(git.RefOption{LocalBranches: true}), + ) }