Class: Xsdvi::CLI

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

Overview

Command-line interface for XSDVI

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/xsdvi/cli.rb', line 9

def self.exit_on_failure?
  true
end

Instance Method Details

#compare(input) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/xsdvi/cli.rb', line 118

def compare(input)
  unless File.exist?(input)
    puts "Error: XSD file '#{input}' not found!"
    exit(1)
  end

  puts "=" * 60
  puts "XsdVi Comparison Tool"
  puts "=" * 60
  puts "Schema: #{input}"
  puts ""

  begin
    generator = Comparison::DualGenerator.new(input, options)
    result = generator.generate

    puts ""
    puts "=" * 60
    puts "Comparison Complete!"
    puts "=" * 60
    puts ""
    puts "Output directory: #{result[:output_dir]}"
    puts "HTML comparison:  #{result[:html_file]}"
    puts ""

    if result[:java][:file_count] && result[:java][:generation_time] && result[:java][:generation_time]
      puts "Java:  #{result[:java][:total_size_kb]} KB, " \
           "#{result[:java][:file_count]} file(s), " \
           "#{result[:java][:generation_time]}s"
    end

    if result[:ruby][:file_count] && result[:ruby][:generation_time] && result[:ruby][:generation_time]
      puts "Ruby:  #{result[:ruby][:total_size_kb]} KB, " \
           "#{result[:ruby][:file_count]} file(s), " \
           "#{result[:ruby][:generation_time]}s"
    end

    puts ""

    if options[:open]
      open_in_browser(result[:html_file])
    else
      puts "Open #{result[:html_file]} in your browser to view the comparison"
    end
  rescue StandardError => e
    puts ""
    puts "Error: #{e.message}"
    puts e.backtrace.first(5).join("\n") if ENV["DEBUG"]
    exit(1)
  end
end

#generate(*inputs) ⇒ Object



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
92
93
94
# File 'lib/xsdvi/cli.rb', line 37

def generate(*inputs)
  if inputs.empty?
    puts "Error: No input files specified"
    exit(1)
  end

  # Validate input files exist
  inputs.each do |input|
    unless File.exist?(input)
      puts "Error: XSD file '#{input}' not found!"
      exit(1)
    end
  end

  # Process options
  root_node_name = options[:root_node_name]
  one_node_only = options[:one_node_only]
  one_node_only = true if root_node_name == "all"
  output_path = options[:output_path]

  # Determine style mode
  style_mode = determine_style_mode(options)

  # Process each input file
  builder = Tree::Builder.new
  xsd_handler = XsdHandler.new(builder)
  writer_helper = Utils::Writer.new
  svg_generator = SVG::Generator.new(writer_helper)

  svg_generator.hide_menu_buttons = one_node_only

  apply_style_settings(svg_generator, style_mode, options)

  inputs.each do |input|
    # Special handling for -r all: generate file for each element
    if root_node_name == "all"
      process_all_elements(
        input,
        xsd_handler,
        svg_generator,
        builder,
        writer_helper,
        output_path,
      )
    else
      process_input_file(
        input,
        xsd_handler,
        svg_generator,
        builder,
        writer_helper,
        root_node_name,
        one_node_only,
        output_path,
      )
    end
  end
end