Class: Vinter::CLI
- Inherits:
-
Object
- Object
- Vinter::CLI
- Defined in:
- lib/vinter/cli.rb
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #run(args) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
3 4 5 |
# File 'lib/vinter/cli.rb', line 3 def initialize @linter = Linter.new end |
Instance Method Details
#run(args) ⇒ Object
7 8 9 10 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 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 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/vinter/cli.rb', line 7 def run(args) if args.empty? puts "Usage: vinter [file.vim|directory] [--exclude=dir1,dir2]" return 1 end # Parse args: first non-option argument is the target path. exclude_value = nil target_path = nil args.each_with_index do |a, i| if a.start_with?("--exclude=") exclude_value = a.split("=", 2)[1] elsif a == "--exclude" exclude_value = args[i + 1] elsif !a.start_with?('-') && target_path.nil? target_path = a end end if target_path.nil? puts "Usage: vinter [file.vim|directory] [--exclude=dir1,dir2]" return 1 end unless File.exist?(target_path) puts "Error: File or directory not found: #{target_path}" return 1 end excludes = Array(exclude_value).flat_map { |v| v.to_s.split(',') }.map(&:strip).reject(&:empty?) vim_files = if File.directory?(target_path) find_vim_files(target_path, excludes) else # Check if single file is inside an excluded directory if excluded_file?(target_path, excludes, File.dirname(target_path)) [] else [target_path] end end if vim_files.empty? puts "No .vim files found in #{target_path}" return 0 end total_issues = 0 error_count = 0 vim_files.each do |file_path| content = File.read(file_path) issues = @linter.lint(content) total_issues += issues.length if issues.empty? puts "No issues found in #{file_path}" if vim_files.length == 1 else puts "Found #{issues.length} issues in #{file_path}:" if vim_files.length > 1 issues.each do |issue| type_str = case issue[:type] when :error then "ERROR" when :warning then "WARNING" when :rule then "RULE(#{issue[:rule]})" else "UNKNOWN" end line = issue[:line] || 1 column = issue[:column] || 1 puts "#{file_path}:#{line}:#{column}: #{type_str}: #{issue[:message]}" end error_count += 1 if issues.any? { |i| i[:type] == :error } end end if vim_files.length > 1 puts "\nProcessed #{vim_files.length} files, found #{total_issues} total issues" end return error_count > 0 ? 1 : 0 end |