diff options
| -rw-r--r-- | aplus.go | 2 | ||||
| -rw-r--r-- | go.mod | 4 | ||||
| -rw-r--r-- | go.sum | 2 | ||||
| -rw-r--r-- | main.go | 63 |
4 files changed, 49 insertions, 22 deletions
| @@ -63,7 +63,7 @@ func submit_code(course_code int, attendance_code string) { | |||
| 63 | func launch_aplus(course_code int) string { | 63 | 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") | 66 | fmt.Println("Failed to get A+ base URL and tool ID. Try again with a different course code.") |
| 67 | os.Exit(1) | 67 | os.Exit(1) |
| 68 | } | 68 | } |
| 69 | 69 | ||
| @@ -1,7 +1,5 @@ | |||
| 1 | module codeberg.org/flpolyaplus/aplus | 1 | module codeberg.org/flpolyaplus/aplus |
| 2 | 2 | ||
| 3 | go 1.21.3 | 3 | go 1.21.1 |
| 4 | 4 | ||
| 5 | require golang.org/x/net v0.18.0 | 5 | require golang.org/x/net v0.18.0 |
| 6 | |||
| 7 | require github.com/pborman/getopt v1.1.0 // indirect | ||
| @@ -1,4 +1,2 @@ | |||
| 1 | github.com/pborman/getopt v1.1.0 h1:eJ3aFZroQqq0bWmraivjQNt6Dmm5M0h2JcDW38/Azb0= | ||
| 2 | github.com/pborman/getopt v1.1.0/go.mod h1:FxXoW1Re00sQG/+KIkuSqRL/LwQgSkv7uyac+STFsbk= | ||
| 3 | golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= | 1 | golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= |
| 4 | golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= | 2 | golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= |
| @@ -1,43 +1,74 @@ | |||
| 1 | package main | 1 | package main |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "flag" | ||
| 4 | "fmt" | 5 | "fmt" |
| 5 | "net/http" | 6 | "net/http" |
| 6 | "os" | 7 | "os" |
| 7 | |||
| 8 | "github.com/pborman/getopt" | ||
| 9 | ) | 8 | ) |
| 10 | 9 | ||
| 11 | var base_link string | 10 | var base_link string |
| 11 | var base_aplus_link string | ||
| 12 | var external_tools_code int | ||
| 12 | var token string | 13 | var token string |
| 13 | var client http.Client | 14 | var client http.Client |
| 14 | 15 | ||
| 16 | func usage() { | ||
| 17 | fmt.Println("Usage: aplus [--code attendance_code --course course_code] [--list] [--listfav] [--help]") | ||
| 18 | } | ||
| 19 | |||
| 15 | func main() { | 20 | func main() { |
| 16 | initialize() | 21 | initialize() |
| 17 | 22 | ||
| 18 | code := getopt.StringLong("code", 'c', "", "Code to enter") | 23 | var code string |
| 19 | course := getopt.IntLong("course", 'C', -1, "Canvas course number") | 24 | var course int |
| 20 | list_all := getopt.BoolLong("list-all", 'L', "List all courses") | 25 | var listall bool |
| 21 | list_favorites := getopt.BoolLong("list-favorites", 'F', "List favorite courses") | 26 | var listfav bool |
| 22 | help := getopt.BoolLong("help", 'h', "Help") | 27 | var help bool |
| 23 | 28 | ||
| 24 | getopt.Parse() | 29 | flag.StringVar(&code, "code", "", "5 character attendance code") |
| 30 | flag.StringVar(&code, "c", "", "5 character attendance code") | ||
| 31 | flag.IntVar(&course, "course", -1, "canvas course code") | ||
| 32 | flag.IntVar(&course, "C", -1, "canvas course code") | ||
| 33 | flag.BoolVar(&listall, "list", false, "list all canvas courses") | ||
| 34 | flag.BoolVar(&listall, "L", false, "list all canvas courses") | ||
| 35 | flag.BoolVar(&listfav, "listfav", false, "list favorited canvas courses") | ||
| 36 | flag.BoolVar(&listfav, "F", false, "list favorited canvas courses") | ||
| 37 | flag.BoolVar(&help, "help", false, "view usage message") | ||
| 38 | flag.BoolVar(&help, "h", false, "view usage message") | ||
| 25 | 39 | ||
| 26 | if *help || (*list_all == false && *list_favorites == false && *code == "" && *course == -1) { | 40 | flag.Parse() |
| 27 | getopt.Usage() | 41 | |
| 28 | os.Exit(0) | 42 | if (code == "" && course == -1 && !listall && !listfav) { |
| 43 | usage() | ||
| 44 | os.Exit(1) | ||
| 29 | } | 45 | } |
| 30 | 46 | ||
| 31 | if *list_all { | 47 | if (listall) { |
| 32 | list_all_courses() | 48 | list_all_courses() |
| 49 | os.Exit(0) | ||
| 33 | } | 50 | } |
| 34 | 51 | ||
| 35 | if *list_favorites { | 52 | if (listfav) { |
| 36 | list_favorite_courses() | 53 | list_favorite_courses() |
| 54 | os.Exit(0) | ||
| 55 | } | ||
| 56 | |||
| 57 | if (help) { | ||
| 58 | usage() | ||
| 59 | os.Exit(0) | ||
| 60 | } | ||
| 61 | |||
| 62 | if (len(code) != 5) { | ||
| 63 | fmt.Println("Attendance code must be 5 characters long") | ||
| 64 | os.Exit(1) | ||
| 37 | } | 65 | } |
| 38 | 66 | ||
| 39 | if *code != "" && *course != -1 { | 67 | if code != "" && course != -1 { |
| 40 | fmt.Printf("%d %s", *course, *code) | 68 | fmt.Printf("%d %s\n", course, code) |
| 41 | submit_code(*course, *code) | 69 | submit_code(course, code) |
| 70 | } else { | ||
| 71 | usage() | ||
| 72 | os.Exit(1) | ||
| 42 | } | 73 | } |
| 43 | } | 74 | } |
