Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added the bin that executes which-cloud #3

Merged
merged 1 commit into from
Jun 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions bin/which-cloud.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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