Class: Wikiwiki::CLI::Commands::Attachment::Show

Inherits:
Base
  • Object
show all
Defined in:
lib/wikiwiki/cli/commands/attachment/show.rb

Overview

Show attachment metadata

Instance Method Summary collapse

Instance Method Details

#call(page_name:, file_name:, out: $stdout, err: $stderr, **options) ⇒ void

This method returns an undefined value.

Execute the show command

Parameters:

  • page_name (String)

    name of the page

  • file_name (String)

    name of the attachment file

  • options (Hash)

    command options including wiki_id, auth, json, verbose, out, err



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/wikiwiki/cli/commands/attachment/show.rb', line 21

def call(page_name:, file_name:, out: $stdout, err: $stderr, **options)
  wiki = create_wiki(out:, err:, **options)
  attachment = wiki.attachment(page_name:, attachment_name: file_name)

   = attachment.to_h.except(:content).transform_values {|v| v.is_a?(Time) ? v.iso8601 : v }

  if options[:json]
    out.puts Formatter::JSON.new.format()
  else
    out.puts "Page: #{metadata[:page_name]}"
    out.puts "Name: #{metadata[:name]}"
    out.puts "Size: #{metadata[:size]} bytes"
    out.puts "Time: #{metadata[:time]}"
    out.puts "Type: #{metadata[:type]}"
    say("Attachment metadata retrieved", out:, **options)
  end
end