Navigation Menu

Skip to content

Commit

Permalink
Add new command line utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 3, 2012
1 parent ab856cd commit 0915970
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 7 deletions.
35 changes: 35 additions & 0 deletions bin/cs-create-domain
@@ -0,0 +1,35 @@
#!/usr/bin/env node

var program = require('commander');
var commandLine = require(__dirname + '/../lib/command-line');

program
.version(require('../package').version)
.usage('[options] --domain-name <domain name>')
.option('-d, --domain-name <domain name>',
'name for the new domain',
String)
.option('--database-path <path>',
'database path [' + commandLine.defaultDatabasePath + ']',
String,
commandLine.defaultDatabasePath)
.parse(process.argv);

if (!program.domainName) {
console.log('You must specify the domain name.');
return false;
}

console.log('Creating domain [' + program.domainName + ']');

var context = commandLine.getContext(program.databasePath);
var domain = new commandLine.Domain(program.domainName, context);
if (domain.exists()) {
console.log('The domain [' + program.domainName + '] already exists.');
return false;
}

domain.createSync();

consoole.log('Domain endpoints are currently being created. ' +
'Use cs-describe-domain to check for endpoints.');
42 changes: 42 additions & 0 deletions bin/cs-describe-domain
@@ -0,0 +1,42 @@
#!/usr/bin/env node

var program = require('commander');
var commandLine = require(__dirname + '/../lib/command-line');

program
.version(require('../package').version)
.usage('[options]')
.option('-d, --domain-name <domain name>',
'name for the new domain',
String)
.option('-all, --show-all',
'name for the new domain',
String)
.option('--database-path <path>',
'database path [' + commandLine.defaultDatabasePath + ']',
String,
commandLine.defaultDatabasePath)
.parse(process.argv);

function report(domain) {
console.log('Domain Name %s', domain.name);
console.log('Document Service Endpoint %s', domain.getDocumentsEndpoint('localhost'));
console.log('Search Endpoint %s', domain.getSearchEndpoint('localhost'));
console.log('Searchable Documents %s', domain.searchableDocumentsCount);
console.log('Index Fields %s', domain.name);
// console.log('Ranking Fields %s', ;
console.log('SearchPartitionCount %s', domain.searchPartitionCount);
console.log('SearchInstanceCount %s', domain.searchPartitionCount);
console.log('SearchInstanceType %s', domain.searchInstanceType);
}

var context = commandLine.getContext(program.databasePath);
if (program.domainName) {
var domain = new Domain(program.domainName, context);
report(domain);
} else {
Domain.getAll(context).forEach(function(domain, index) {
if (index) console.log('========================================');
report(domain);
});
}
12 changes: 5 additions & 7 deletions bin/gcs
Expand Up @@ -2,9 +2,7 @@

var gcsServer = require(__dirname + '/../lib/server');
var program = require('commander');

var defaultDatabasePath = process.env.HOME + '/.gcs/database/gcs';
var defaultPrivilegedRanges = '127.0.0.0/8';
var commandLine = require(__dirname + '/../lib/command-line');

program
.version(require('../package').version)
Expand All @@ -14,14 +12,14 @@ program
Number,
7575)
.option('--database-path <path>',
'database path [' + defaultDatabasePath + ']',
'database path [' + commandLine.defaultDatabasePath + ']',
String,
defaultDatabasePath)
commandLine.defaultDatabasePath)
.option('--privilege <ip range>',
'list of IP ranges for privileged client '+
'[' + defaultPrivilegedRanges + ']',
'[' + commandLine.defaultPrivilegedRanges + ']',
String,
defaultPrivilegedRanges)
commandLine.defaultPrivilegedRanges)
.parse(process.argv);

var server;
Expand Down
11 changes: 11 additions & 0 deletions lib/command-line.js
@@ -0,0 +1,11 @@
var nroonga = require('./wrapped-nroonga');
var context;

exports.defaultDatabasePath = process.env.HOME + '/.gcs/database/gcs';
exports.defaultPrivilegedRanges = '127.0.0.0/8';
exports.getContext = function(databasePath) {
return context ||
(context = new nroonga.Context(databasePath || exports.defaultDatabasePath));
};

exports.Domain = require('./database/domain');

0 comments on commit 0915970

Please sign in to comment.