Class: Asciidoctor::Confluence::Options

Inherits:
Asciidoctor::Cli::Options
  • Object
show all
Defined in:
lib/asciidoctor/confluence/options.rb

Constant Summary collapse

HOST_MISSING =
'FAILED: The hostname of the Confluence instance is missing'
SPACE_KEY_MISSING =
'FAILED: The spaceKey of the Confluence instance is missing'
TITLE_MISSING =
'FAILED: The title of the Confluence page is missing'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Options

Returns a new instance of Options.



13
14
15
16
17
# File 'lib/asciidoctor/confluence/options.rb', line 13

def initialize(options = {})
  super options
  self[:confluence] = options[:confluence] || {:update => false}
  self[:confluence][:auth] = {} if self[:confluence][:auth].nil?
end

Class Method Details

.parse!(*args) ⇒ Object



88
89
90
# File 'lib/asciidoctor/confluence/options.rb', line 88

def self.parse! (*args)
  Options.new.parse! args.flatten
end

Instance Method Details

#check_mandatory_optionsObject

Raises:



82
83
84
85
86
# File 'lib/asciidoctor/confluence/options.rb', line 82

def check_mandatory_options
  raise HOST_MISSING if self[:confluence][:host].nil?
  raise SPACE_KEY_MISSING if self[:confluence][:space_key].nil?
  raise TITLE_MISSING if self[:confluence][:title].nil?
end

#init_options(args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/asciidoctor/confluence/options.rb', line 31

def init_options(args)
  opts_parser = ::OptionParser.new do |opts|
    opts.banner = <<-EOS
Usage: asciidoctor-confluence --host HOSTNAME --spaceKey SPACEKEY --title TITLE [ASCIIDOCTOR OPTIONS]...  FILE...
    EOS

    opts.on('--host HOST', 'the hostname of the Confluence instance ') do |host|
      self[:confluence][:host] = host
    end

    opts.on('--spaceKey SPACEKEY', 'the Confluence space within the page will be created') do |spaceKey|
      self[:confluence][:space_key] = spaceKey
    end

    opts.on('--title TITLE', 'the title of the Confluence page') do |title|
      self[:confluence][:title] = title
    end

    opts.on('--pageid PAGEID', 'the id of the page to update') do |page_id|
      self[:confluence][:page_id] = page_id
      end

    opts.on('--update', 'indicate that the page must be updated instead of created') do
      self[:confluence][:update] = true
    end

    opts.on('--username USERNAME', 'the username used if credential are need to create the page') do |spaceKey|
      self[:confluence][:auth][:username] = spaceKey
    end

    opts.on('--password PASSWORD', 'the password used if credential are need to create the page') do |spaceKey|
      self[:confluence][:auth][:password] = spaceKey
    end

    opts.on_tail('-h', '--help', 'Show the full helper (including Asciidoctor helper)') do
      $stdout.puts opts, "\n\n"
      return Asciidoctor::Cli::Options.parse! ['-h']
    end

    opts.on_tail('-V', '--version', 'display the version and runtime environment (or -v if no other flags or arguments)') do
      $stdout.puts "Asciidoctor-confluence v#{Asciidoctor::Confluence::VERSION}\n"
      return Asciidoctor::Cli::Options.parse! ['-V']
    end

  end

  opts_parser.parse! args
  check_mandatory_options
end

#parse!(args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/asciidoctor/confluence/options.rb', line 19

def parse!(args)
    init_options args
    unless args.empty?
      base_options = super args
      if (base_options.is_a? ::Integer) && base_options == -1
        $stderr.puts 'There are some issue with the asciidoctor command'
      end
    end

    self
end