Permalink
Browse files

Updated

  • Loading branch information...
1 parent b19fa10 commit 8c60df79bc4120b078de51c27a9827e6dbeaa6cf @jheusala jheusala committed Mar 18, 2012
Showing with 116 additions and 0 deletions.
  1. +19 −0 LICENSE.txt
  2. +20 −0 cli.js
  3. +57 −0 joker.js
  4. +20 −0 package.json
View
@@ -0,0 +1,19 @@
+Copyright (C) 2011 by Jaakko-Heikki Heusala <jheusala@iki.fi>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
View
20 cli.js
@@ -0,0 +1,20 @@
+/* Builder for simple command line utils */
+var cli = module.exports = {};
+
+/* Core implementation for CLI applications */
+cli.run = function(commands) {
+ var optimist = require('optimist'),
+ argv = optimist
+ .usage('Usage: $0 COMMAND [argument(s)]')
+ .argv,
+ name = argv._.shift(),
+ fn = commands[name];
+ if(fn && commands.hasOwnProperty(name) && (typeof fn === 'function')) {
+ commands[name].apply(commands, argv._);
+ } else {
+ console.error('Error: Unknown command: ' + name);
+ optimist.showHelp();
+ }
+}
+
+/* EOF */
View
@@ -0,0 +1,57 @@
+#!/usr/bin/env node
+
+var commands = module.exports = {},
+ basedir = process.env.HOME || __dirname,
+ db = require('filedb').open(basedir + '/.joker-cli.json'),
+ foreach = require('snippets').foreach,
+ rpad = require('snippets').rpad,
+ dmapi = require('joker-dmapi');
+
+// FIXME: Change filedb so that it doesn't save backups or it can be opted out
+
+/* Event when database becomes ready */
+db.on('ready', function() {
+ db.hostname = db.hostname || 'dmapi.joker.com';
+ db.username = db.username || '';
+ db.password = db.password || '';
+
+ /* */
+ dmapi.on('error', function(err) {
+ console.log("Error: " + err);
+ });
+
+ if(db.auth_key) {
+ dmapi.config({'auth_key':db.auth_key});
+ } else {
+ dmapi.login({'hostname':db.hostname, 'username':db.username, 'password':db.password}, function(err, res) {
+ if(err) {
+ console.log('Error: ' + err);
+ return;
+ }
+ db.auth_key = res.auth_key;
+ db.commit();
+ });
+ }
+});
+
+/* Help command */
+commands.help = function() {
+ console.log('Commands:');
+ console.log(' config list -- list configuration');
+ console.log(' config set KEY=VALUE -- set configuration');
+ console.log(' login -- login to DMAPI');
+ console.log(' query-domain-list -- list domains');
+};
+
+/* List domains */
+commands['query-domain-list'] = function() {
+ db.whenReady(function() {
+ dmapi.queryDomainList(function(domains) {
+
+ });
+ });
+};
+
+require('./cli.js').run(commands);
+
+/* EOF */
View
@@ -0,0 +1,20 @@
+{
+ "author": "",
+ "name": "joker",
+ "version": "0.0.0",
+ "repository": {
+ "url": ""
+ },
+ "private": true,
+ "engines": {
+ "node": ">= 0.6.10"
+ },
+ "dependencies": {
+ "optimist": ">= 0.0.1",
+ "snippets": ">= 0.0.1",
+ "filedb": "https://github.com/jheusala/node-filedb/tarball/master",
+ "joker-dmapi": "https://github.com/jheusala/node-joker-dmapi/tarball/master"
+ },
+ "devDependencies": {},
+ "optionalDependencies": {}
+}

0 comments on commit 8c60df7

Please sign in to comment.