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)


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/udb/cli.rb', line 84

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
  resolver =
    Udb::Resolver.new(
      std_path_override: Pathname.new(options[:std]),
      gen_path_override: Pathname.new(options[:gen]),
      custom_path_override: Pathname.new(options[:custom])
    )
  begin
    cfg_arch = resolver.cfg_arch_for(cfg_file.realpath)
  rescue InvalidConfigError
    say "Config is #{pastel.red.bold("invalid")}"
    exit 1
  end
  result = cfg_arch.valid?

  if result.valid
    say "Config #{pastel.bold(cfg_arch.name)} is #{pastel.green.bold("valid")}"
  else
    say "Config #{pastel.bold(cfg_arch.name)} is #{pastel.red.bold("invalid")}"
    say ""
    result.reasons.each do |r|
      say "  * #{pastel.yellow.bold(r.gsub("\n", "\n    "))}"
    end
    exit 1
  end
end

#specObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/udb/cli.rb', line 49

def spec

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

  resolver =
    Udb::Resolver.new(
      std_path_override: Pathname.new(options[:std]),
      gen_path_override: Pathname.new(options[:gen]),
      custom_path_override: Pathname.new(options[:custom])
    )
  cfg_arch = resolver.cfg_arch_for(cfg_file.realpath)

  puts "Checking arch files against schema.."
  cfg_arch.validate($resolver, show_progress: true)
  puts "All files validate against their schema"
end