Class: Asciidoctor::Confluence::Invoker

Inherits:
Object
  • Object
show all
Defined in:
lib/asciidoctor/confluence/invoker.rb

Class Method Summary collapse

Class Method Details

.invoke(args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/asciidoctor/confluence/invoker.rb', line 11

def self.invoke(args)
  begin
    orig_stdout, orig_stderr = $stdout, $stderr
    captured_stdout, captured_stderr = StringIO.new, StringIO.new
    $stdout, $stderr = captured_stdout, captured_stderr

    options = Asciidoctor::Confluence::Options.parse! args
    unless invoke_helper_or_version(args)
      publisher = Asciidoctor::Confluence::Publisher.new options
      publisher.publish
    else
      return 0
    end
  ensure
    $stderr = orig_stdout
    $stdout = orig_stderr

    $stderr.puts captured_stderr.string
    $stdout.puts captured_stdout.string
  end
end

.invoke_helper_or_version(args) ⇒ Object



33
34
35
36
# File 'lib/asciidoctor/confluence/invoker.rb', line 33

def self.invoke_helper_or_version(args)
  helpers = %w(-h --help -V --version)
  args.size == 1 && helpers.include?(args[0])
end