Skip to content

Commit b2bde7b

Browse files
committed
Added domain check functionality and updated readme and command reference.
1 parent 4af45a5 commit b2bde7b

5 files changed

Lines changed: 161 additions & 71 deletions

File tree

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@ See the [command reference][3] for complete planned command structure.
1818

1919
---
2020
* Domains: `(command: dnsimple domain)`
21-
* List domains in your account
22-
* List domains in your account that match a wildcard filter (e.g. *.com)
23-
* Show details for a specific domain in your account
24-
* Add a domain to your account
25-
* Delete a domain from your account
21+
* List domains in your account `(command: dnsimple domain list)`
22+
* List domains in your account that match a wildcard filter (e.g. *.com) `(command: dnsimple domain list *.com)`
23+
* Show details for a specific domain in your account `(command: dnsimple domain show)`
24+
* Add a domain to your account `(command: dnsimple domain add)`
25+
* Delete a domain from your account `(command: dnsimple domain delete)`
26+
* Check availability of one more domains `(command: dnsimple domain check)`
2627
* Records: `(command: dnsimple domain record)`
27-
* Show DNS Records for a specific domain
28-
* Show DNS Records of a specific type (A, CNAME, TXT, NS, etc.) for a specific domain
29-
* Show DNS Records whose content matches a specific filter (e.g. \*spf\*)
30-
* Add DNS Records to a domain
31-
* Show details for a domain DNS Record
32-
* Update DNS Records for a domain
33-
* Delete DNS Records for a domain
28+
* Show DNS Records for a specific domain `(command: dnsimple domain record list)`
29+
* Show DNS Records of a specific type (A, CNAME, TXT, NS, etc.) for a specific domain `(command: dnsimple domain record list -t CNAME)`
30+
* Show DNS Records whose content matches a specific filter (e.g. \*spf\*) `(command: dnsimple domain record list -f *spf*)`
31+
* Add DNS Records to a domain `(command: dnsimple domain record add)`
32+
* Show details for a domain DNS Record `(command: dnsimple domain record show)`
33+
* Update DNS Records for a domain `(command: dnsimple domain record update)`
34+
* Delete DNS Records for a domain `(command: dnsimple domain record delete)`
3435

3536
---
3637
* Contacts: `(command: dnsimple contact)`

command-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
|- reset [domain]
2626
|- push [domain] -email -contact (Move the domain to another account)
2727
--------------
28-
|- check [domain]
28+
|- check [domains] (Check availability of one or more domains)
2929
|- register [domain]
3030
|- transfer (in) [domain]
3131
|- renew [domain]

lib/commands/domain/domain._js

Lines changed: 93 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919

2020
/* jshint unused: false */
2121

22+
var async = require('async');
2223
var __ = require('underscore');
2324
var util = require('util');
2425
var wrap = require('wordwrap').hard(0, 75);
2526
var datejs = require('datejs');
27+
var accounting = require('accounting');
2628

2729
var Constants = require('../../util/constants');
2830
var profile = require('../../util/profile');
@@ -216,6 +218,76 @@ exports.init = function (cli) {
216218
return domain.doDomainDelete(context, _);
217219
},
218220

221+
domain.checkCommand = function (name, options, _) {
222+
var context = {
223+
subscription: profile.current.getSubscription(options.subscription).id,
224+
domain: {
225+
name: name
226+
}
227+
};
228+
229+
promptForDomainName(_);
230+
231+
var domains = context.domain.name.split(',');
232+
var results = [];
233+
if (domains.length > 1) {
234+
// var checks = [];
235+
// var contexts = [];
236+
// __.each(domains, function(d) {
237+
// contexts.push({
238+
// subscription: context.subscription,
239+
// domain: {
240+
// name: d
241+
// }
242+
// });
243+
// });
244+
245+
// __.each(contexts, function(c) {
246+
// checks.push(function(_) {
247+
// return domain.doDomainCheck(c, _);
248+
// });
249+
// });
250+
251+
results = async.map(domains, function(d, _) {
252+
domain.doDomainCheck({
253+
subscription: context.subscription,
254+
domain: {
255+
name: d
256+
}
257+
}, _);
258+
}, _);
259+
//results = async.parallel(checks, _);
260+
} else {
261+
results = [domain.doDomainCheck(context, _)];
262+
}
263+
264+
var format = [
265+
[$('Name'), 'name'],
266+
[$('Status'), 'status'],
267+
[$('Price'), null, function (value) {
268+
return accounting.formatMoney(value.price, value.currency_symbol);
269+
}]
270+
];
271+
272+
//log.report(format, d);
273+
274+
log.table(results, function (row, item) {
275+
//var parsedName = WebsitesClient.parseSiteName(item.name);
276+
row.cell($('Name'), item.name);
277+
row.cell($('Status'), item.status);
278+
row.cell($('Price'), accounting.formatMoney(item.price, item.currency_symbol));
279+
});
280+
281+
function promptForDomainName(_) {
282+
log.silly('promptForDomainName');
283+
if (context.domain.name === undefined) {
284+
log.help($('Need a domain name'));
285+
context.domain.name = cli.interaction.prompt($('Domain: '), _);
286+
}
287+
}
288+
289+
},
290+
219291
domain.command('list [name]')
220292
.description($('List domains'))
221293
.option('-e --expiring', $('only show expiring domains'))
@@ -235,6 +307,15 @@ exports.init = function (cli) {
235307
.option('-q --quiet', $('quiet mode, do not ask for delete confirmation'))
236308
.execute(domain.deleteCommand);
237309

310+
domain.command('check [name]')
311+
.description($('Check if a domain is available for registration..'))
312+
.execute(domain.checkCommand);
313+
314+
domain.doDomainsGet = function (options, callback) {
315+
var domainClient = new DomainClient(cli, options.subscription);
316+
return domainClient.getDomains(options, callback);
317+
};
318+
238319
domain.doDomainGet = function (options, callback) {
239320
var domainClient = new DomainClient(cli, options.subscription);
240321
return domainClient.getDomain(options, callback);
@@ -250,34 +331,34 @@ exports.init = function (cli) {
250331
return domainClient.deleteDomain(options, callback);
251332
};
252333

253-
domain.doDomainsGet = function (options, callback) {
334+
domain.doDomainCheck = function (options, callback) {
254335
var domainClient = new DomainClient(cli, options.subscription);
255-
return domainClient.getDomains(options, callback);
336+
return domainClient.checkDomain(options, callback);
256337
};
257338

258-
domain.doRecordAdd = function (options, callback) {
339+
domain.doRecordsGet = function (options, callback) {
259340
var domainClient = new DomainClient(cli, options.subscription);
260-
return domainClient.addRecord(options, callback);
341+
return domainClient.getRecords(options, callback);
261342
};
262343

263-
domain.doRecordUpdate = function (options, callback) {
344+
domain.doRecordGet = function (options, callback) {
264345
var domainClient = new DomainClient(cli, options.subscription);
265-
return domainClient.updateRecord(options, callback);
346+
return domainClient.getRecord(options, callback);
266347
};
267348

268-
domain.doRecordDelete = function (options, callback) {
349+
domain.doRecordAdd = function (options, callback) {
269350
var domainClient = new DomainClient(cli, options.subscription);
270-
return domainClient.deleteRecord(options, callback);
351+
return domainClient.addRecord(options, callback);
271352
};
272353

273-
domain.doRecordGet = function (options, callback) {
354+
domain.doRecordUpdate = function (options, callback) {
274355
var domainClient = new DomainClient(cli, options.subscription);
275-
return domainClient.getRecord(options, callback);
356+
return domainClient.updateRecord(options, callback);
276357
};
277358

278-
domain.doRecordsGet = function (options, callback) {
359+
domain.doRecordDelete = function (options, callback) {
279360
var domainClient = new DomainClient(cli, options.subscription);
280-
return domainClient.getRecords(options, callback);
361+
return domainClient.deleteRecord(options, callback);
281362
};
282363

283364
// TODO: remove all these "site."" function and just call websiteClient directly.

0 commit comments

Comments
 (0)