diff --git a/aplus.go b/aplus.go index 6d308c4..96fbd92 100644 --- a/aplus.go +++ b/aplus.go @@ -64,6 +64,7 @@ func launch_aplus(course_code int) string { err := init_aplus_toolid(course_code) if err != nil { fmt.Println("Failed to get A+ base URL and tool ID. Try again with a different course code.") + fmt.Printf("Error: %s\n", err) os.Exit(1) } diff --git a/main.go b/main.go index 93defd3..0ebd8f7 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,12 @@ var token string var client http.Client func usage() { - fmt.Println("Usage: aplus [--code attendance_code --course course_code] [--list] [--listfav] [--help]") + fmt.Println("Usage: aplus --code attendance_code --course course_code [--list] [--listfav] [--help]") + fmt.Println(" -c, --code\tfive character attendance code") + fmt.Println(" -C, --course\tcanvas course ID") + fmt.Println(" -L, --list\tlists canvas courses with name and ID") + fmt.Println(" -F, --listfav\tlists favourited canvas courses with name and ID") + fmt.Println(" -h, --help\tdisplays this help message") } func main() { @@ -39,35 +44,39 @@ func main() { flag.Parse() - if (code == "" && course == -1 && !listall && !listfav) { + if code == "" && course == -1 && !listall && !listfav && !help { usage() os.Exit(1) } - if (listall) { + if listall { list_all_courses() os.Exit(0) } - if (listfav) { + if listfav { list_favorite_courses() os.Exit(0) } - if (help) { + if help { usage() os.Exit(0) } - if (len(code) != 5) { - fmt.Println("Attendance code must be 5 characters long") - os.Exit(1) - } - - if code != "" && course != -1 { + if len(code) == 5 && course != -1 { fmt.Printf("%d %s\n", course, code) submit_code(course, code) - } else { + } else if code != "" && course == -1 { + fmt.Println("Course code not provided") + usage() + os.Exit(1) + } else if code == "" && course != -1 { + fmt.Println("Attendance code not provided") + usage() + os.Exit(1) + } else if len(code) != 5 { + fmt.Println("Attendance code must be 5 characters long") usage() os.Exit(1) }