#!/usr/bin/env node
const program = require('commander');
const config = require('config').config;
const record = require('../model/record');
const GcDnsClient = require('../model/gcdns');
const CommonUtil = require('../util/common');

program
  .command('list')
  .description('list resource record sets')
  .action(function(){
    const client = new GcDnsClient();
    client.listPromise()
    .then(function(result){
      console.log(JSON.stringify(result, null, 2));
    })
    .catch(function(err){
      console.log(err)
    });
  });

program
  .command('register <host> <ip> [ttl]')
  .description('register A/AAAA record')
  .action(function(host, ip, ttl){
    const ipVersion = CommonUtil.validateIpVersion(ip);
    const recordType = CommonUtil.getAddressRecordType(ipVersion);
    if (recordType == null) {
      console.log('Invalid IP address');
      return;
    }

    const recordTtl = parseInt(config.ttl || ttl, 10);
    if (isNaN(recordTtl)) {
      console.log('Invalid TTL');
      return;
    }

    record.create(host, ip, recordType, ttl, function(err, result){
      console.log(JSON.stringify(result, null, 2));
    });
  });

program.parse(process.argv);

@@ -13,16 +13,17 @@
 nv node%0A
+%0A
 const pr
@@ -400,24 +400,18 @@
 hen(
-function(
 result
-)
+ =%3E 
 %7B%0A  
@@ -482,21 +482,15 @@
 tch(
-function(err)
+err =%3E 
 %7B%0A  
@@ -505,16 +505,19 @@
 ole.
-log
+error
 (err)
+;
 %0A   
@@ -812,35 +812,37 @@
 %7B%0A      console.
-log
+error
 ('Invalid IP add
@@ -905,22 +905,22 @@
 Int(
-config.
 ttl %7C%7C 
+config.
 ttl,
@@ -967,19 +967,21 @@
 console.
-log
+error
 ('Invali
@@ -1050,17 +1050,23 @@
 rdType, 
-t
+recordT
 tl, func

Fix ttl