osx-wifi-cli
Advanced tools
Comparing version 0.0.3 to 1.0.0
{ | ||
"name": "osx-wifi-cli", | ||
"version": "0.0.1", | ||
"from": "osx-wifi-cli@", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"commander": { | ||
"version": "2.1.0", | ||
"from": "commander@2.1.0", | ||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.1.0.tgz" | ||
}, | ||
"q": { | ||
"version": "1.0.0", | ||
"from": "q@1.0.0" | ||
}, | ||
"rekuire": { | ||
"version": "0.1.5", | ||
"from": "rekuire@0.1.5", | ||
"dependencies": { | ||
"underscore": { | ||
"version": "1.6.0", | ||
"from": "underscore@*" | ||
} | ||
} | ||
}, | ||
"commander": { | ||
"version": "2.1.0", | ||
"from": "commander@2.1.0" | ||
"from": "q@1.0.0", | ||
"resolved": "https://registry.npmjs.org/q/-/q-1.0.0.tgz" | ||
} | ||
} | ||
} |
#!/usr/bin/env node | ||
'use strict'; | ||
'use strict' | ||
var Q = require('q'); | ||
var cli = require('commander'); | ||
var exec = require('child_process').exec; | ||
var rek = require('rekuire'); | ||
var commands = rek('commands'); | ||
var version = rek('package.json').version; | ||
var Q = require('q') | ||
var cli = require('commander') | ||
var exec = require('child_process').exec | ||
var commands = require('./commands.js') | ||
var version = require('./package.json').version | ||
@@ -20,7 +19,7 @@ cli | ||
.option('--device <device>', 'set device (default is en0)') //see ugly todo below. | ||
.parse(process.argv); | ||
.parse(process.argv) | ||
var utils = commands.osx; // If implementing other OSs, this is the place to check which we're on. | ||
var utils = commands.osx // If implementing other OSs, this is the place to check which we're on. | ||
var args = process.argv.slice(2); | ||
var args = process.argv.slice(2) | ||
@@ -30,3 +29,3 @@ //This is very ugly!! TODO: check how to combine flags and "commands" properly. maybe use 'npm i cli'. | ||
Object.keys(utils).forEach(function(key) { | ||
if (typeof utils[key] == 'string') utils[key] = utils[key].replace('en0', cli.device); | ||
if (typeof utils[key] == 'string') utils[key] = utils[key].replace('en0', cli.device) | ||
}) | ||
@@ -36,9 +35,9 @@ args.splice(args.indexOf('--device'),2) | ||
if (args[0] == 'on') execute(utils.on); //cli.on is a function | ||
else if (cli.off) execute(utils.off); | ||
else if (cli.restart) execute(utils.off).then(execute.bind(this,utils.on)); | ||
else if (cli.scan) execute(utils.scan).then(utils.parseScan).then(printNetworks); | ||
if (args[0] == 'on') execute(utils.on) //cli.on is a function | ||
else if (cli.off) execute(utils.off) | ||
else if (cli.restart) execute(utils.off).then(execute.bind(this,utils.on)) | ||
else if (cli.scan) execute(utils.scan).then(utils.parseScan).then(printNetworks) | ||
else if (args.length == 2) execute(utils.connect.replace('NETWORK_TOKEN',args[0]).replace('PASSWORD_TOKEN',args[1])) | ||
else if (args.length == 0) execute(utils.currentNetwork).then(utils.extractCurrentNetwork).then(help); | ||
else console.log('input error') | ||
else if (args.length == 0) execute(utils.currentNetwork).then(utils.extractCurrentNetwork).then(help) | ||
else cli.help() | ||
@@ -49,5 +48,5 @@ //////////////////////////////////////////////// | ||
if (currentNetwork.SSID) { | ||
console.log('you are connected to ' + currentNetwork.SSID); | ||
console.log('you are connected to ' + currentNetwork.SSID) | ||
} else { | ||
console.log('you are not connected anywhere'); | ||
console.log('you are not connected anywhere') | ||
} | ||
@@ -58,24 +57,24 @@ //TODO: add more help text | ||
function printNetworks(networksObj) { | ||
networksObj.sort(function(a,b){return a.SSID > b.SSID}); | ||
networksObj.sort(function(a,b){return a.SSID > b.SSID}) | ||
var maxLengths = networksObj.reduce(function(lengths, network) { | ||
Object.keys(network).forEach(function(key) { | ||
lengths[key] = Math.max(lengths[key] || 0, network[key].toString().length) | ||
}); | ||
return lengths; | ||
}, {}); | ||
}) | ||
return lengths | ||
}, {}) | ||
//TODO: add numeric IDs and colors | ||
var output = networksObj.map(function(network) { return Object.keys(network).map(function(key) {return pad(network[key].toString(), maxLengths[key]+2, ' ') }).join(' ')}).join('\n'); | ||
console.log(output); | ||
var output = networksObj.map(function(network) { return Object.keys(network).map(function(key) {return pad(network[key].toString(), maxLengths[key]+2, ' ') }).join(' ')}).join('\n') | ||
console.log(output) | ||
} | ||
function execute(cmd) { | ||
//console.log('executing command:', cmd); | ||
var deferred = Q.defer(); | ||
//console.log('executing command:', cmd) | ||
var deferred = Q.defer() | ||
exec(cmd, function(err, strout, strerr) { | ||
if (err) deferred.reject(new Error(err)); | ||
else if (strerr) deferred.reject(new Error(strerr)); | ||
else deferred.resolve(strout); | ||
}); | ||
return deferred.promise; | ||
}; | ||
if (err) deferred.reject(new Error(err)) | ||
else if (strerr) deferred.reject(new Error(strerr)) | ||
else deferred.resolve(strout) | ||
}) | ||
return deferred.promise | ||
} | ||
@@ -85,3 +84,3 @@ //////////////////////////////////////////////////////////////////////////////// | ||
function pad(path, len, char) { | ||
return (path.length >= len) ? path : pad(path + char[0], len, char); | ||
return (path.length >= len) ? path : pad(path + char[0], len, char) | ||
} |
{ | ||
"name": "osx-wifi-cli", | ||
"version": "0.0.3", | ||
"version": "1.0.0", | ||
"description": "A command line tool for managing wifi connection in osx", | ||
@@ -12,2 +12,3 @@ "keywords": ["osx", "wifi", "cli", "mac", "wireless", "network"], | ||
}, | ||
"os": ["darwin"], | ||
"contributors": [], | ||
@@ -37,5 +38,4 @@ "licenses": [ | ||
"q": "1.0.0", | ||
"rekuire": "0.1.5", | ||
"commander": "2.1.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
## osx-wifi-cli | ||
## osx-wifi-cli - WIP | ||
### A command line tool for managing wifi connections on OSX | ||
@@ -25,12 +25,3 @@ | ||
* This was developed in a way that should make implementing this for other operating systems easy. If you want to give it a shot, check out the code or send me a message. | ||
* To connect to network without a password (bad idea!) use `osx-wifi-cli networkname " "` | ||
* * * | ||
#### TODOs | ||
* Enable connection to a network without a password. (Should currently be possible with `" "`) | ||
* Enable picking a network by a numeric id | ||
* * * | ||
#### Feedback | ||
* If you enjoyed this tool, please star it on Github! | ||
* I'd love to get any feedback you might have! Mail me at danyshaanan@gmail.com, or [open an issue](https://github.com/danyshaanan/osx-wifi-cli/issues/new). | ||
* More material appreciation is welcome in the form of bitcoins. My address can be found on [this page](http://danyshaanan.com/bitcoin). |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2
0
7497
106
27
- Removedrekuire@0.1.5
- Removedrekuire@0.1.5(transitive)
- Removedunderscore@1.13.6(transitive)