package main import ( "fmt" "net/http" "os" "strings" "git.ddd.rip/ptrcnull/html" ) const BOLD = "\033[1m" const RESET = "\033[0m" func main() { if len(os.Args) < 2 { fmt.Println("usage: pkgs ") os.Exit(1) } file := os.Args[1] res, err := http.Get("https://pkgs.alpinelinux.org/contents?file=" + file + "&path=&name=&branch=edge&arch=x86_64") if err != nil { fmt.Println(err.Error()) os.Exit(1) } node, err := html.ParseDocument(res.Body) if err != nil { fmt.Println(err.Error()) os.Exit(1) } tbody := node.QuerySelector("tbody") if tbody == nil { fmt.Println("cannot find tbody") os.Exit(1) } reply := "" tbody.ForEach(func(row *html.Node) { cells := row.Children() if len(cells) == 0 { return } if len(cells) < 5 { reply = "Not found :(" return } reply += BOLD + cells[1].TrimmedText() + RESET + "\n" + cells[0].TrimmedText() + "\n\n" }) reply = strings.Trim(reply, "\n") fmt.Println(reply) }