Class: Wikiwiki::CLI::Commands::Page::Get
- Defined in:
- lib/wikiwiki/cli/commands/page/get.rb
Overview
Get page content
Instance Method Summary collapse
-
#call(page_name:, output_file: nil, force: false, out: $stdout, err: $stderr) ⇒ void
Execute the get command.
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
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 |