Class: Wikiwiki::CLI::Commands::Attachment::Put
- Defined in:
- lib/wikiwiki/cli/commands/attachment/put.rb
Overview
Upload attachment to a page
Instance Method Summary collapse
-
#call(page_name:, file_path:, name: nil, force: false, out: $stdout, err: $stderr) ⇒ void
Execute the put command.
Instance Method Details
#call(page_name:, file_path:, name: nil, force: false, out: $stdout, err: $stderr) ⇒ void
This method returns an undefined value.
Execute the put command
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/wikiwiki/cli/commands/attachment/put.rb', line 28 def call(page_name:, file_path:, name: nil, force: false, out: $stdout, err: $stderr, **) wiki = create_wiki(out:, err:, **) = name || File.basename(file_path) content = File.binread(file_path) if content.bytesize > MAX_ATTACHMENT_SIZE raise ArgumentError, "File size (#{content.bytesize} bytes) exceeds maximum allowed size (#{MAX_ATTACHMENT_SIZE} bytes / 512 KiB)" end begin wiki.(page_name:, attachment_name:, content:) rescue ConflictError raise ArgumentError, "Attachment '#{attachment_name}' already exists. Use --force to overwrite." unless force wiki.(page_name:, attachment_name:) retry end say("Attachment '#{attachment_name}' uploaded to page '#{page_name}'", out:, **) end |