Class: Lutaml::Cli::Uml::StatsCommand

Inherits:
Object
  • Object
show all
Includes:
SharedHelpers
Defined in:
lib/lutaml/cli/uml/stats_command.rb

Overview

StatsCommand shows repository statistics

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SharedHelpers

#load_repository, #normalize_path

Constructor Details

#initialize(options = {}) ⇒ StatsCommand

Returns a new instance of StatsCommand.



15
16
17
# File 'lib/lutaml/cli/uml/stats_command.rb', line 15

def initialize(options = {})
  @options = options.transform_keys(&:to_sym)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/lutaml/cli/uml/stats_command.rb', line 13

def options
  @options
end

Class Method Details

.add_options_to(thor_class, _method_name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/lutaml/cli/uml/stats_command.rb', line 19

def self.add_options_to(thor_class, _method_name)
  thor_class.long_desc <<-DESC
  Display statistics about the repository or a specific package.

  Examples:
    lutaml uml stats model.lur                  # Full repository stats
    lutaml uml stats model.lur --detailed       # Detailed breakdown
    lutaml uml stats model.lur --type diagrams  # Diagram-specific stats
  DESC

  thor_class.option :type, type: :string, default: "all",
                           desc: "Statistics type " \
                                 "(packages|classes|diagrams|all)"
  thor_class.option :detailed, type: :boolean, default: false,
                               desc: "Show detailed statistics"
  thor_class.option :format, type: :string, default: "text",
                             desc: "Output format (text|yaml|json)"
  thor_class.option :lazy, type: :boolean, default: false,
                           desc: "Use lazy loading"
end

Instance Method Details

#run(lur_path, _path = nil) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/lutaml/cli/uml/stats_command.rb', line 40

def run(lur_path, _path = nil) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  repo = load_repository(lur_path, lazy: options[:lazy])
  statistics = repo.statistics

  if options[:format] == "text"
    puts OutputFormatter.format_stats(statistics,
                                      detailed: options[:detailed])
  else
    puts OutputFormatter.format(statistics, format: options[:format])
  end
rescue Thor::Error
  raise
rescue ArgumentError => e
  raise Thor::Error, e.message
rescue StandardError => e
  raise Thor::Error, "Stats command failed: #{e.message}"
end