Module: Mihari::Commands::Validator

Included in:
Mihari::CLI::Validator
Defined in:
lib/mihari/commands/validator.rb

Class Method Summary collapse

Class Method Details

.included(thor) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mihari/commands/validator.rb', line 6

def self.included(thor)
  thor.class_eval do
    desc "rule [PATH]", "Validate rule file format"
    #
    # Validate format of a rule
    #
    # @param [String] path
    #
    # @return [nil]
    #
    def rule(path)
      rule = Structs::Rule.from_path_or_id(path)

      begin
        rule.validate!
        Mihari.logger.info "Valid format. The input is parsed as the following:\n#{rule.data.to_yaml}"
      rescue RuleValidationError
        nil
      end
    end
  end
end