Class: Jekyll::Commands::AgentAudit

Inherits:
Jekyll::Command
  • Object
show all
Defined in:
lib/jekyll/agent_audit/command.rb

Defined Under Namespace

Modules: CommandParser, ParserErrors

Class Method Summary collapse

Class Method Details

.init_with_program(prog) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jekyll/agent_audit/command.rb', line 29

def init_with_program(prog)
  prog.command(:"agent:audit") do |command|
    command.singleton_class.prepend(CommandParser)
    command.syntax "agent:audit [options]"
    command.description "Audit rendered publication output"
    add_build_options(command)
    command.option "format", "--format FORMAT", "console or json"
    command.option "output", "--output PATH", "Write the report atomically"
    command.option "fail_on", "--fail-on LEVEL", "error, warning, or none"
    command.option "only", "--only RULES", "Comma-separated rule IDs"
    command.option "list_rules", "--list-rules", "List available rules"
    command.option "explain", "--explain RULE", "Explain a rule"
    command.option "verbose", "--verbose", "Include skipped checks"
    command.action { |_, options| process(options) }
  end
end

.process(options) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/jekyll/agent_audit/command.rb', line 46

def process(options)
  options = options.transform_keys(&:to_s)
  validate_only!(options)
  if options["list_rules"]
    write_output(render_rules(options), options["output"])
    return 0
  end
  if options["explain"]
    write_output(explain(options["explain"], options), options["output"])
    return 0
  end
  report = run_audit(options)
  format = options["format"] || report.to_h.dig("run", "effective_configuration", "format") || "console"
  output = render_report(report, format)
  write_output(output, options["output"])
  exit(report_exit_code(report))
rescue Jekyll::AgentAudit::ConfigurationError, ArgumentError => e
  if options && options["format"] == "json"
    write_output(render_error(e), options["output"])
  else
    warn "jekyll-agent-audit: #{e.message}"
  end
  exit 2
rescue SystemExit
  raise
rescue StandardError => e
  if options && options["format"] == "json"
    write_output(render_error(e), options["output"])
  else
    warn "jekyll-agent-audit: #{e.message}"
  end
  exit 2
end