@@ -66,7 +66,7 @@ exports.init = function (cli) {
6666 row . cell ( $ ( 'Id' ) , item . id ) ;
6767 //}
6868 row . cell ( $ ( 'Type' ) , item . record_type ) ;
69- row . cell ( $ ( 'Name' ) , item . name ) ;
69+ row . cell ( $ ( 'Name' ) , item . name || context . domain . name ) ;
7070 row . cell ( $ ( 'TTL' ) , item . ttl ) ;
7171 row . cell ( $ ( 'Content' ) , item . content . length > 50 ? item . content . substr ( 0 , 50 ) + '...' : item . content ) ;
7272 } ) ;
@@ -76,6 +76,90 @@ exports.init = function (cli) {
7676 } ) ;
7777 } ;
7878
79+ domainRecords . addCommand = function ( recordname , type , content , name , options , _ ) {
80+ recordname = cli . interaction . promptIfNotGiven ( $ ( 'Record Name (Leave blank to create a record for the root domain.): ' ) , recordname , _ ) ;
81+ type = cli . interaction . chooseIfNotGiven ( $ ( 'Record Type: ' ) , $ ( 'Getting types' ) , type ,
82+ function ( cb ) {
83+ cb ( null , [ 'A' , 'ALIAS' , 'CNAME' , 'MX' , 'SPF' , 'URL' , 'TXT' , 'NS' , 'SRV' , 'NAPTR' , 'PTR' , 'AAAA' , 'SSHFP' , 'HINFO' , 'POOL' ] ) ;
84+ } , _ ) ;
85+
86+ if ( utils . ignoreCaseEquals ( type , 'A' ) ) {
87+ type = 'A' ;
88+ } else if ( utils . ignoreCaseEquals ( type , 'ALIAS' ) ) {
89+ type = 'ALIAS' ;
90+ } else if ( utils . ignoreCaseEquals ( type , 'CNAME' ) ) {
91+ type = 'CNAME' ;
92+ } else if ( utils . ignoreCaseEquals ( type , 'MX' ) ) {
93+ type = 'MX' ;
94+ } else if ( utils . ignoreCaseEquals ( type , 'SPF' ) ) {
95+ type = 'SPF' ;
96+ } else if ( utils . ignoreCaseEquals ( type , 'URL' ) ) {
97+ type = 'URL' ;
98+ } else if ( utils . ignoreCaseEquals ( type , 'TXT' ) ) {
99+ type = 'TXT' ;
100+ } else if ( utils . ignoreCaseEquals ( type , 'NS' ) ) {
101+ type = 'NS' ;
102+ } else if ( utils . ignoreCaseEquals ( type , 'SRV' ) ) {
103+ type = 'SRV' ;
104+ } else if ( utils . ignoreCaseEquals ( type , 'NAPTR' ) ) {
105+ type = 'NAPTR' ;
106+ } else if ( utils . ignoreCaseEquals ( type , 'PTR' ) ) {
107+ type = 'PTR' ;
108+ } else if ( utils . ignoreCaseEquals ( type , 'AAAA' ) ) {
109+ type = 'AAAA' ;
110+ } else if ( utils . ignoreCaseEquals ( type , 'SSHFP' ) ) {
111+ type = 'SSHFP' ;
112+ } else if ( utils . ignoreCaseEquals ( type , 'HINFO' ) ) {
113+ type = 'HINFO' ;
114+ } else if ( utils . ignoreCaseEquals ( type , 'POOL' ) ) {
115+ type = 'POOL' ;
116+ } else {
117+ throw new Error ( $ ( 'Invalid record type. Valid types are: A, ALIAS, CNAME, MX, SPF, URL, TXT, NS, SRV, NAPTR, PTR, AAAA, SSHFP, HINFO, POOL' ) ) ;
118+ }
119+ content = cli . interaction . promptIfNotGiven ( $ ( 'Record Content: ' ) , content , _ ) ;
120+
121+ var context = {
122+ subscription : profile . current . getSubscription ( options . subscription ) . id ,
123+ domain : {
124+ name : name
125+ } ,
126+ record : { }
127+ } ;
128+
129+ var recordName = options . recordname || '' ;
130+
131+ var r = {
132+ name : recordName ,
133+ record_type : type ,
134+ content : content
135+ } ;
136+
137+ if ( options . ttl ) {
138+ r [ 'ttl' ] = options . ttl ;
139+ }
140+
141+ if ( options . priority ) {
142+ r [ 'prio' ] = options . priority ;
143+ }
144+
145+ context . record = r ;
146+ domain . lookupDomainName ( context , _ ) ;
147+
148+ var record = domain . doRecordAdd ( context , _ ) ;
149+
150+ var format = [
151+ [ $ ( 'Id' ) , 'id' ] ,
152+ [ $ ( 'Name' ) , 'name' ] ,
153+ [ $ ( 'Type' ) , 'record_type' ] ,
154+ [ $ ( 'TTL' ) , 'ttl' ] ,
155+ [ $ ( 'Content' ) , 'content' ] ,
156+ ] ;
157+
158+ log . info ( 'Successfully added record:' ) ;
159+ log . report ( format , record ) ;
160+
161+ } ,
162+
79163 domainRecords . command ( 'list [name]' )
80164 . usage ( '[options] [name]' )
81165 . description ( $ ( 'Show your domain dns records' ) )
@@ -84,4 +168,14 @@ exports.init = function (cli) {
84168 . option ( '-d --details' , $ ( 'Show extra information about the records' ) )
85169 . execute ( domainRecords . listCommand ) ;
86170
171+ domainRecords . command ( 'add [recordname] [type] [content] [name]' )
172+ . usage ( '[options] <recordname> <type> <content> [name]' )
173+ . description ( $ ( 'Add a dns record to your domain' ) )
174+ . option ( '-r --recordname <recordname>' , $ ( 'Record name. Use an empty string to create a record for the root domain.' ) )
175+ . option ( '-t --type <type>' , $ ( 'Type of record to add (A, CNAME, MX, etc.)' ) )
176+ . option ( '-c --content <content>' , $ ( 'Record content.' ) )
177+ . option ( '-ttl --ttl <ttl>' , $ ( 'Record TTL.' ) )
178+ . option ( '-p --priority <priority>' , $ ( 'Record Priority.' ) )
179+ . execute ( domainRecords . addCommand ) ;
180+
87181} ;
0 commit comments