Class: Lutaml::Cli::Uml::TreeCommand
- Inherits:
-
Object
- Object
- Lutaml::Cli::Uml::TreeCommand
- Includes:
- SharedHelpers
- Defined in:
- lib/lutaml/cli/uml/tree_command.rb
Overview
TreeCommand shows hierarchical tree view
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ TreeCommand
constructor
A new instance of TreeCommand.
-
#run(lur_path, path = nil) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength.
Methods included from SharedHelpers
#load_repository, #normalize_path
Constructor Details
#initialize(options = {}) ⇒ TreeCommand
Returns a new instance of TreeCommand.
15 16 17 |
# File 'lib/lutaml/cli/uml/tree_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/tree_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/tree_command.rb', line 19 def self.(thor_class, _method_name) thor_class.long_desc <<-DESC Display a tree view of the package hierarchy. Examples: lutaml uml tree model.lur # Full tree lutaml uml tree model.lur ModelRoot::Core # Subtree lutaml uml tree model.lur --depth 2 # Limited depth DESC thor_class.option :depth, aliases: "-d", type: :numeric, desc: "Maximum depth to display" thor_class.option :show_counts, type: :boolean, default: true, desc: "Show class and diagram counts" 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lutaml/cli/uml/tree_command.rb', line 39 def run(lur_path, path = nil) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength unless File.exist?(lur_path) puts OutputFormatter.error("Package file not found: #{lur_path}") raise Thor::Error, "Package file not found: #{lur_path}" end path = normalize_path(path) repo = load_repository(lur_path, lazy: [:lazy]) tree_data = repo.package_tree(path, max_depth: [:depth]) unless tree_data puts OutputFormatter.error("Package not found: #{path}") raise Thor::Error, "Package not found: #{path}" end if [:format] == "text" puts display_tree_without_root(tree_data, show_counts: [:show_counts]) else puts OutputFormatter.format(tree_data, format: [:format]) end end |