Class: Hedra::CLI
- Inherits:
-
Thor
- Object
- Thor
- Hedra::CLI
- Defined in:
- lib/hedra/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #audit(url) ⇒ Object
- #compare(url1, url2) ⇒ Object
- #export(format) ⇒ Object
- #scan(target) ⇒ Object
- #watch(url) ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
50 51 52 |
# File 'lib/hedra/cli.rb', line 50 def self.exit_on_failure? true end |
Instance Method Details
#audit(url) ⇒ Object
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 |
# File 'lib/hedra/cli.rb', line 90 def audit(url) setup_logging client = build_http_client analyzer = Analyzer.new begin response = client.get(url) result = analyzer.analyze(url, response.headers.to_h) if [:json] output = JSON.pretty_generate(result) if [:output] File.write([:output], output) say "Audit saved to #{[:output]}", :green unless [:quiet] else puts output end else print_detailed_result(result) end rescue StandardError => e log_error("Audit failed: #{e.}") exit 1 end end |
#compare(url1, url2) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/hedra/cli.rb', line 143 def compare(url1, url2) setup_logging client = build_http_client analyzer = Analyzer.new begin response1 = client.get(url1) response2 = client.get(url2) result1 = analyzer.analyze(url1, response1.headers.to_h) result2 = analyzer.analyze(url2, response2.headers.to_h) print_comparison(result1, result2) rescue StandardError => e log_error("Comparison failed: #{e.}") exit 1 end end |
#export(format) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/hedra/cli.rb', line 165 def export(format) unless %w[json csv].include?(format) say "Invalid format: #{format}. Use json or csv.", :red exit 1 end results = [:input] ? JSON.parse(File.read([:input])) : [] exporter = Exporter.new exporter.export(results, format, [:output]) say "Exported to #{[:output]}", :green unless [:quiet] end |
#scan(target) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/hedra/cli.rb', line 64 def scan(target) setup_logging urls = [:file] ? read_urls_from_file(target) : [target] client = build_http_client analyzer = Analyzer.new results = [] with_concurrency(urls, [:concurrency]) do |url| response = client.get(url) result = analyzer.analyze(url, response.headers.to_h) results << result print_result(result) unless [:quiet] || [:output] rescue StandardError => e log_error("Failed to scan #{url}: #{e.}") end export_results(results) if [:output] end |
#watch(url) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/hedra/cli.rb', line 120 def watch(url) setup_logging client = build_http_client analyzer = Analyzer.new say "Watching #{url} every #{[:interval]} seconds. Press Ctrl+C to stop.", :cyan loop do begin response = client.get(url) result = analyzer.analyze(url, response.headers.to_h) print_result(result) rescue StandardError => e log_error("Watch check failed: #{e.}") end sleep [:interval] end rescue Interrupt say "\nStopped watching.", :yellow end |