Class: OKF::CLI::Validate

Inherits:
Command
  • Object
show all
Defined in:
lib/okf/cli/validate.rb

Overview

The §9 conformance judge: is this legal OKF? Binary and tolerant — it is forbidden from failing a bundle over a broken link or a missing optional field, which is lint's job. Exit 1 when non-conformant.

Constant Summary

Constants inherited from Command

Command::DUCK_TYPE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

hidden?, #initialize

Constructor Details

This class inherits a constructor from OKF::CLI::Command

Class Method Details

.groupObject



13
14
15
# File 'lib/okf/cli/validate.rb', line 13

def self.group
  :judge
end

.help_rowsObject



17
18
19
20
21
# File 'lib/okf/cli/validate.rb', line 17

def self.help_rows
  [
    [ "validate  <dir|@slug> [--json]", "check OKF v0.1 conformance" ]
  ]
end

.idObject



9
10
11
# File 'lib/okf/cli/validate.rb', line 9

def self.id
  :validate
end

Instance Method Details

#call(argv) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/okf/cli/validate.rb', line 23

def call(argv)
  options = { json: false }
  parser = OptionParser.new do |o|
    o.banner = "Usage: okf validate <dir|@slug> [--json]"
    json_flags(o, options, "emit a JSON report")
    help_flag(o)
  end
  dir = positional_dir(parser, argv) or return 2

  result = OKF::Bundle::Folder.load(dir).validate
  options[:json] ? print_validation_json(dir, result) : print_validation(dir, result)
  result.valid? ? 0 : 1
end