-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_args.go
116 lines (103 loc) · 2.33 KB
/
parse_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"flag"
"fmt"
"strconv"
"strings"
)
var (
help = flag.Bool(
"help",
false,
"Show usage help",
)
token = flag.String(
"token",
"",
"The oauth admin token which authorizes this application to connect to github",
)
org = flag.String(
"org",
"",
"The name of the GitHub organization",
)
repos = flag.String(
"repos",
"",
"The list of student repositories, delimited by commas",
)
labs = flag.String(
"labs",
"",
"The list of labs to check, delimited by commas",
)
languages = flag.String(
"languages",
"",
"The list of languages of the labs, delimited by commas. 0 = Java, 1 = Go, 2 = C++, 3 = C",
)
endpoint = flag.String(
"endpoint",
"",
"The endpoint to listen on.",
)
)
func usage() {
flag.PrintDefaults()
fmt.Printf("Example: ./antiplagiarism -token=0123456789ABCDEF -org=DAT320 ")
fmt.Printf("-repos=Student1,Student2,Student3 -labs=LabA,LabB,LabC -languages=0,1,0\n")
fmt.Printf("Example: ./antiplagiarism -endpoint=localhost:11111\n")
}
// parseArgs() parses the command line arguments.
// The return argument indicates whether or not the function was successful.
func parseArgs(args *commandLineArgs) bool {
flag.Usage = usage
flag.Parse()
if *help {
flag.Usage()
return false
}
if *endpoint != "" {
args.endpoint = *endpoint
// The other values are not needed, so just return.
return true
}
if *org == "" {
fmt.Printf("No GitHub organization provided.\n")
return false
}
args.githubOrg = *org
if *labs == "" {
fmt.Printf("No lab names provided.\n")
return false
}
args.labNames = strings.Split(*labs, ",")
if *token == "" {
fmt.Printf("No token provided.\n")
return false
}
args.githubToken = *token
if *repos == "" {
fmt.Printf("No student repositories provided.\n")
return false
}
args.studentRepos = strings.Split(*repos, ",")
if *languages == "" {
fmt.Printf("No languages provided.\n")
return false
}
langStr := strings.Split(*languages, ",")
if len(args.labNames) != len(langStr) {
fmt.Printf("The number of labs does not equal the number of languages provided.\n")
return false
}
for _, lang := range langStr {
langNum, err := strconv.Atoi(lang)
if err != nil {
fmt.Printf("Error parsing languages: %v.\n", err)
return false
}
args.labLanguages = append(args.labLanguages, langNum)
}
return true
}