-
Notifications
You must be signed in to change notification settings - Fork 0
/
args.go
57 lines (53 loc) · 1.16 KB
/
args.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
package fakegit
import (
"fmt"
"os"
"regexp"
"strings"
)
func ProcUser(argx []string) ([]string, string, string, bool) {
var name, email string
if IsIn("--user", argx) {
ind := IndexOf("--user", argx)
Pop(ind, &argx)
if ind >= len(argx) {
Fatal(ARGUMENT_ERROR_INVALID)
}
info := Pop(ind, &argx)
re, _ := regexp.Compile(`([\w -]+)(<.*@.*>|<>)?`)
res := re.FindStringSubmatch(info)
name = strings.TrimSpace(res[1])
email = res[2]
if name == "" {
Fatal(ARGUMENT_ERROR_USERNAME)
}
if email == "" {
fmt.Printf("Finding user %s...\n", name)
fake := NewGithubUser(name)
name, email = fake.GetIdentity()
fmt.Printf("User found: %s <%s>\n", name, email)
} else {
email = email[1 : len(email)-1]
}
}
return argx, name, email, IsIn("change", argx)
}
func ShowHelp() {
fmt.Print(HELP_DOCS)
os.Exit(0)
}
func ProcArgs() ([]string, string, string, bool) {
if len(os.Args) < 2 {
ShowHelp()
}
cliArgs := os.Args[1:]
if IsIn("--help", cliArgs) || IsIn("-h", cliArgs) {
ShowHelp()
}
if IsIn("recover", cliArgs) {
NewGitConf(".git/config").Recover()
fmt.Println("Config file reset.")
os.Exit(0)
}
return ProcUser(cliArgs)
}