@@ -62,7 +62,7 @@ exports.init = function (cli) {
6262 } ;
6363
6464 context . skipCache = true ;
65- var domains = domain . doDomainsGet ( context , _ ) ;
65+ var domains = domain . client ( context ) . getDomains ( context , _ ) ;
6666
6767 if ( name ) {
6868
@@ -86,7 +86,6 @@ exports.init = function (cli) {
8686 cli . interaction . formatOutput ( domains , function ( data ) {
8787 if ( data . length > 0 ) {
8888 log . table ( data , function ( row , item ) {
89- //var parsedName = WebsitesClient.parseSiteName(item.name);
9089 row . cell ( $ ( 'Name' ) , item . name ) ;
9190 row . cell ( $ ( 'Records' ) , item . record_count ) ;
9291 row . cell ( $ ( 'Expires' ) , item . expires_on ) ;
@@ -112,7 +111,7 @@ exports.init = function (cli) {
112111 self . lookupDomainName ( context , _ ) ;
113112
114113 context . skipCache = true ;
115- var d = domain . doDomainGet ( context , _ ) ;
114+ var d = domain . client ( context ) . getDomain ( context , _ ) ;
116115
117116 var format = [
118117 [ $ ( 'Id' ) , 'id' ] ,
@@ -159,7 +158,7 @@ exports.init = function (cli) {
159158 throw new Error ( util . format ( $ ( 'Can\'t add domain %s because it already exists.' ) , context . domain . name ) ) ;
160159 }
161160
162- var d = domain . doDomainAdd ( context , _ ) ;
161+ var d = domain . client ( context ) . addDomain ( context , _ ) ;
163162
164163 var format = [
165164 [ $ ( 'Id' ) , 'id' ] ,
@@ -221,83 +220,143 @@ exports.init = function (cli) {
221220 var self = this ;
222221 self . lookupDomainName ( context , _ ) ;
223222
224- var shouldDelete = options . quiet || cli . interaction . confirm ( $ ( 'This will permanently remove the domain from your account and cannot be undone. Are you sure? ' ) , _ ) ;
225- if ( ! shouldDelete ) {
223+ var shouldContinue = options . quiet || cli . interaction . confirm ( $ ( 'This will permanently remove the domain from your account and cannot be undone. Are you sure? ' ) , _ ) ;
224+ if ( ! shouldContinue ) {
225+ log . warn ( 'Domain delete cancelled.' ) ;
226226 return ;
227227 }
228228
229- return domain . doDomainDelete ( context , _ ) ;
229+ return domain . client ( context ) . deleteDomain ( context , _ ) ;
230230 } ,
231231
232- domain . checkCommand = function ( name , options , _ ) {
232+ domain . resetCommand = function ( name , options , _ ) {
233233 var context = {
234234 subscription : profile . current . getSubscription ( options . subscription ) . id ,
235235 domain : {
236236 name : name
237237 }
238238 } ;
239239
240- promptForDomainName ( _ ) ;
240+ var self = this ;
241+ self . promptForDomainName ( context , _ ) ;
241242
242243 var domains = context . domain . name . split ( ',' ) ;
243244 var results = [ ] ;
245+ var domainClient = domain . client ( context ) ;
246+ var shouldContinue = options . quiet || cli . interaction . confirm ( $ ( 'This will reset the domain token and prevent api access with the current token.\nYou will need to access the api using the new domain token.\nAre you sure? ' ) , _ ) ;
247+ if ( ! shouldContinue ) {
248+ log . warn ( 'Domain token reset cancelled.' ) ;
249+ return ;
250+ }
244251 if ( domains . length > 1 ) {
245- // var checks = [];
246- // var contexts = [];
247- // __.each(domains, function(d) {
248- // contexts.push({
249- // subscription: context.subscription,
250- // domain: {
251- // name: d
252- // }
253- // });
254- // });
255-
256- // __.each(contexts, function(c) {
257- // checks.push(function(_) {
258- // return domain.doDomainCheck(c, _);
259- // });
260- // });
261252
262253 results = async . map ( domains , function ( d , _ ) {
263- domain . doDomainCheck ( {
254+ domainClient . resetToken ( {
264255 subscription : context . subscription ,
265256 domain : {
266257 name : d
267258 }
268259 } , _ ) ;
269260 } , _ ) ;
270261 results = results . sort ( sortByName ) ;
271- //results = async.parallel(checks, _);
272262 } else {
273- results = [ domain . doDomainCheck ( context , _ ) ] ;
263+ results = [ domainClient . resetToken ( context , _ ) ] ;
274264 }
265+ log . info ( 'Successfully reset domain token:' ) ;
266+ log . table ( results , function ( row , item ) {
267+ row . cell ( $ ( 'Id' ) , item . id ) ;
268+ row . cell ( $ ( 'Name' ) , item . name ) ;
269+ row . cell ( $ ( 'Token' ) , item . token ) ;
270+ } ) ;
275271
276- var format = [
277- [ $ ( 'Name' ) , 'name' ] ,
278- [ $ ( 'Status' ) , 'status' ] ,
279- [ $ ( 'Price' ) , null , function ( value ) {
280- return accounting . formatMoney ( value . price , value . currency_symbol ) ;
281- } ]
282- ] ;
272+ } ,
273+
274+ domain . pushCommand = function ( useremail , contactid , name , options , _ ) {
275+ useremail = cli . interaction . promptIfNotGiven ( $ ( 'The new account\'s email address: ' ) , useremail , _ ) ;
276+ contactid = cli . interaction . promptIfNotGiven ( $ ( 'The new account\'s registrant ID: ' ) , contactid , _ ) ;
283277
284- //log.report(format, d);
278+ var context = {
279+ subscription : profile . current . getSubscription ( options . subscription ) . id ,
280+ domain : {
281+ name : name
282+ } ,
283+ push : {
284+ new_user_email : useremail ,
285+ contact_id : contactid
286+ }
287+ } ;
288+
289+ var self = this ;
290+ self . promptForDomainName ( context , _ ) ;
291+
292+ var domains = context . domain . name . split ( ',' ) ;
293+ var results = [ ] ;
294+ var domainClient = domain . client ( context ) ;
295+ var shouldContinue = options . quiet || cli . interaction . confirm ( $ ( 'Once a domain is pushed you will no longer be able to access it through your account.\nYou will need to access it using the new account\'s credentials.\nAre you sure? ' ) , _ ) ;
296+ if ( ! shouldContinue ) {
297+ log . warn ( 'Domain push cancelled.' ) ;
298+ return ;
299+ }
285300
301+ if ( domains . length > 1 ) {
302+
303+ results = async . map ( domains , function ( d , _ ) {
304+ domainClient . pushDomain ( {
305+ subscription : context . subscription ,
306+ domain : {
307+ name : d
308+ } ,
309+ push : context . push
310+ } , _ ) ;
311+ } , _ ) ;
312+ results = results . sort ( sortByName ) ;
313+ } else {
314+ results = [ domainClient . pushDomain ( context , _ ) ] ;
315+ }
316+ log . info ( 'Successfully pushed the following domains:' ) ;
286317 log . table ( results , function ( row , item ) {
287- //var parsedName = WebsitesClient.parseSiteName( item.name );
318+ row . cell ( $ ( 'Id' ) , item . id ) ;
288319 row . cell ( $ ( 'Name' ) , item . name ) ;
289- row . cell ( $ ( 'Status' ) , item . status ) ;
290- row . cell ( $ ( 'Price' ) , accounting . formatMoney ( item . price , item . currency_symbol ) ) ;
320+ row . cell ( $ ( 'New Account' ) , useremail ) ;
291321 } ) ;
292322
293- function promptForDomainName ( _ ) {
294- log . silly ( 'promptForDomainName' ) ;
295- if ( context . domain . name === undefined ) {
296- log . help ( $ ( 'Need a domain name' ) ) ;
297- context . domain . name = cli . interaction . prompt ( $ ( 'Domain: ' ) , _ ) ;
323+ } ,
324+
325+ domain . checkCommand = function ( name , options , _ ) {
326+ var context = {
327+ subscription : profile . current . getSubscription ( options . subscription ) . id ,
328+ domain : {
329+ name : name
298330 }
331+ } ;
332+
333+ var self = this ;
334+ self . promptForDomainName ( context , _ ) ;
335+
336+ var domains = context . domain . name . split ( ',' ) ;
337+ var results = [ ] ;
338+ var domainClient = domain . client ( context ) ;
339+ if ( domains . length > 1 ) {
340+
341+ results = async . map ( domains , function ( d , _ ) {
342+ domainClient . checkDomain ( {
343+ subscription : context . subscription ,
344+ domain : {
345+ name : d
346+ }
347+ } , _ ) ;
348+ } , _ ) ;
349+ results = results . sort ( sortByName ) ;
350+ } else {
351+ results = [ domainClient . checkDomain ( context , _ ) ] ;
299352 }
300353
354+ log . table ( results , function ( row , item ) {
355+ row . cell ( $ ( 'Name' ) , item . name ) ;
356+ row . cell ( $ ( 'Status' ) , item . status ) ;
357+ row . cell ( $ ( 'Price' ) , accounting . formatMoney ( item . price , item . currency_symbol ) ) ;
358+ } ) ;
359+
301360 } ,
302361
303362 domain . command ( 'list [name]' )
@@ -319,61 +378,36 @@ exports.init = function (cli) {
319378 . option ( '-q --quiet' , $ ( 'quiet mode, do not ask for delete confirmation' ) )
320379 . execute ( domain . deleteCommand ) ;
321380
322- domain . command ( 'check [name]' )
323- . description ( $ ( 'Check if a domain is available for registration..' ) )
324- . execute ( domain . checkCommand ) ;
325-
326- domain . doDomainsGet = function ( options , callback ) {
327- var domainClient = new DomainClient ( cli , options . subscription ) ;
328- return domainClient . getDomains ( options , callback ) ;
329- } ;
330-
331- domain . doDomainGet = function ( options , callback ) {
332- var domainClient = new DomainClient ( cli , options . subscription ) ;
333- return domainClient . getDomain ( options , callback ) ;
334- } ;
335-
336- domain . doDomainAdd = function ( options , callback ) {
337- var domainClient = new DomainClient ( cli , options . subscription ) ;
338- return domainClient . addDomain ( options , callback ) ;
339- } ;
340-
341- domain . doDomainDelete = function ( options , callback ) {
342- var domainClient = new DomainClient ( cli , options . subscription ) ;
343- return domainClient . deleteDomain ( options , callback ) ;
344- } ;
345-
346- domain . doDomainCheck = function ( options , callback ) {
347- var domainClient = new DomainClient ( cli , options . subscription ) ;
348- return domainClient . checkDomain ( options , callback ) ;
349- } ;
350-
351- domain . doRecordsGet = function ( options , callback ) {
352- var domainClient = new DomainClient ( cli , options . subscription ) ;
353- return domainClient . getRecords ( options , callback ) ;
354- } ;
381+ domain . command ( 'reset [name]' )
382+ . description ( $ ( 'Reset a domain token' ) )
383+ . option ( '-q --quiet' , $ ( 'quiet mode, do not ask for confirmation' ) )
384+ . execute ( domain . resetCommand ) ;
355385
356- domain . doRecordGet = function ( options , callback ) {
357- var domainClient = new DomainClient ( cli , options . subscription ) ;
358- return domainClient . getRecord ( options , callback ) ;
359- } ;
386+ domain . command ( 'push [useremail] [contactid] [name]' )
387+ . usage ( '[options] <useremail> <contactid> [name]' )
388+ . description ( $ ( 'Move a domain from the current account to another' ) )
389+ . option ( '-u --useremail <useremail>' , $ ( 'The new account\'s email address.' ) )
390+ . option ( '-c --contactid <contactid>' , $ ( 'The new account\'s registrant ID.' ) )
391+ . option ( '-q --quiet' , $ ( 'quiet mode, do not ask for confirmation' ) )
392+ . execute ( domain . pushCommand ) ;
360393
361- domain . doRecordAdd = function ( options , callback ) {
362- var domainClient = new DomainClient ( cli , options . subscription ) ;
363- return domainClient . addRecord ( options , callback ) ;
364- } ;
394+ domain . command ( 'check [name]' )
395+ . description ( $ ( 'Check if a domain is available for registration' ) )
396+ . execute ( domain . checkCommand ) ;
365397
366- domain . doRecordUpdate = function ( options , callback ) {
367- var domainClient = new DomainClient ( cli , options . subscription ) ;
368- return domainClient . updateRecord ( options , callback ) ;
398+ domain . client = function ( options ) {
399+ return new DomainClient ( cli , options . subscription ) ;
369400 } ;
370401
371- domain . doRecordDelete = function ( options , callback ) {
372- var domainClient = new DomainClient ( cli , options . subscription ) ;
373- return domainClient . deleteRecord ( options , callback ) ;
374- } ;
402+ domain . promptForDomainName = function ( context , _ ) {
403+ log . silly ( 'promptForDomainName' ) ;
404+ if ( context . domain . name === undefined ) {
405+ log . help ( $ ( 'Need a domain name' ) ) ;
406+ context . domain . name = cli . interaction . prompt ( $ ( 'Domain: ' ) , _ ) ;
407+ }
408+ }
375409
376- // TODO: remove all these "site ."" function and just call websiteClient directly.
410+ // TODO: remove all these "domain ."" function and just call domainClient directly.
377411 domain . lookupDomainName = function ( options , callback ) {
378412 var domainClient = new DomainClient ( cli , options . subscription ) ;
379413 return domainClient . lookupDomainName ( options , callback ) ;
0 commit comments