func main() { if len(os.Args) < 3 { usage() os.Exit(1) } cmd := os.Args[1] if cmd != "print" && cmd != "print-json" { fmt.Fprintf(os.Stderr, "Invalid command: %s\n\n", cmd) usage() return } objs, err := importer.GetPackageObjects(os.Args[2]) if err != nil { die("%s\n", err) } switch cmd { case "print": fmt.Println(objs) case "print-json": bs, err := json.Marshal(objs) if err != nil { die("%s\n", err) } fmt.Println(string(bs)) } }
func main() { if len(os.Args) < 2 { fmt.Fprintln(os.Stderr, "Usage: scope <pkg-name>") os.Exit(1) } objs, err := importer.GetPackageObjects(os.Args[1]) if err != nil { fmt.Fprintf(os.Stderr, "%s\n", err) } else { fmt.Println(objs) } }
func getPackageObjectsJSON(pkgName string) string { objs, err := importer.GetPackageObjects(pkgName) if err != nil { return respondWithError(err) } b, err := json.Marshal(importer.Scope{objs}) if err != nil { return respondWithError(err) } return string(b) }