Skip to content

Instantly share code, notes, and snippets.

@mnylen
Created July 26, 2012 16:40
Show Gist options
  • Save mnylen/3183126 to your computer and use it in GitHub Desktop.
Save mnylen/3183126 to your computer and use it in GitHub Desktop.
m2search
$ m2search "logback"
"de.huxhorn.lilith" % "logback" % "0.9.41"
"ch.qos.logback" % "logback" % "0.5"
"ch.qos.logback" % "logback-parent" % "1.0.6"
"ch.qos.logback" % "logback-site" % "1.0.6"
"ch.qos.logback" % "logback-skin" % "0.9"
"org.wicketstuff" % "wicketstuff-logback-parent" % "6.0.0-beta1.1"
"ch.qos.logback" % "audit-parent" % "0.5"
"ch.qos.logback" % "logback-examples" % "1.0.6"
"ch.qos.logback" % "logback-access" % "1.0.6"
"ch.qos.logback" % "logback-classic" % "1.0.6"
#!/usr/bin/env coffee
http = require('http')
base = "/solrsearch/select?"
q = "q="
all = false
if process.argv.length == 3
q += process.argv[2]
else if process.argv.length > 3
current = null
for own idx, val of process.argv
if idx < 2
continue
if val == "--all"
all = true
continue
if current == null
current = val[1..]
else
q += current + ":\"" + val + "\"%20"
current = null
else
console.log("usage: m2search query")
console.log(" m2search [-g groupId] [-a artifactId]")
process.exit(1)
path = base + q.trim() + "&wt=json"
path += "&core=gav" if all == true
options =
host : "search.maven.org"
port : 80
path : path
method : 'GET'
formatResult = (doc) ->
v = if all then doc.v else doc.latestVersion
"\"" + doc.g + "\" % \"" + doc.a + "\" % \"" + v + "\""
printResults = (results) ->
response = results.response
if response.numFound == 0
console.log("Sorry, nothing was found")
else
for doc in response.docs
console.log(formatResult(doc))
req = http.request(options, (res) ->
respData = ""
res.on('data', (chunk) -> respData += chunk)
res.on('end', ->
results = JSON.parse(respData)
printResults(results)
)
)
req.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment