-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (31 loc) · 907 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env node
var fs = require('fs');
var optimist = require('optimist')
var argv = optimist.usage(fs.readFileSync(__dirname + '/USAGE.txt', 'utf8'))
.argv;
var env = require('superenv')('stripe');
var stripe = require('stripe')(env.key);
var resource = argv._[0];
var command = argv._[1];
if (!resource || !stripe[resource]) {
console.error('Invalid resource');
optimist.showHelp();
process.exit(1);
}
if (!command || !stripe[resource][command]) {
console.error('Invalid command');
optimist.showHelp();
process.exit(1);
}
var objects = [];
(function list(offset) {
stripe[resource][command]({
count: 100,
offset: 100 * offset
}, function(err, i) {
if (err) throw err;
if (i.data.length == 0) return console.log(JSON.stringify(objects, null, 4));
objects = objects.concat(i.data);
list(++offset);
});
})(0);