-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
187 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/rsteube/carapace" | ||
"github.com/rsteube/carapace-bin/completers/git_completer/cmd/action" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var branchCmd = &cobra.Command{ | ||
Use: "branch", | ||
Short: "List, create, or delete branches", | ||
Run: func(cmd *cobra.Command, args []string) {}, | ||
} | ||
|
||
func init() { | ||
carapace.Gen(branchCmd).Standalone() | ||
|
||
branchCmd.Flags().BoolS("D", "D", false, "Shortcut for --delete --force.") | ||
branchCmd.Flags().BoolS("M", "M", false, "Shortcut for --move --force.") | ||
branchCmd.Flags().BoolS("C", "C", false, "Shortcut for --copy --force.") | ||
branchCmd.Flags().String("abbrev", "", "Alter the sha1s minimum display length in the output listing.") | ||
branchCmd.Flags().BoolP("all", "a", false, "List both remote-tracking branches and local branches.") | ||
branchCmd.Flags().String("color", "", "Color branches to highlight current, local, and remote-tracking branches.") | ||
branchCmd.Flags().String("contains", "", "Only list branches which contain the specified commit (HEAD if not specified).") | ||
branchCmd.Flags().BoolP("copy", "c", false, "Copy a branch and the corresponding reflog.") | ||
branchCmd.Flags().Bool("create-reflog", false, "Create the branchs reflog.") | ||
branchCmd.Flags().BoolP("delete", "d", false, "Delete a branch.") | ||
branchCmd.Flags().Bool("edit-description", false, "Open an editor and edit the text to explain what the branch is for.") | ||
branchCmd.Flags().BoolP("force", "f", false, "Reset <branchname> to <startpoint>, even if <branchname> exists already.") | ||
branchCmd.Flags().String("format", "", "A string that interpolates %(fieldname) from a branch ref being shown and the object it points at.") | ||
branchCmd.Flags().BoolP("ignore-case", "i", false, "Sorting and filtering branches are case insensitive.") | ||
branchCmd.Flags().BoolP("list", "l", false, "List branches.") | ||
branchCmd.Flags().String("merged", "", "Only list branches whose tips are reachable from the specified commit (HEAD if not specified).") | ||
branchCmd.Flags().BoolP("move", "m", false, "Move/rename a branch and the corresponding reflog.") | ||
branchCmd.Flags().Bool("no-abbrev", false, "Display the full sha1s in the output listing rather than abbreviating them.") | ||
branchCmd.Flags().Bool("no-color", false, "Turn off branch colors, even when the configuration file gives the default to color output.") | ||
branchCmd.Flags().String("no-contains", "", "Only list branches which dont contain the specified commit (HEAD if not specified).") | ||
branchCmd.Flags().String("no-merged", "", "Only list branches whose tips are not reachable from the specified commit (HEAD if not specified).") | ||
branchCmd.Flags().Bool("no-track", false, "Do not set up upstream configuration, even if the branch.autoSetupMerge configuration variable is true.") | ||
branchCmd.Flags().String("points-at", "", "Only list branches of the given object.") | ||
branchCmd.Flags().BoolP("quiet", "q", false, "Be more quiet when creating or deleting a branch, suppressing non-error messages.") | ||
branchCmd.Flags().BoolP("remotes", "r", false, "List or delete (if used with -d) the remote-tracking branches.") | ||
branchCmd.Flags().String("set-upstream-to", "", "Set up <branchname>s tracking information so <upstream> is considered <branchname>s upstream branch.") | ||
branchCmd.Flags().Bool("show-current", false, "Print the name of the current branch.") | ||
branchCmd.Flags().String("sort", "", "Sort based on the key given.") | ||
branchCmd.Flags().BoolP("track", "t", false, "When creating a new branch, set up branch.<name>.remote and branch.<name>.merge configuration entries to mark the start-point branch as upstream from the new branch.") | ||
branchCmd.Flags().Bool("unset-upstream", false, "Remove the upstream information for <branchname>.") | ||
rootCmd.AddCommand(branchCmd) | ||
|
||
carapace.Gen(branchCmd).FlagCompletion(carapace.ActionMap{ | ||
"color": carapace.ActionValues("always", "auto", "never"), | ||
"contains": action.ActionCommits(), | ||
"D": action.ActionLocalBranches(), | ||
"delete": action.ActionLocalBranches(), | ||
"merged": action.ActionCommits(), | ||
"no-contains": action.ActionCommits(), | ||
"no-merged": action.ActionCommits(), | ||
"points-at": action.ActionRemoteBranches(), | ||
"set-upstream-to": action.ActionRemoteBranches(), | ||
"sort": action.ActionFieldNames(), | ||
}) | ||
|
||
carapace.Gen(branchCmd).PositionalAnyCompletion( | ||
carapace.ActionCallback(func(args []string) carapace.Action { | ||
switch len(args) { | ||
case 0: | ||
if branchCmd.Flag("set-upstream-to").Changed || | ||
branchCmd.Flag("track").Changed || | ||
branchCmd.Flag("no-track").Changed || | ||
branchCmd.Flag("unset-upstream").Changed || | ||
branchCmd.Flag("M").Changed || | ||
branchCmd.Flag("C").Changed || | ||
branchCmd.Flag("D").Changed || | ||
branchCmd.Flag("move").Changed || | ||
branchCmd.Flag("copy").Changed || | ||
branchCmd.Flag("delete").Changed || | ||
branchCmd.Flag("edit-description").Changed { | ||
return action.ActionLocalBranches() | ||
} | ||
case 1: | ||
if branchCmd.Flag("M").Changed || | ||
branchCmd.Flag("C").Changed || | ||
branchCmd.Flag("D").Changed || | ||
branchCmd.Flag("move").Changed || | ||
branchCmd.Flag("copy").Changed || | ||
branchCmd.Flag("delete").Changed { | ||
return action.ActionLocalBranches() | ||
} | ||
default: | ||
if branchCmd.Flag("D").Changed || | ||
branchCmd.Flag("delete").Changed { | ||
return action.ActionLocalBranches() | ||
} | ||
} | ||
return carapace.ActionValues() | ||
}), | ||
) | ||
|
||
} |
This file was deleted.
Oops, something went wrong.