-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (64 loc) · 1.93 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"flag"
"fmt"
"github.com/alxlchnr/change-git-user/git"
"os"
"path/filepath"
)
var user string
var token string
var email string
var name string
var path string
var help bool
var global bool
var unset bool
func init() {
flag.StringVar(&user, "user", "", "the API username of the new user")
flag.StringVar(&token, "token", "", "the API token of the new user")
flag.StringVar(&email, "email", "", "the email of the new user")
flag.StringVar(&name, "name", "", "the name of the new user")
flag.StringVar(&path, "path", ".", "path where to look for git repositories")
flag.BoolVar(&global, "global", true, "apply user name and email globally")
flag.BoolVar(&unset, "unset", false, "unset user name and email")
flag.BoolVar(&help, "help", false, "show help")
}
var initChangeGitUser = func(params *git.ChangeGitParameters) *git.ChangeGitUser {
return &git.ChangeGitUser{Parameters: params, GitCommands: git.GitCommands(&git.GitCommandsImpl{})}
}
var walkDirectories = filepath.Walk
func main() {
flag.Parse()
if help {
fmt.Println("change-git-user")
flag.PrintDefaults()
} else {
doChangeGitUser(user, token, email, name, path, global, unset)
}
}
func doChangeGitUser(user string, token string, email string, name string, path string, global bool, unset bool) {
params := &git.ChangeGitParameters{
User: user,
Token: token,
Email: email,
Name: name,
Path: path,
Global: global,
Unset: unset,
}
fmt.Printf("parameters: %v\n", params)
changeGitUser := initChangeGitUser(params)
if !changeGitUser.GitCommands.CheckForGitInstallation() {
panic("You need to have GIT installed on your computer.")
}
if global {
go changeGitUser.ChangeGlobalUserConfig()
}
walkDirectories(path, func(currentPath string, info os.FileInfo, err error) error {
if info.IsDir() && filepath.Base(currentPath) == ".git" {
go changeGitUser.ChangeUserConfigAndRemotes(filepath.Dir(currentPath))
}
return nil
})
}