add deleting branch, editing account via editor

This commit is contained in:
daveberrys committed 2026-07-20 02:01:44 +08:00
1 parent 6ba9baaecd
commit 2e91a67c8f
4 files changed
+54

No files matched your search

+33
View File
@@ -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
},
}
+1
View File
@@ -9,6 +9,7 @@ func init() {
cmd.RootCmd.AddCommand(accountCmd) cmd.RootCmd.AddCommand(accountCmd)
accountCmd.AddCommand(saveCmd) accountCmd.AddCommand(saveCmd)
accountCmd.AddCommand(switchCmd) accountCmd.AddCommand(switchCmd)
accountCmd.AddCommand(editCmd)
} }
var accountCmd = &cobra.Command{ var accountCmd = &cobra.Command{
+19
View File
@@ -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
},
}
+1
View File
@@ -10,6 +10,7 @@ func init() {
branchCmd.AddCommand(createCmd) branchCmd.AddCommand(createCmd)
branchCmd.AddCommand(switchCmd) branchCmd.AddCommand(switchCmd)
branchCmd.AddCommand(renameCmd) branchCmd.AddCommand(renameCmd)
branchCmd.AddCommand(deleteCmd)
} }
var branchCmd = &cobra.Command{ var branchCmd = &cobra.Command{