Class: Wikiwiki::CLI::Commands::Attachment::Get
- Defined in:
- lib/wikiwiki/cli/commands/attachment/get.rb
Overview
Download attachment from a page
Instance Method Summary collapse
-
#call(page_name:, file_name:, directory: nil, force: false, out: $stdout, err: $stderr) ⇒ void
Execute the get command.
Instance Method Details
#call(page_name:, file_name:, directory: nil, force: false, out: $stdout, err: $stderr) ⇒ void
This method returns an undefined value.
Execute the get command
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/wikiwiki/cli/commands/attachment/get.rb', line 25 def call(page_name:, file_name:, directory: nil, force: false, out: $stdout, err: $stderr, **) wiki = create_wiki(out:, err:, **) output_path = directory ? File.join(directory, file_name) : file_name if File.exist?(output_path) && !force raise ArgumentError, "File '#{output_path}' already exists. Use --force to overwrite." end = wiki.(page_name:, attachment_name: file_name) File.binwrite(output_path, .content) say("Attachment '#{file_name}' (#{attachment.content.bytesize} bytes) saved to #{output_path}", out:, **) end |