Module: Envdoctor::CLI
- Defined in:
- lib/envdoctor/cli.rb
Overview
Command-line entry point.
Class Method Summary collapse
Class Method Details
.run(argv) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/envdoctor/cli.rb', line 11 def run(argv) dir = "." strict = false parser = OptionParser.new do |o| o. = "Usage: envdoctor scan [options]" o.on("-d", "--dir DIR", "Project root (default: cwd)") { |v| dir = v } o.on("--strict", "Treat warnings as errors") { strict = true } end args = argv.dup args.shift if args.first == "scan" parser.parse!(args) root = File.(dir) findings = Scanner.scan(root) errors = findings.select { |f| f.severity == "error" } warnings = findings.select { |f| f.severity == "warning" } puts "ENVIRONMENT AUDIT" puts "=" * 40 if findings.empty? puts "\nNo issues found." return 0 end unless errors.empty? puts "\nErrors" errors.each { |f| puts " x #{f.name} #{f.origin.file}:#{f.origin.line} #{f.}" } end unless warnings.empty? puts "\nWarnings" warnings.each { |f| puts " ! #{f.name} #{f.origin.file}:#{f.origin.line} #{f.}" } end puts "\nSummary: #{errors.length} error(s), #{warnings.length} warning(s)" (!errors.empty? || (strict && !warnings.empty?)) ? 1 : 0 end |