mirror of
https://github.com/amark/gun.git
synced 2025-06-07 14:46:44 +00:00
66 lines
1.7 KiB
JavaScript
66 lines
1.7 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
var repl = require('repl').start('aws-sdk> '),
|
|
replEval = repl.eval,
|
|
replHistory = require('repl.history'),
|
|
defaultOptions = {
|
|
logger: process.stdout,
|
|
region: process.env.AWS_REGION || 'us-east-1'
|
|
};
|
|
|
|
|
|
function customEval(cmd, context, filename, callback) {
|
|
replEval(cmd, context, filename, function(err, value) {
|
|
if (err) {
|
|
callback(err, null);
|
|
return;
|
|
}
|
|
|
|
if (value && value.constructor === AWS.Request) {
|
|
if (!value.__hasBeenSent__) {
|
|
value.__hasBeenSent__ = true;
|
|
try {
|
|
value.on('complete', function consoleDataExtraction(resp) {
|
|
context.data = resp.data;
|
|
context.error = resp.error;
|
|
callback(resp.error, resp.data);
|
|
});
|
|
context.request = value;
|
|
context.data = null;
|
|
context.error = null;
|
|
context.response = value.send();
|
|
} catch (err2) {
|
|
callback(err2, null);
|
|
return;
|
|
}
|
|
}
|
|
} else {
|
|
callback(null, value);
|
|
}
|
|
});
|
|
}
|
|
|
|
var AWS = repl.context.AWS = require('../lib/aws');
|
|
repl.eval = customEval;
|
|
|
|
// context variables
|
|
repl.context.data = null;
|
|
repl.context.error = null;
|
|
repl.context.request = null;
|
|
repl.context.response = null;
|
|
|
|
// setup REPL history
|
|
replHistory(repl, process.env.HOME + '/.node_history');
|
|
|
|
// load services as defined instances
|
|
for (var key in AWS) {
|
|
if (AWS[key].serviceIdentifier) {
|
|
var svcClass = AWS[key];
|
|
var svc = new svcClass(defaultOptions);
|
|
svc.with = function(config) {
|
|
return new this.constructor.__super__(AWS.util.merge(this.config, config));
|
|
};
|
|
repl.context[svcClass.serviceIdentifier] = svc;
|
|
}
|
|
}
|