diff --git a/src/cmd/account/edit.go b/src/cmd/account/edit.go new file mode 100644 index 0000000..fe5042b --- /dev/null +++ b/src/cmd/account/edit.go @@ -0,0 +1,33 @@ +package account + +import ( + "fmt" + "os/exec" + "strings" + + "github.com/daveberrys/guh/src/utils" + "github.com/spf13/cobra" +) + +var editCmd = &cobra.Command{ + Use: "edit", + Short: "Opens up a code editor, and opens accounts.json file", + Args: cobra.ExactArgs(0), + RunE: func(c *cobra.Command, args []string) error { + path, _ := utils.AccountsFilePath() + editors := []string{"nano", "code", "zed", "zeditor", "vi", "vim", "emacs", "notepad.exe"} + // editors := []string{"this", "is", "a", "_test", "for", "fail"} + for _, editor := range editors { + if _, err := exec.Command(editor, path).Output(); err == nil { + fmt.Printf("Opening editor: %s\n", editor) + return nil + } + } + + fmt.Println("No supported editors found") + fmt.Println("Here are the supported editors we have;") + fmt.Println(strings.Join(editors, ", ")) + // for _, editor := range editors { fmt.Println("- " + editor) } + return nil + }, +} \ No newline at end of file diff --git a/src/cmd/account/root.go b/src/cmd/account/root.go index 1d62d41..b6287bc 100644 --- a/src/cmd/account/root.go +++ b/src/cmd/account/root.go @@ -9,6 +9,7 @@ func init() { cmd.RootCmd.AddCommand(accountCmd) accountCmd.AddCommand(saveCmd) accountCmd.AddCommand(switchCmd) + accountCmd.AddCommand(editCmd) } var accountCmd = &cobra.Command{ diff --git a/src/cmd/branch/delete.go b/src/cmd/branch/delete.go new file mode 100644 index 0000000..06573ac --- /dev/null +++ b/src/cmd/branch/delete.go @@ -0,0 +1,19 @@ +package branch + +import ( + "fmt" + + "github.com/daveberrys/guh/src/utils" + "github.com/spf13/cobra" +) + +var deleteCmd = &cobra.Command{ + Use: "delete [name]", + Short: "Delete a branch", + Args: cobra.ExactArgs(1), + RunE: func(c *cobra.Command, args []string) error { + utils.RunGitSequence(false, []string{"branch", "-D", args[0]}) + fmt.Printf("Deleted branch: %s\n", args[0]) + return nil + }, +} \ No newline at end of file diff --git a/src/cmd/branch/root.go b/src/cmd/branch/root.go index 0c58f18..02ec0e7 100644 --- a/src/cmd/branch/root.go +++ b/src/cmd/branch/root.go @@ -10,6 +10,7 @@ func init() { branchCmd.AddCommand(createCmd) branchCmd.AddCommand(switchCmd) branchCmd.AddCommand(renameCmd) + branchCmd.AddCommand(deleteCmd) } var branchCmd = &cobra.Command{