Class: Lutaml::Cli::Uml::SearchCommand

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

Overview

SearchCommand performs full-text search in model

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SharedHelpers

#load_repository, #normalize_path

Constructor Details

#initialize(options = {}) ⇒ SearchCommand

Returns a new instance of SearchCommand.



15
16
17
# File 'lib/lutaml/cli/uml/search_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/search_command.rb', line 13

def options
  @options
end

Class Method Details

.add_options_to(thor_class, _method_name) ⇒ Object

rubocop:disable Metrics/MethodLength



19
20
21
22
23
24
25
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/uml/search_command.rb', line 19

def self.add_options_to(thor_class, _method_name) # rubocop:disable Metrics/MethodLength
  thor_class.long_desc <<-DESC
  Perform full-text search across model elements.

  Examples:
    lutaml uml search model.lur "building"
    lutaml uml search model.lur "building" --type class
    lutaml uml search model.lur "urban" --in name documentation
  DESC

  thor_class.option :type, type: :array,
                           default: [
                             "class", "attribute",
                             "association"
                           ],
                           desc: "Types to search"
  thor_class.option :package, type: :string,
                              desc: "Filter by package path"
  thor_class.option :in, type: :array, default: ["name"],
                         desc: "Search in fields (name, documentation)"
  thor_class.option :format, type: :string, default: "table",
                             desc: "Output format " \
                                   "(text|table|yaml|json)"
  thor_class.option :limit, type: :numeric, default: 100,
                            desc: "Maximum results"
  thor_class.option :lazy, type: :boolean, default: false,
                           desc: "Use lazy loading"
end

Instance Method Details

#run(lur_path, query) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/lutaml/cli/uml/search_command.rb', line 48

def run(lur_path, query)
  repo = load_repository(lur_path, lazy: options[:lazy])
  types = options[:type].map(&:to_sym)
  search_fields = options[:in].map(&:to_sym)

  results = repo.search(query, types: types, fields: search_fields)

  display_search_results(results, query, repo)
end