diff --git a/cmd/fix.go b/cmd/fix.go new file mode 100644 index 0000000..60825a8 --- /dev/null +++ b/cmd/fix.go @@ -0,0 +1,31 @@ +package cmd + +import ( + "github.com/rs/zerolog/log" + "github.com/spf13/cobra" +) + +var fixCmd = &cobra.Command{ + Use: "fix sub-command", + Short: "For all the times you did something you really wish you didn't", + Args: cobra.NoArgs, +} + +var undo_commitCmd = &cobra.Command{ + Use: "undo-commit", + Short: "soft undos last commit if not pushed already", + Run: func(cmd *cobra.Command, args []string) { + if IsAheadOfCurrent() { + err := execCommand("git", "reset", "--soft", "HEAD~1").Run() + if err != nil { + log.Debug().Err(err).Send() + } + } + }, + Args: cobra.NoArgs, +} + +func init() { + BitCmd.AddCommand(fixCmd) + fixCmd.AddCommand(undo_commitCmd) +} diff --git a/cmd/suggestion_tree.go b/cmd/suggestion_tree.go index e1eb781..77412db 100644 --- a/cmd/suggestion_tree.go +++ b/cmd/suggestion_tree.go @@ -1,11 +1,12 @@ package cmd import ( + "time" + "github.com/chriswalz/complete/v3" "github.com/rs/zerolog/log" "github.com/spf13/cobra" "github.com/thoas/go-funk" - "time" ) func toAutoCLI(suggs []complete.Suggestion) func(prefix string) []complete.Suggestion { @@ -46,6 +47,11 @@ func CreateSuggestionMap(cmd *cobra.Command) (*complete.CompTree, map[string]*co st.Flags["version"] = &complete.CompTree{Desc: "Print bit and git version"} // add dynamic predictions and bit specific commands st.Sub["add"].Dynamic = toAutoCLI(gitAddSuggestions) + st.Sub["fix"] = &complete.CompTree{ + Args: map[string]*complete.CompTree{ + "undo-commit": {Desc: "soft undos last commit if not pushed already"}, + }, + } st.Sub["checkout"].Dynamic = toAutoCLI(branchListSuggestions) st.Sub["co"].Dynamic = toAutoCLI(branchListSuggestions) st.Sub["info"] = &complete.CompTree{Desc: "Get general information about the status of your repository"} diff --git a/main.go b/main.go index 7c0e9a0..c14f1ec 100644 --- a/main.go +++ b/main.go @@ -17,10 +17,11 @@ package main import ( "fmt" + "os" + bitcmd "github.com/chriswalz/bit/cmd" "github.com/rs/zerolog" "github.com/rs/zerolog/log" - "os" ) // this should be overwritten at compile time @@ -61,7 +62,7 @@ func main() { } } - bitcliCmds := []string{"save", "sync", "help", "info", "release", "update", "pr", "complete", "gitmoji"} + bitcliCmds := []string{"save", "sync", "help", "info", "release", "update", "pr", "complete", "gitmoji", "fix"} if len(argsWithoutProg) == 0 || bitcmd.Find(bitcliCmds, argsWithoutProg[0]) != -1 { bitcli() } else {