Module: Razor::CLI::Format

Extended by:
Forwardable
Defined in:
lib/razor/cli/format.rb

Constant Summary collapse

PriorityKeys =
%w[ id name spec ]
SpecNames =
{
  "/spec/object/policy" => "Policy",
  "/spec/object/tag" => "Tag",
  "/spec/object/reference" => "reference"
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.spec_name(spec) ⇒ Object



14
15
16
17
18
19
# File 'lib/razor/cli/format.rb', line 14

def self.spec_name(spec)
  path = spec && URI.parse(spec).path
  SpecNames[path] || path
rescue => e
  spec
end

Instance Method Details

#format_document(doc, parse = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/razor/cli/format.rb', line 21

def format_document(doc, parse = nil)
  format = parse && parse.format
  arguments = parse && parse.stripped_args
  doc = Razor::CLI::Document.new(doc, format)

  return "There are no items for this query." if doc.items.empty?
  return format_command_help(doc, parse.show_api_help?) if parse && parse.show_command_help?

  case (doc.format_view['+layout'] or 'list')
  when 'list'
    format_objects(doc.items) + String(additional_details(doc, parse, arguments)).chomp
  when 'table'
    case doc.items
      when Array then
        get_table(doc.items, doc.format_view) + String(additional_details(doc, parse, arguments))
      else doc.to_s
    end
  else
    raise ArgumentError, "Unrecognized view format #{doc.format_view['+layout']}"
  end
end