create linking repo, cleanupo code

This commit is contained in:
daveberrys committed 2026-07-15 22:00:30 +08:00
1 parent e2cc0e1006
commit 2c476b8d2a
6 files changed
+63 -41

No files matched your search

+24 -18
View File
@@ -6,23 +6,29 @@ import (
"path/filepath"
"github.com/daveberrys/guh/src/utils"
"github.com/spf13/cobra"
)
func performAccountSwitch(username string) error {
account, err := utils.FindAccount(username)
if err != nil { return err }
if err := utils.RunGitSequence(false,
[]string{"config", "--global", "user.name", account.Username},
[]string{"config", "--global", "user.email", account.Email},
); err != nil { return err }
homeDir, err := os.UserHomeDir()
if err != nil { return err }
credentials := fmt.Sprintf("https://%s:%s@%s\n", account.Username, account.ClassicToken, account.Platform)
if err := os.WriteFile(filepath.Join(homeDir, ".git-credentials"), []byte(credentials), 0600); err != nil { return err }
fmt.Printf("Switched to account: %s\n", account.Username)
return nil
}
var switchAccountCmd = &cobra.Command{
Use: "account [username]",
Short: "Switch to a specific user account",
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
account, err := utils.FindAccount(args[0])
if err != nil { return err }
if err := utils.RunGitSequence(false,
[]string{"config", "--global", "user.name", account.Username},
[]string{"config", "--global", "user.email", account.Email},
); err != nil { return err }
homeDir, err := os.UserHomeDir()
if err != nil { return err }
credentials := fmt.Sprintf("https://%s:%s@%s\n", account.Username, account.ClassicToken, account.Platform)
if err := os.WriteFile(filepath.Join(homeDir, ".git-credentials"), []byte(credentials), 0600); err != nil { return err }
fmt.Printf("Switched to account: %s\n", account.Username)
return nil
},
}