Class: Xcop::CLI
- Inherits:
-
Object
- Object
- Xcop::CLI
- Defined in:
- lib/xcop/cli.rb
Overview
Command line interface.
- Author
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
Copyright (c) 2017-2026 Yegor Bugayenko
- License
MIT
Constant Summary collapse
- EXTENSIONS =
%w[xml xsd xhtml xsl html].freeze
Class Method Summary collapse
-
.expand(dir) ⇒ Object
Recursively collect XML-like files inside a directory.
Instance Method Summary collapse
-
#fix ⇒ Object
Fix them all.
-
#initialize(files, nocolor: false) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
Class Method Details
.expand(dir) ⇒ Object
Recursively collect XML-like files inside a directory.
23 24 25 |
# File 'lib/xcop/cli.rb', line 23 def self.(dir) EXTENSIONS.flat_map { |ext| Dir.glob(File.join(dir, '**', "*.#{ext}")) }.sort end |
Instance Method Details
#fix ⇒ Object
Fix them all. The block, when given, receives the file path and a
status symbol that is :fixed when the file was rewritten and
:untouched when the file was already canonical.
47 48 49 50 51 52 |
# File 'lib/xcop/cli.rb', line 47 def fix @files.each do |f| status = Xcop::Document.new(f).fix yield(f, status) if block_given? end end |
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/xcop/cli.rb', line 27 def run @files.each do |f| doc = Xcop::Document.new(f) diff = doc.diff(nocolor: @nocolor) unless diff.empty? puts(diff) raise(StandardError, "Invalid XML formatting in #{f}") end errors = doc.validate unless errors.empty? puts(errors.join("\n")) raise(StandardError, "XSD validation failed in #{f}") end yield(f) if block_given? end end |