func tpdoc(src *commander.Source, resp *commander.Response, cmd string, args []string) { if len(args) == 0 { resp.Public() u := &url.URL{ Scheme: "http", Host: ThirdPartyHost, Path: "/", } resp.Printf("%s: %s", cmd, u) return } pkg := args[0] for _, ch := range pkg { switch ch { case 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z': case 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z': case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': case '-', '.', '_', '/': default: resp.Private() resp.Printf("Hmm, that doesn't look like a package name...") return } } uri := url.URL{ Scheme: "http", Host: ThirdPartyHost, Path: "/", RawQuery: url.Values{"q": {pkg}}.Encode(), } r, err := http.Head(uri.String()) // If the query did not redirect, then GoPkgDoc could not find the package. if err != nil || r.StatusCode != http.StatusOK || r.Request.URL.Path == "/" { resp.Public() resp.Printf("Hmm, I can't find %q. You can look for it on %s", pkg, ThirdPartyIndex) return } resp.Public() resp.Printf("3pkg: %s", r.Request.URL.String()) }
func nopaste(s *commander.Source, r *commander.Response, cmd string, args []string) { r.Public() r.Printf("If you need to paste more than 3 lines, use gp: go get github.com/kylelemons/gopaste/gp") }
func godoc(src *commander.Source, resp *commander.Response, cmd string, args []string) { // The index is copy-on-write index := godocIndex sites, pages := []string{"release"}, []string{cmd} switch cmd { case "doc": pages = make([]string, 0, len(DocPages)) for page := range DocPages { pages = append(pages, page) } default: if _, ok := DocPages[cmd]; !ok { resp.Private() resp.Printf("Unrecognized godoc subcommand %q", cmd) return } } var start int var overriddenSites bool for _, arg := range args { if len(arg) == 0 || arg[0] != '-' { continue } for len(arg) > 1 && arg[0] == '-' { arg = arg[1:] } start++ if _, ok := DocSites[arg]; ok { if overriddenSites { sites = append(sites, arg) continue } sites = []string{arg} overriddenSites = true } else { resp.Private() resp.Printf("Unrecognized godoc option: --%s", arg) } } search := strings.Join(args[start:], " ") if search == "" { resp.Private() resp.Printf("What do you want to search for?") return } if index == nil { resp.Private() resp.Printf("The index isn't ready yet.") return } prefix := "" exact := make([]string, 0, MaxPublicResults) found := make([]string, 0, MaxPublicResults) for _, site := range sites { if len(sites) > 1 { prefix = site + ": " } for _, page := range pages { search := search switch page { case "pkg", "cmd": // leave the case alone default: search = strings.Title(search) } pageIndex := index.Pages[site][page] if urls, ok := pageIndex.SectionURLs[search]; ok { for _, url := range urls { exact = append(exact, fmt.Sprintf("%s%s: %s - %s", prefix, page, search, url)) } } if len(exact) > 0 { continue } for section, urls := range pageIndex.SectionURLs { if strings.Contains(section, search) { for _, url := range urls { found = append(found, fmt.Sprintf("%s%s: %s - %s", prefix, page, section, url)) } } } } } switch { case len(exact) > 0: resp.Public() for _, e := range exact { resp.Printf(e) } case len(found) > MaxPublicResults: resp.Private() resp.Printf("Found %d results; only showing %d", len(found), MaxPublicResults) sort.Sort(DashSorter(found)) found = found[:MaxPublicResults] fallthrough case len(found) > 0: resp.Public() for _, f := range found { resp.Printf(f) } default: resp.Private() resp.Printf("Nothing found for %q in %v x %v", search, sites, pages) } }