Switch to getopt library from flag library for flag parsing.

This commit is contained in:
Juan Roig 2023-11-15 03:58:38 -05:00
parent e28dc92307
commit d425358bd0
3 changed files with 18 additions and 8 deletions

2
go.mod
View File

@ -3,3 +3,5 @@ module codeberg.org/flpolyaplus/aplus
go 1.21.3
require golang.org/x/net v0.18.0
require github.com/pborman/getopt v1.1.0 // indirect

2
go.sum
View File

@ -1,2 +1,4 @@
github.com/pborman/getopt v1.1.0 h1:eJ3aFZroQqq0bWmraivjQNt6Dmm5M0h2JcDW38/Azb0=
github.com/pborman/getopt v1.1.0/go.mod h1:FxXoW1Re00sQG/+KIkuSqRL/LwQgSkv7uyac+STFsbk=
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=

22
main.go
View File

@ -1,9 +1,11 @@
package main
import (
"flag"
"fmt"
"net/http"
"os"
"github.com/pborman/getopt"
)
var base_link string
@ -15,12 +17,18 @@ var client http.Client
func main() {
initialize()
code := flag.String("code", "", "Code to enter")
course := flag.Int("course", -1, "Canvas course number")
list_all := flag.Bool("list-all", false, "List all courses")
list_favorites := flag.Bool("list-favorites", false, "List favorite courses")
code := getopt.StringLong("code", 'c', "", "Code to enter")
course := getopt.IntLong("course", 'C', -1, "Canvas course number")
list_all := getopt.BoolLong("list-all", 0, "List all courses")
list_favorites := getopt.BoolLong("list-favorites", 0, "List favorite courses")
help := getopt.BoolLong("help", 0, "Help")
flag.Parse()
getopt.Parse()
if *help {
getopt.Usage()
os.Exit(0)
}
if *list_all {
list_all_courses()
@ -34,6 +42,4 @@ func main() {
fmt.Printf("%d %s", *course, *code)
submit_code(*course, *code)
}
submit_code(7329, "asdkl")
}