cmd

package
v0.3.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ShellCmd = &cobra.Command{
	Use:   "bit",
	Short: "Bit is a Git CLI that predicts what you want to do",
	Long:  `v0.3.16`,
	Run: func(cmd *cobra.Command, args []string) {
		_, bitCmdMap := AllBitSubCommands(cmd)
		allBitCmds := AllBitAndGitSubCommands(cmd)
		branchListSuggestions := BranchListSuggestions()
		completerSuggestionMap := map[string][]prompt.Suggest{
			"":         {},
			"shell":    CobraCommandToSuggestions(allBitCmds),
			"checkout": branchListSuggestions,
			"switch":   branchListSuggestions,
			"co":       branchListSuggestions,
			"merge":    branchListSuggestions,
			"add":      GitAddSuggestions(),
			"release": {
				{Text: "bump", Description: "Increment SemVer from tags and release"},
				{Text: "<version>", Description: "Name of release version e.g. v0.1.2"},
			},
			"reset": GitResetSuggestions(),
		}

		resp := SuggestionPrompt("> bit ", shellCommandCompleter(completerSuggestionMap))
		subCommand := resp
		if subCommand == "" {
			return
		}
		if strings.Index(resp, " ") > 0 {
			subCommand = subCommand[0:strings.Index(resp, " ")]
		}
		if bitCmdMap[subCommand] == nil {
			parsedArgs, err := parseCommandLine(resp)
			if err != nil {
				fmt.Println(err)
				return
			}
			sub := parsedArgs[0]
			if sub == "checkout" || sub == "switch" || sub == "co" {
				branchName := strings.TrimSpace(parsedArgs[len(parsedArgs)-1])
				if strings.HasPrefix(branchName, "origin/") {
					branchName = branchName[7:]
				}
				parsedArgs[len(parsedArgs)-1] = branchName
			}
			err = Runwithcolor("git", parsedArgs)
			if err != nil {
				fmt.Println("DEBUG: CMD may not be allow listed")
			}
			return
		}
		parsedArgs, err := parseCommandLine(resp)
		if err != nil {
			fmt.Println(err)
			return
		}
		cmd.SetArgs(parsedArgs)
		cmd.Execute()
	},
}

ShellCmd represents the base command when called without any subcommands

Functions

func AddCommandToShellHistory added in v0.3.13

func AddCommandToShellHistory(cmd string, args []string)

func AllBitAndGitSubCommands added in v0.3.13

func AllBitAndGitSubCommands(rootCmd *cobra.Command) (cc []*cobra.Command)

func AllBitSubCommands added in v0.3.13

func AllBitSubCommands(rootCmd *cobra.Command) ([]*cobra.Command, map[string]*cobra.Command)

func AllGitAliases added in v0.3.14

func AllGitAliases() (cc []*cobra.Command)

func AllGitSubCommands added in v0.3.13

func AllGitSubCommands() (cc []*cobra.Command)

func BranchListSuggestions added in v0.3.13

func BranchListSuggestions() []prompt.Suggest

func CloudBranchExists added in v0.3.13

func CloudBranchExists() bool

func CobraCommandToSuggestions added in v0.3.13

func CobraCommandToSuggestions(cmds []*cobra.Command) []prompt.Suggest

func CommonCommandsList added in v0.3.14

func CommonCommandsList() []*cobra.Command

func CurrentBranch added in v0.3.13

func CurrentBranch() string

func Execute

func Execute()

Execute adds all child commands to the shell command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the ShellCmd.

func FlagSuggestionsForCommand added in v0.3.13

func FlagSuggestionsForCommand(gitSubCmd string, flagtype string) []prompt.Suggest

func GenBumpedSemVersion added in v0.3.13

func GenBumpedSemVersion() string

func GitAddSuggestions added in v0.3.13

func GitAddSuggestions() []prompt.Suggest

func GitResetSuggestions added in v0.3.16

func GitResetSuggestions() []prompt.Suggest

func IsAheadOfCurrent added in v0.3.13

func IsAheadOfCurrent() bool

func IsBehindCurrent added in v0.3.13

func IsBehindCurrent() bool

func IsDiverged added in v0.3.13

func IsDiverged() bool

func IsYes added in v0.3.13

func IsYes(resp string) bool

func MostRecentCommonAncestorCommit added in v0.3.17

func MostRecentCommonAncestorCommit(branchA, branchB string) string

func NothingToCommit added in v0.3.13

func NothingToCommit() bool

func PromptUser added in v0.3.13

func PromptUser(prompt string) string

fixme when writing input the user cant backspace in the normal fashion

func RunScriptWithString added in v0.3.13

func RunScriptWithString(path string, script string, args ...string)

func Runwithcolor added in v0.3.13

func Runwithcolor(cmdName string, args []string) error

func StashList added in v0.3.13

func StashList() []string

func StashableChanges added in v0.3.13

func StashableChanges() bool

func SuggestionPrompt added in v0.3.13

func SuggestionPrompt(prefix string, completer func(d prompt.Document) []prompt.Suggest) string

Types

type Branch added in v0.3.13

type Branch struct {
	Author       string
	Name         string
	RelativeDate string
}

func BranchList added in v0.3.13

func BranchList() []Branch

type FileChange added in v0.3.13

type FileChange struct {
	Name   string
	Status string
}

func FileChangesList added in v0.3.13

func FileChangesList() []FileChange

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL