Class: Lutaml::Cli::InteractiveShell::QueryCommands

Inherits:
CommandBase
  • Object
show all
Defined in:
lib/lutaml/cli/interactive_shell/query_commands.rb

Instance Attribute Summary

Attributes inherited from CommandBase

#shell

Instance Method Summary collapse

Methods inherited from CommandBase

#bookmarks, #config, #current_path, #current_path=, #initialize, #last_results, #last_results=, #path_history, #repository

Constructor Details

This class inherits a constructor from Lutaml::Cli::InteractiveShell::CommandBase

Instance Method Details

#cmd_find(args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lutaml/cli/interactive_shell/query_commands.rb', line 7

def cmd_find(args)
  if args.empty?
    puts OutputFormatter.warning("Usage: find CLASS_NAME")
    return
  end

  query = args.join(" ")
  results = repository.search(query, types: [:class])

  if results[:class].empty?
    puts OutputFormatter.warning("No classes found matching '#{query}'")
  else
    puts OutputFormatter.colorize(
      "Found #{results[:class].size} class(es):", :cyan
    )
    display_class_results(results[:class])
  end
end

#cmd_results(_args) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/lutaml/cli/interactive_shell/query_commands.rb', line 64

def cmd_results(_args)
  if last_results.nil? || last_results.empty?
    puts OutputFormatter.warning("No previous results")
  else
    puts OutputFormatter.colorize(
      "Last results (#{last_results.size}):", :cyan
    )
    last_results.each_with_index do |item, i|
      puts "  #{i + 1}. #{item}"
    end
  end
end

#cmd_search(args) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/lutaml/cli/interactive_shell/query_commands.rb', line 48

def cmd_search(args)
  if args.empty?
    puts OutputFormatter.warning("Usage: search QUERY")
    return
  end

  query = args.join(" ")
  results = repository.search(query)

  if results.values.all?(&:empty?)
    puts OutputFormatter.warning("No results found for '#{query}'")
  else
    display_search_results(results)
  end
end

#cmd_show(args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/lutaml/cli/interactive_shell/query_commands.rb', line 26

def cmd_show(args)
  if args.empty?
    puts OutputFormatter.warning(
      "Usage: show class QNAME | show package PATH | show NUMBER",
    )
    return
  end

  subcommand = args[0].downcase

  case subcommand
  when "class"
    show_class(args[1..].join(" "))
  when "package"
    show_package(args[1..].join(" "))
  when /^\d+$/
    show_numbered_result(subcommand.to_i)
  else
    show_class(args.join(" "))
  end
end

#display_search_results(results) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/lutaml/cli/interactive_shell/query_commands.rb', line 120

def display_search_results(results)
  results.each do |type, items|
    next if items.empty?

    puts ""
    puts OutputFormatter.colorize(
      "#{type.to_s.capitalize} Results (#{items.size}):", :cyan
    )

    case type
    when :class
      display_class_results(items)
    when :attribute
      display_attribute_results(items)
    when :association
      display_association_results(items)
    end
  end
end

#show_class(qname) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/lutaml/cli/interactive_shell/query_commands.rb', line 77

def show_class(qname)
  cls = repository.find_class(qname)

  unless cls
    puts OutputFormatter.error("Class not found: #{qname}")
    return
  end

  if config[:icons]
    puts EnhancedFormatter.format_class_details_enhanced(cls)
  else
    display_class_plain(cls, qname)
  end
end

#show_numbered_result(number) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/lutaml/cli/interactive_shell/query_commands.rb', line 105

def show_numbered_result(number)
  if last_results.nil? || last_results.empty?
    puts OutputFormatter.warning("No previous results")
    return
  end

  index = number - 1
  if index.negative? || index >= last_results.size
    puts OutputFormatter.error("Invalid result number: #{number}")
    return
  end

  show_class(last_results[index])
end

#show_package(path) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/lutaml/cli/interactive_shell/query_commands.rb', line 92

def show_package(path)
  nav = shell.navigation
  path = nav.resolve_path(path)
  pkg = repository.find_package(path)

  unless pkg
    puts OutputFormatter.error("Package not found: #{path}")
    return
  end

  display_package_contents(pkg, path)
end