-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitcher.go
More file actions
23 lines (18 loc) · 847 Bytes
/
switcher.go
File metadata and controls
23 lines (18 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package main
import "fmt"
func SwitchProfile(run RunCmd, profile Profile) (warnings []string, err error) {
if _, err := run("git", "config", "--local", "user.name", profile.GitName); err != nil {
return nil, fmt.Errorf("failed to set user.name: %w", err)
}
if _, err := run("git", "config", "--local", "user.email", profile.GitEmail); err != nil {
return nil, fmt.Errorf("failed to set user.email: %w", err)
}
sshCmd := fmt.Sprintf("ssh -i %s -o IdentitiesOnly=yes", expandPath(profile.SSHKey))
if _, err := run("git", "config", "--local", "core.sshCommand", sshCmd); err != nil {
return nil, fmt.Errorf("failed to set SSH key: %w", err)
}
if _, err := run("gh", "auth", "switch", "--user", profile.GHUser); err != nil {
warnings = append(warnings, fmt.Sprintf("gh account switch failed: %v", err))
}
return warnings, nil
}