Class: Xcop::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/xcop/cli.rb

Overview

Command line interface.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2017-2025 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(files, nocolor: false) ⇒ CLI

Returns a new instance of CLI.



32
33
34
35
# File 'lib/xcop/cli.rb', line 32

def initialize(files, nocolor: false)
  @files = files
  @nocolor = nocolor
end

Instance Method Details

#fixObject

Fix them all.



50
51
52
53
54
55
# File 'lib/xcop/cli.rb', line 50

def fix
  @files.each do |f|
    Xcop::Document.new(f).fix
    yield(f) if block_given?
  end
end

#runObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/xcop/cli.rb', line 37

def run
  @files.each do |f|
    doc = Xcop::Document.new(f)
    diff = doc.diff(nocolor: @nocolor)
    unless diff.empty?
      puts diff
      raise "Invalid XML formatting in #{f}"
    end
    yield(f) if block_given?
  end
end