Class: Lutaml::Xsd::Commands::MetadataCommand::GetCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/lutaml/xsd/commands/metadata_command.rb

Overview

Get command implementation

Instance Attribute Summary

Attributes inherited from BaseCommand

#options

Instance Method Summary collapse

Constructor Details

#initialize(package_path, key, options) ⇒ GetCommand

Returns a new instance of GetCommand.



49
50
51
52
53
# File 'lib/lutaml/xsd/commands/metadata_command.rb', line 49

def initialize(package_path, key, options)
  super(options)
  @package_path = package_path
  @key = key
end

Instance Method Details

#runObject



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
# File 'lib/lutaml/xsd/commands/metadata_command.rb', line 55

def run
  pkg = SchemaRepositoryPackage.new(@package_path)
   = pkg.

  # Load metadata if not already loaded
  unless 
    validation = pkg.validate
    unless validation.valid?
      error "Failed to load package metadata"
      validation.errors.each { |err| error "  - #{err}" }
      exit 1
    end
     = validation.
  end

  # Filter out internal lutaml-model fields
   = .reject do |k, _|
    k.to_s.start_with?("_") || k == :using_default
  end

  # Show specific key or all
  if @key
    value = [@key.to_sym] || [@key]
    if value.nil?
      error "Metadata key '#{@key}' not found"
      exit 1
    end
    output value.to_s
  elsif options[:all]
    case options[:format]
    when "json"
      require "json"
      output JSON.pretty_generate()
    when "yaml"
      require "yaml"
      output .to_yaml
    else
      # Text format - table
      ()
    end
  else
    error "Please specify a KEY or use --all"
    exit 1
  end
rescue StandardError => e
  error "Failed to get metadata: #{e.message}"
  verbose_output e.backtrace.join("\n") if verbose?
  exit 1
end