├── .gitignore ├── README.mkd └── main.go /.gitignore: -------------------------------------------------------------------------------- 1 | /maven-search 2 | /maven-search.exe 3 | /tags/ 4 | /tmp/ 5 | -------------------------------------------------------------------------------- /README.mkd: -------------------------------------------------------------------------------- 1 | # Search maven artifacts in CLI 2 | 3 | Install 4 | 5 | $ go get github.com/koron/maven-search 6 | 7 | Run 8 | 9 | $ maven-search junit 10 | 11 | Then you'll get like this. 12 | 13 | junit:junit:4.12 14 | org.technbolts:junit:1.0.1 15 | com.groupon.roboremote.roboremoteclient:junit:0.4 16 | org.apache.tuscany.sca.samples:junit:2.0 17 | org.apache.isis.viewer:junit:0.2.0-incubating 18 | com.kenai.nbpwr:junit:4.7-201002241900 19 | org.mod4j.org:junit:3.8.2 20 | org.codehaus.mevenide:junit:3.1.4 21 | org.eclipse.jdt:junit:3.3.0-v20070606-0010 22 | junit:junit-dep:4.11 23 | junit-addons:junit-addons:1.4 24 | junit-doclet:junit-doclet:1.0.2 25 | org.jboss.arquillian.junit:arquillian-junit-parent:1.1.5.Final 26 | com.googlecode.guice-junit4:guice-junit4-parent:0.2 27 | com.pholser:junit-quickcheck:0.4-beta-3 28 | pl.javadevelopers.junit:parent:0.8 29 | ant:ant-junit:1.6.5 30 | org.robovm:robovm-junit-parent:1.0.0-beta-01 31 | org.apache.jmeter:ApacheJMeter_junit:2.12 32 | com.github.mjeanroy:junit-servers:0.2.2 33 | 34 | # Inspired by 35 | 36 | * [maven, browse central repository via command line client](http://stackoverflow.com/questions/14465721/maven-browse-central-repository-via-command-line-client) 37 | * [コマンドラインから、maven アーティファクトを検索するには?](http://ja.stackoverflow.com/questions/1581/%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%83%A9%E3%82%A4%E3%83%B3%E3%81%8B%E3%82%89-maven-%E3%82%A2%E3%83%BC%E3%83%86%E3%82%A3%E3%83%95%E3%82%A1%E3%82%AF%E3%83%88%E3%82%92%E6%A4%9C%E7%B4%A2%E3%81%99%E3%82%8B%E3%81%AB%E3%81%AF) 38 | 39 | # License 40 | 41 | The BSD 3-Clause License 42 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "net/http" 8 | "net/url" 9 | "os" 10 | "strconv" 11 | ) 12 | 13 | func searchArtifact(q string, n int) error { 14 | p := url.Values{ 15 | "rows": []string{strconv.Itoa(n)}, 16 | "wt": []string{"json"}, 17 | "q": []string{q}, 18 | } 19 | u := "http://search.maven.org/solrsearch/select?" + p.Encode() 20 | resp, err := http.Get(u) 21 | if err != nil { 22 | return err 23 | } 24 | defer resp.Body.Close() 25 | if resp.StatusCode != 200 { 26 | return errors.New(resp.Status) 27 | } 28 | // parse JSON with anonymous struct. 29 | d := json.NewDecoder(resp.Body) 30 | var v struct { 31 | Response struct { 32 | Docs []struct { 33 | ID string 34 | LatestVersion string 35 | } 36 | } 37 | } 38 | if err := d.Decode(&v); err != nil { 39 | return err 40 | } 41 | // print results. 42 | for _, d := range v.Response.Docs { 43 | fmt.Println(d.ID + ":" + d.LatestVersion) 44 | } 45 | return nil 46 | } 47 | 48 | func main() { 49 | if len(os.Args) < 2 { 50 | fmt.Println("ERROR: need a query string") 51 | os.Exit(1) 52 | } 53 | if err := searchArtifact(os.Args[1], 20); err != nil { 54 | fmt.Printf("ERROR: %s\n", err) 55 | os.Exit(1) 56 | } 57 | } 58 | --------------------------------------------------------------------------------