Class: Wikiwiki::CLI::Commands::Page::Get

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

Overview

Get page content

Instance Method Summary collapse

Instance Method Details

#call(page_name:, output_file: nil, force: false, out: $stdout, err: $stderr) ⇒ void

This method returns an undefined value.

Execute the get command

Parameters:

  • page_name (String)

    name of the page to get

  • output_file (String, nil) (defaults to: nil)

    optional output file path

  • force (Boolean) (defaults to: false)

    whether to overwrite existing file

  • out (IO) (defaults to: $stdout)

    output stream

  • err (IO) (defaults to: $stderr)

    error stream



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/wikiwiki/cli/commands/page/get.rb', line 23

def call(page_name:, output_file: nil, force: false, out: $stdout, err: $stderr, **)
  wiki = create_wiki(out:, err:, **)

  # Check if output file exists when not forcing
  if output_file && File.exist?(output_file) && !force
    raise ArgumentError, "File '#{output_file}' already exists. Use --force to overwrite."
  end

  page = wiki.page(page_name:)

  if output_file
    File.write(output_file, page.source)
    say("Page '#{page_name}' (#{page.source.bytesize} bytes) saved to #{output_file}", out:, **)
  else
    out.puts page.source
  end
end