diff options
| author | vin <git@vineetk.net> | 2023-11-20 15:41:28 -0500 |
|---|---|---|
| committer | vin <git@vineetk.net> | 2023-11-20 15:50:22 -0500 |
| commit | 3065b05ed45a04f401e8aec7d770b9e7a22c8ec4 (patch) | |
| tree | 60fa26f50e6315fd7eed9a2cbbe3caa7c3347344 | |
| parent | 6abb8ede02ebe38f1c84b7bdf0d8be96b9997ec1 (diff) | |
update usage message
| -rw-r--r-- | aplus.go | 1 | ||||
| -rw-r--r-- | main.go | 33 |
2 files changed, 22 insertions, 12 deletions
| @@ -64,6 +64,7 @@ func launch_aplus(course_code int) string { | |||
| 64 | err := init_aplus_toolid(course_code) | 64 | err := init_aplus_toolid(course_code) |
| 65 | if err != nil { | 65 | if err != nil { |
| 66 | fmt.Println("Failed to get A+ base URL and tool ID. Try again with a different course code.") | 66 | fmt.Println("Failed to get A+ base URL and tool ID. Try again with a different course code.") |
| 67 | fmt.Printf("Error: %s\n", err) | ||
| 67 | os.Exit(1) | 68 | os.Exit(1) |
| 68 | } | 69 | } |
| 69 | 70 | ||
| @@ -14,7 +14,12 @@ var token string | |||
| 14 | var client http.Client | 14 | var client http.Client |
| 15 | 15 | ||
| 16 | func usage() { | 16 | func usage() { |
| 17 | fmt.Println("Usage: aplus [--code attendance_code --course course_code] [--list] [--listfav] [--help]") | 17 | fmt.Println("Usage: aplus --code attendance_code --course course_code [--list] [--listfav] [--help]") |
| 18 | fmt.Println(" -c, --code\tfive character attendance code") | ||
| 19 | fmt.Println(" -C, --course\tcanvas course ID") | ||
| 20 | fmt.Println(" -L, --list\tlists canvas courses with name and ID") | ||
| 21 | fmt.Println(" -F, --listfav\tlists favourited canvas courses with name and ID") | ||
| 22 | fmt.Println(" -h, --help\tdisplays this help message") | ||
| 18 | } | 23 | } |
| 19 | 24 | ||
| 20 | func main() { | 25 | func main() { |
| @@ -39,35 +44,39 @@ func main() { | |||
| 39 | 44 | ||
| 40 | flag.Parse() | 45 | flag.Parse() |
| 41 | 46 | ||
| 42 | if (code == "" && course == -1 && !listall && !listfav) { | 47 | if code == "" && course == -1 && !listall && !listfav && !help { |
| 43 | usage() | 48 | usage() |
| 44 | os.Exit(1) | 49 | os.Exit(1) |
| 45 | } | 50 | } |
| 46 | 51 | ||
| 47 | if (listall) { | 52 | if listall { |
| 48 | list_all_courses() | 53 | list_all_courses() |
| 49 | os.Exit(0) | 54 | os.Exit(0) |
| 50 | } | 55 | } |
| 51 | 56 | ||
| 52 | if (listfav) { | 57 | if listfav { |
| 53 | list_favorite_courses() | 58 | list_favorite_courses() |
| 54 | os.Exit(0) | 59 | os.Exit(0) |
| 55 | } | 60 | } |
| 56 | 61 | ||
| 57 | if (help) { | 62 | if help { |
| 58 | usage() | 63 | usage() |
| 59 | os.Exit(0) | 64 | os.Exit(0) |
| 60 | } | 65 | } |
| 61 | 66 | ||
| 62 | if (len(code) != 5) { | 67 | if len(code) == 5 && course != -1 { |
| 63 | fmt.Println("Attendance code must be 5 characters long") | ||
| 64 | os.Exit(1) | ||
| 65 | } | ||
| 66 | |||
| 67 | if code != "" && course != -1 { | ||
| 68 | fmt.Printf("%d %s\n", course, code) | 68 | fmt.Printf("%d %s\n", course, code) |
| 69 | submit_code(course, code) | 69 | submit_code(course, code) |
| 70 | } else { | 70 | } else if code != "" && course == -1 { |
| 71 | fmt.Println("Course code not provided") | ||
| 72 | usage() | ||
| 73 | os.Exit(1) | ||
| 74 | } else if code == "" && course != -1 { | ||
| 75 | fmt.Println("Attendance code not provided") | ||
| 76 | usage() | ||
| 77 | os.Exit(1) | ||
| 78 | } else if len(code) != 5 { | ||
| 79 | fmt.Println("Attendance code must be 5 characters long") | ||
| 71 | usage() | 80 | usage() |
| 72 | os.Exit(1) | 81 | os.Exit(1) |
| 73 | } | 82 | } |
