Class: Lutaml::Cli::Uml::FindCommand
- Inherits:
-
Object
- Object
- Lutaml::Cli::Uml::FindCommand
- Includes:
- SharedHelpers
- Defined in:
- lib/lutaml/cli/uml/find_command.rb
Overview
FindCommand finds elements by criteria
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ FindCommand
constructor
A new instance of FindCommand.
-
#run(lur_path) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity.
Methods included from SharedHelpers
#load_repository, #normalize_path
Constructor Details
#initialize(options = {}) ⇒ FindCommand
Returns a new instance of FindCommand.
15 16 17 |
# File 'lib/lutaml/cli/uml/find_command.rb', line 15 def initialize( = {}) @options = .transform_keys(&:to_sym) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/lutaml/cli/uml/find_command.rb', line 13 def @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 |
# File 'lib/lutaml/cli/uml/find_command.rb', line 19 def self.(thor_class, _method_name) thor_class.long_desc <<-DESC Find elements matching specific criteria. Examples: lutaml uml find model.lur --stereotype interface lutaml uml find model.lur --package ModelRoot::Core lutaml uml find model.lur --pattern "^Building.*" DESC thor_class.option :stereotype, type: :string, desc: "Filter by stereotype" thor_class.option :package, type: :string, desc: "Filter by package" thor_class.option :pattern, type: :string, desc: "Match name pattern" 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) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
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 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/lutaml/cli/uml/find_command.rb', line 39 def run(lur_path) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity # Load the repository from the LUR file repo = load_repository(lur_path, lazy: [:lazy]) # Get results based on the filter type results = if [:pattern] # e.g. "^Building.*" types = [[:type] || :class] repo.search([:pattern], types: types) elsif [:stereotype] repo.find_classes_by_stereotype([:stereotype]) elsif [:package] repo.classes_in_package([:package], recursive: false) else [] end # Extract classes from the nested structure classes = case results when Array if results.length == 2 && results[0] == :classes results[1] # Extract the actual classes array else results # Assume it's already an array of classes end when NilClass [] else [results] # Wrap single result in array end if classes.nil? || classes.empty? filter_desc = if [:pattern] "pattern: #{[:pattern]}" elsif [:stereotype] "stereotype: #{[:stereotype]}" elsif [:package] "package: #{[:package]}" else "criteria" end puts "No elements found matching #{filter_desc}" return end output = classes.map do |cls| cls.respond_to?(:name) ? (cls.name || cls.to_s) : cls.to_s end # output result based on the format option case [:format] when "json" puts output.to_json when "yaml" puts output.to_yaml else puts output.join("\n") end rescue Thor::Error raise rescue ArgumentError => e raise Thor::Error, e. rescue StandardError => e raise Thor::Error, "Find command failed: #{e.}" end |