1919
2020/* jshint unused: false */
2121
22+ var async = require ( 'async' ) ;
2223var __ = require ( 'underscore' ) ;
2324var util = require ( 'util' ) ;
2425var wrap = require ( 'wordwrap' ) . hard ( 0 , 75 ) ;
2526var datejs = require ( 'datejs' ) ;
27+ var accounting = require ( 'accounting' ) ;
2628
2729var Constants = require ( '../../util/constants' ) ;
2830var 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