mirror of
https://codeberg.org/flpolyaplus/aplus.git
synced 2024-11-21 08:50:30 -05:00
use golang flag instead of external getopt library
This commit is contained in:
parent
23226c46a1
commit
138121330e
2
aplus.go
2
aplus.go
@ -63,7 +63,7 @@ func submit_code(course_code int, attendance_code string) {
|
|||||||
func launch_aplus(course_code int) string {
|
func launch_aplus(course_code int) string {
|
||||||
err := init_aplus_toolid(course_code)
|
err := init_aplus_toolid(course_code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Failed to get A+ base URL and tool ID")
|
fmt.Println("Failed to get A+ base URL and tool ID. Try again with a different course code.")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
go.mod
4
go.mod
@ -1,7 +1,5 @@
|
|||||||
module codeberg.org/flpolyaplus/aplus
|
module codeberg.org/flpolyaplus/aplus
|
||||||
|
|
||||||
go 1.21.3
|
go 1.21.1
|
||||||
|
|
||||||
require golang.org/x/net v0.18.0
|
require golang.org/x/net v0.18.0
|
||||||
|
|
||||||
require github.com/pborman/getopt v1.1.0 // indirect
|
|
||||||
|
2
go.sum
2
go.sum
@ -1,4 +1,2 @@
|
|||||||
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 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
|
||||||
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
|
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
|
||||||
|
67
main.go
67
main.go
@ -1,43 +1,74 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/pborman/getopt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var base_link string
|
var base_link string
|
||||||
|
var base_aplus_link string
|
||||||
|
var external_tools_code int
|
||||||
var token string
|
var token string
|
||||||
var client http.Client
|
var client http.Client
|
||||||
|
|
||||||
|
func usage() {
|
||||||
|
fmt.Println("Usage: aplus [--code attendance_code --course course_code] [--list] [--listfav] [--help]")
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
initialize()
|
initialize()
|
||||||
|
|
||||||
code := getopt.StringLong("code", 'c', "", "Code to enter")
|
var code string
|
||||||
course := getopt.IntLong("course", 'C', -1, "Canvas course number")
|
var course int
|
||||||
list_all := getopt.BoolLong("list-all", 'L', "List all courses")
|
var listall bool
|
||||||
list_favorites := getopt.BoolLong("list-favorites", 'F', "List favorite courses")
|
var listfav bool
|
||||||
help := getopt.BoolLong("help", 'h', "Help")
|
var help bool
|
||||||
|
|
||||||
getopt.Parse()
|
flag.StringVar(&code, "code", "", "5 character attendance code")
|
||||||
|
flag.StringVar(&code, "c", "", "5 character attendance code")
|
||||||
|
flag.IntVar(&course, "course", -1, "canvas course code")
|
||||||
|
flag.IntVar(&course, "C", -1, "canvas course code")
|
||||||
|
flag.BoolVar(&listall, "list", false, "list all canvas courses")
|
||||||
|
flag.BoolVar(&listall, "L", false, "list all canvas courses")
|
||||||
|
flag.BoolVar(&listfav, "listfav", false, "list favorited canvas courses")
|
||||||
|
flag.BoolVar(&listfav, "F", false, "list favorited canvas courses")
|
||||||
|
flag.BoolVar(&help, "help", false, "view usage message")
|
||||||
|
flag.BoolVar(&help, "h", false, "view usage message")
|
||||||
|
|
||||||
if *help || (*list_all == false && *list_favorites == false && *code == "" && *course == -1) {
|
flag.Parse()
|
||||||
getopt.Usage()
|
|
||||||
|
if (code == "" && course == -1 && !listall && !listfav) {
|
||||||
|
usage()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listall) {
|
||||||
|
list_all_courses()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *list_all {
|
if (listfav) {
|
||||||
list_all_courses()
|
|
||||||
}
|
|
||||||
|
|
||||||
if *list_favorites {
|
|
||||||
list_favorite_courses()
|
list_favorite_courses()
|
||||||
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *code != "" && *course != -1 {
|
if (help) {
|
||||||
fmt.Printf("%d %s", *course, *code)
|
usage()
|
||||||
submit_code(*course, *code)
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len(code) != 5) {
|
||||||
|
fmt.Println("Attendance code must be 5 characters long")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if code != "" && course != -1 {
|
||||||
|
fmt.Printf("%d %s\n", course, code)
|
||||||
|
submit_code(course, code)
|
||||||
|
} else {
|
||||||
|
usage()
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user