diff options
| author | Juan Roig <jaroig@outlook.com> | 2023-11-15 03:58:38 -0500 |
|---|---|---|
| committer | Juan Roig <jaroig@outlook.com> | 2023-11-15 03:58:38 -0500 |
| commit | d425358bd0ac54bf9bfe176d5328b2d87fa86f27 (patch) | |
| tree | 6deb904dab97f22af1faacd476734f8d2812e9e2 | |
| parent | e28dc923074ff7445d23cb97a04233f6192a69be (diff) | |
Switch to getopt library from flag library for flag parsing.
| -rw-r--r-- | go.mod | 2 | ||||
| -rw-r--r-- | go.sum | 2 | ||||
| -rw-r--r-- | main.go | 22 |
3 files changed, 18 insertions, 8 deletions
| @@ -3,3 +3,5 @@ module codeberg.org/flpolyaplus/aplus | |||
| 3 | go 1.21.3 | 3 | go 1.21.3 |
| 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,2 +1,4 @@ | |||
| 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= | ||
| 1 | golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= | 3 | golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= |
| 2 | golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= | 4 | golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= |
| @@ -1,9 +1,11 @@ | |||
| 1 | package main | 1 | package main |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "flag" | ||
| 5 | "fmt" | 4 | "fmt" |
| 6 | "net/http" | 5 | "net/http" |
| 6 | "os" | ||
| 7 | |||
| 8 | "github.com/pborman/getopt" | ||
| 7 | ) | 9 | ) |
| 8 | 10 | ||
| 9 | var base_link string | 11 | var base_link string |
| @@ -15,12 +17,18 @@ var client http.Client | |||
| 15 | func main() { | 17 | func main() { |
| 16 | initialize() | 18 | initialize() |
| 17 | 19 | ||
| 18 | code := flag.String("code", "", "Code to enter") | 20 | code := getopt.StringLong("code", 'c', "", "Code to enter") |
| 19 | course := flag.Int("course", -1, "Canvas course number") | 21 | course := getopt.IntLong("course", 'C', -1, "Canvas course number") |
| 20 | list_all := flag.Bool("list-all", false, "List all courses") | 22 | list_all := getopt.BoolLong("list-all", 0, "List all courses") |
| 21 | list_favorites := flag.Bool("list-favorites", false, "List favorite courses") | 23 | list_favorites := getopt.BoolLong("list-favorites", 0, "List favorite courses") |
| 24 | help := getopt.BoolLong("help", 0, "Help") | ||
| 25 | |||
| 26 | getopt.Parse() | ||
| 22 | 27 | ||
| 23 | flag.Parse() | 28 | if *help { |
| 29 | getopt.Usage() | ||
| 30 | os.Exit(0) | ||
| 31 | } | ||
| 24 | 32 | ||
| 25 | if *list_all { | 33 | if *list_all { |
| 26 | list_all_courses() | 34 | list_all_courses() |
| @@ -34,6 +42,4 @@ func main() { | |||
| 34 | fmt.Printf("%d %s", *course, *code) | 42 | fmt.Printf("%d %s", *course, *code) |
| 35 | submit_code(*course, *code) | 43 | submit_code(*course, *code) |
| 36 | } | 44 | } |
| 37 | |||
| 38 | submit_code(7329, "asdkl") | ||
| 39 | } | 45 | } |
