diff --git a/commands/commands.go b/commands/commands.go index 5253f3c7d..87c7cf126 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -95,29 +95,36 @@ func (args *GetDNSConfigArgs) flags() []cli.Flag { // GetDNSConfig reads the json-formatted IR file. Or executes javascript. All depending on flags provided. func GetDNSConfig(args GetDNSConfigArgs) (*models.DNSConfig, error) { - if args.JSONFile != "" { + var err error + cfg := &models.DNSConfig{} + + if args.JSONFile == "" { + // No IR file specified. Generate the IR by running dnsconfig.json + // as normal. + cfg, err = ExecuteDSL(args.ExecuteDSLArgs) + if err != nil { + return nil, err + } + } else { + // Read an IR file. f, err := os.Open(args.JSONFile) if err != nil { return nil, err } defer f.Close() dec := json.NewDecoder(f) - cfg := &models.DNSConfig{} if err = dec.Decode(cfg); err != nil { return nil, err } - return preloadProviders(cfg, nil) } - return preloadProviders(ExecuteDSL(args.ExecuteDSLArgs)) + + return preloadProviders(cfg) } // the json only contains provider names inside domains. This denormalizes the data for more // convenient access patterns. Does everything we need to prepare for the validation phase, but // cannot do anything that requires the credentials file yet. -func preloadProviders(cfg *models.DNSConfig, err error) (*models.DNSConfig, error) { - if err != nil { - return cfg, err - } +func preloadProviders(cfg *models.DNSConfig) (*models.DNSConfig, error) { //build name to type maps cfg.RegistrarsByName = map[string]*models.RegistrarConfig{} cfg.DNSProvidersByName = map[string]*models.DNSProviderConfig{}