-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
177 lines (159 loc) · 3.92 KB
/
main.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env node
/* jshint asi:true */
var nomnom = require('nomnom')
var mongolab = require('./index.js')
function createAccount(opts) {
var m = mongolab({username: opts.username, password: opts.password})
m.createAccount(opts, function(err, res) {
if (err) {
console.log("Error creating account: ", res.body.message)
return
}
console.log("Account created!")
})
}
function viewAccounts(opts) {
var m = mongolab({username: opts.username, password: opts.password})
m.viewAccounts(function(err, res) {
if (err) {
console.log("Error viewing accounts: ", res.body.message)
return
}
console.log(res.body)
})
}
function viewPartner(opts) {
var m = mongolab({username: opts.username, password: opts.password})
m.viewPartner(function(err, res) {
if (err) {
console.log("Error viewing partner: ", res.body.message)
return
}
console.log(res.body)
})
}
function listDatabases(opts) {
var m = mongolab({username: opts.username, password: opts.password})
m.listDatabases(opts.accountName, function(err, res) {
if (err) {
console.log("Error listing databases: ", res.body.message)
return
}
console.log(res.body)
})
}
function viewDatabase(opts) {
var m = mongolab({username: opts.username, password: opts.password})
m.viewDatabase(opts.accountName, opts.databaseName, function(err, res) {
if (err) {
console.log("Error viewing database: ", res.body.message)
return
}
console.log(res.body)
})
}
function deleteDatabase(opts) {
var m = mongolab({username: opts.username, password: opts.password})
m.deleteDatabase(opts.accountName, opts.databaseName, function(err, res) {
if (err) {
console.log("Error deleteing database: ", res.body.message)
return
}
console.log(res.body)
})
}
function createDatabase(opts) {
var m = mongolab({username: opts.username, password: opts.password})
m.createDatabase(opts, function(err, res) {
if (err) {
console.log("Error creating database: ", res.body.message)
return
}
console.log(res.body)
})
}
nomnom.option('username', {
abbr: 'u',
required: true,
help: "MongoLab Partner API username"
})
.option('password', {
abbr: 'p',
required: true,
help: "MongoLab Partner API password"
})
nomnom.command('createAccount')
.options({
adminUser: {
required: true
},
adminEmail: {
required: true
},
accountName: {
required: true,
help: "Account name to create"
}
})
.callback(createAccount)
nomnom.command('viewAccounts').callback(viewAccounts)
nomnom.command('viewPartner').callback(viewPartner)
nomnom.command('listDatabases')
.options({
accountName: {
required: true,
help: "Account name to list databases for"
}
})
.callback(listDatabases)
nomnom.command('viewDatabase')
.options({
accountName: {
required: true,
help: "Account name to view database for"
},
databaseName: {
required: true,
help: "Databases name to view"
}
})
.callback(viewDatabase)
nomnom.command('deleteDatabase')
.options({
accountName: {
required: true,
help: "Account name to delete databases for"
},
databaseName: {
required: true,
help: "Databases name to delete"
}
})
.callback(deleteDatabase)
nomnom.command('createDatabase')
.options({
accountName: {
required: true,
help: "Account name to create this database under"
},
databaseName: {
required: true,
help: "Name of database to create"
},
plan: {
default: "sandbox"
},
cloud: {
default: 'JYC_us-sw-1'
},
databaseUsername: {
required: true,
help: "Username of admin user to create in database"
},
databasePassword: {
required: true,
help: "Password of admin user to create in database"
}
})
.callback(createDatabase)
nomnom.parse()