Class: Udb::CliCommands::Validate

Inherits:
SubCommandBase show all
Includes:
Thor::Actions
Defined in:
lib/udb/cli.rb

Instance Method Summary collapse

Instance Method Details

#cfg(name_or_path) ⇒ Object

Raises:

  • (ArgumentError)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/udb/cli.rb', line 42

def cfg(name_or_path)
  raise ArgumentError, "Spec directory does not exist: #{options[:std]}" unless File.directory?(options[:std])

  cfg_file =
    if File.file?(name_or_path)
      Pathname.new(name_or_path)
    elsif File.file?("#{options[:config_dir]}/#{name_or_path}.yaml")
      Pathname.new("#{options[:config_dir]}/#{name_or_path}.yaml")
    else
      raise ArgumentError, "Cannot find config: #{name_or_path}"
    end
  result = ConfiguredArchitecture.validate(cfg_file)

  cfg_spec = YAML.load_file(cfg_file)
  if result
    say "Config #{cfg_spec.fetch('name')} is valid"
  else
    say "Config #{cfg_spec.fetch('name')} is invalid"
    exit 1
  end
end