From d425358bd0ac54bf9bfe176d5328b2d87fa86f27 Mon Sep 17 00:00:00 2001 From: Juan Roig Date: Wed, 15 Nov 2023 03:58:38 -0500 Subject: [PATCH] Switch to getopt library from flag library for flag parsing. --- go.mod | 2 ++ go.sum | 2 ++ main.go | 22 ++++++++++++++-------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 732a265..faf8f50 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index ee9cb73..7143679 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/main.go b/main.go index 61bf20f..b46d0c7 100644 --- a/main.go +++ b/main.go @@ -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") }