Permalink
Browse files

init

  • Loading branch information...
1 parent 135fb0d commit 0aa85bd33318d09747ca640ec6411ffa40dba348 @gabrieleds committed Dec 30, 2012
Showing with 880 additions and 221 deletions.
  1. +94 −1 bin/hosty
  2. +240 −215 lib/hosty.js
  3. +170 −0 lib/hosty/ast.js
  4. +225 −0 lib/hosty/block.js
  5. +81 −0 lib/hosty/record.js
  6. +49 −0 lib/hosty/utils.js
  7. +6 −1 package.json
  8. +15 −4 test/hosty.test.js
View
@@ -4,4 +4,97 @@
* Hosty
* Copyright(c) 2012 Gabriele Di Stefano <gabriele.ds@gmail.com>
* MIT Licensed
- */
+ */
+
+var Hosty = require('../lib/hosty')
+ , utils = require('../lib/hosty/utils')
+ , Table = require('cli-table')
+ , colors = require('colors')
+ , args = utils.rest(process.argv, 2)
+ , cmds = ['version', '-v', 'help', '-h', 'ls', 'add', 'rm', 'on', 'off']
+ ;
+
+if(args.length > 0 && utils.contains(cmds, args[0])){
+ args.cmd = args[0];
+ args.block = Hosty.defaultBlock;
+ args.params = utils.rest(args, 1);
+}
+else if(args.length > 1 && utils.contains(cmds, args[1])){
+ args.cmd = args[1];
+ args.block = args[0];
+ args.params = utils.rest(args, 2);
+}
+else{
+ args.cmd = 'help';
+}
+
+switch(args.cmd){
+ case 'version':
+ case '-v':
+ console.log(Hosty.version.green);
+ break;
+ case 'help':
+ case '-h':
+ console.log('help')
+ break;
+ case 'ls':
+ exec(function(err, data){
+
+ var params = args.params.splice(0)
+ , table = new Table({
+ head: ['', 'HOST', 'IP'],
+ colWidths: [3, 40, 20]
+ })
+ ;
+
+ params.pop();
+
+ utils.each(data, function(record){
+ if(!record.disabled){
+ table.push(['.', record.host.white, record.ip.white]);
+ }
+ else{
+ table.push(['', record.host.grey, record.ip.grey]);
+ }
+ });
+
+ console.log('');
+ console.log(' Hosty view block: ' + args.block.cyan, params.toString().grey);
+ console.log('');
+ console.log(table.toString());
+ });
+ break;
+ case 'add':
+ exec(function(err, data){
+ //console.log('add')
+ });
+ break;
+ case 'rm':
+ exec(function(err, data){
+ //console.log('rm')
+ });
+ break;
+ case 'on':
+ exec(function(err, data){
+ //console.log('on')
+ });
+ break;
+ case 'off':
+ exec(function(err, data){
+ //console.log('off')
+ });
+ break;
+}
+
+function exec(cb){
+ var hosty = new Hosty(args.block)
+ , i
+ ;
+
+ while(args.params.length < 2){
+ args.params.push('*');
+ }
+ args.params.push(cb);
+
+ hosty[args.cmd].apply(hosty, args.params);
+}
Oops, something went wrong.

0 comments on commit 0aa85bd

Please sign in to comment.