summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--aplus.go2
-rw-r--r--go.mod4
-rw-r--r--go.sum2
-rw-r--r--main.go63
4 files changed, 49 insertions, 22 deletions
diff --git a/aplus.go b/aplus.go
index 51a5a10..6d308c4 100644
--- a/aplus.go
+++ b/aplus.go
@@ -63,7 +63,7 @@ func submit_code(course_code int, attendance_code string) {
63func launch_aplus(course_code int) string { 63func 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
diff --git a/go.mod b/go.mod
index faf8f50..6659170 100644
--- a/go.mod
+++ b/go.mod
@@ -1,7 +1,5 @@
1module codeberg.org/flpolyaplus/aplus 1module codeberg.org/flpolyaplus/aplus
2 2
3go 1.21.3 3go 1.21.1
4 4
5require golang.org/x/net v0.18.0 5require golang.org/x/net v0.18.0
6
7require github.com/pborman/getopt v1.1.0 // indirect
diff --git a/go.sum b/go.sum
index 7143679..ee9cb73 100644
--- a/go.sum
+++ b/go.sum
@@ -1,4 +1,2 @@
1github.com/pborman/getopt v1.1.0 h1:eJ3aFZroQqq0bWmraivjQNt6Dmm5M0h2JcDW38/Azb0=
2github.com/pborman/getopt v1.1.0/go.mod h1:FxXoW1Re00sQG/+KIkuSqRL/LwQgSkv7uyac+STFsbk=
3golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= 1golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
4golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= 2golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
diff --git a/main.go b/main.go
index 9386b46..93defd3 100644
--- a/main.go
+++ b/main.go
@@ -1,43 +1,74 @@
1package main 1package main
2 2
3import ( 3import (
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
11var base_link string 10var base_link string
11var base_aplus_link string
12var external_tools_code int
12var token string 13var token string
13var client http.Client 14var client http.Client
14 15
16func usage() {
17 fmt.Println("Usage: aplus [--code attendance_code --course course_code] [--list] [--listfav] [--help]")
18}
19
15func main() { 20func 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}