Class: Unitsdb::Commands::Get
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Unitsdb::Commands::Base
Instance Method Details
#get(id) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/unitsdb/commands/get.rb', line 6 def get(id) id_type = @options[:id_type] format = @options[:format] || "text" database = load_database(@options[:database]) entity = database.get_by_id(id: id, type: id_type) if entity.nil? puts "No entity found with ID: '#{id}'" return end if %w[json yaml].include?(format.downcase) print_serialized(entity, format.downcase) else EntityPresenter.new(entity).print_details end rescue Unitsdb::Errors::DatabaseError => e raise Unitsdb::Errors::DatabaseLoadError, "Failed to load database: #{e.}" rescue StandardError => e raise Unitsdb::Errors::CLIRuntimeError, "Get failed: #{e.}" end |