Skip to content

Commit

Permalink
feat: added the bin that executes which-cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Coe committed Jun 3, 2016
1 parent 33be2a3 commit 43be975
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
20 changes: 20 additions & 0 deletions bin/which-cloud.js
@@ -0,0 +1,20 @@
#!/usr/bin/env node

const which = require('../')
const argv = require('yargs')
.usage('$0 <ip>')
.help()
.alias('help', 'h')
.demand(1, 'you must provide an ip to lookup')
.argv
const ip = argv._[0]

which(ip, function (err, cloud) {
if (err) {
console.log('unknown')
process.exit(1)
} else {
console.log(cloud)
process.exit(0)
}
})
4 changes: 2 additions & 2 deletions lib/which.js → index.js
@@ -1,7 +1,7 @@
const parallel = require('async').parallel
const ipRangeCheck = require('ip-range-check')
const azure = require('./azure')
const aws = require('./aws')
const azure = require('./lib/azure')
const aws = require('./lib/aws')

module.exports = function (ip, done) {
var name = 'unknown'
Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "given an ip address, return which cloud provider it belongs to (AWS, GCE, etc)",
"main": "index.js",
"bin": "bin/which-cloud.js",
"global": true,
"scripts": {
"pretest": "standard",
Expand Down Expand Up @@ -46,6 +47,8 @@
"lib/aws.js",
"lib/azure.js",
"LICENSE.txt",
"data/PublicIPs.xml"
"data/PublicIPs.xml",
"index.js",
"bin/which-cloud.js"
]
}
22 changes: 22 additions & 0 deletions test/cli.js
@@ -0,0 +1,22 @@
/* global describe, it */

require('chai').should()

const exec = require('child_process').exec

describe('cli', function () {
it('displays help if no ip is provided', function (done) {
exec('./bin/which-cloud.js', function (err, stdout, stderr) {
err.message.should.match(/you must provide an ip to lookup/)
return done()
})
})

it('looks up an ip', function (done) {
exec('./bin/which-cloud.js 94.245.97.0', function (err, stdout, stderr) {
if (err) return done(err)
stdout.should.match(/azure/)
return done()
})
})
})
4 changes: 2 additions & 2 deletions test/which.js
Expand Up @@ -2,7 +2,7 @@

require('chai').should()

const which = require('../lib/which')
const which = require('../')

describe('which', function () {
it('returns appropriate response for azure ip', function (done) {
Expand All @@ -14,7 +14,7 @@ describe('which', function () {
})

it('returns appropriate response for aws ip', function (done) {
which('54.173.231.160', function (err, name) {
which('54.173.231.161', function (err, name) {
if (err) return done(err)
name.should.equal('aws')
return done()
Expand Down

0 comments on commit 43be975

Please sign in to comment.