├── lib └── asciidoctor │ ├── confluence │ ├── version.rb │ ├── invoker.rb │ └── options.rb │ ├── page.rb │ ├── confluence.rb │ └── confluence_api.rb ├── Gemfile ├── test └── Asciidoctor │ └── confluence │ ├── test.adoc │ ├── confluence_api_tests.rb │ ├── publisher_tests.rb │ └── options_tests.rb ├── Rakefile ├── .gitignore ├── bin └── asciidoctor-confluence ├── .rakeTasks ├── LICENSE.txt ├── asciidoctor-confluence.gemspec └── README.adoc /lib/asciidoctor/confluence/version.rb: -------------------------------------------------------------------------------- 1 | module Asciidoctor 2 | module Confluence 3 | VERSION = "0.0.2" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in asciidoctor-confluence.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /test/Asciidoctor/confluence/test.adoc: -------------------------------------------------------------------------------- 1 | = Hello (Ascii)Doc(umentation) 2 | 3 | Hey I've just published Asciidoctor into Confluence 4 | 5 | This is a list: 6 | 7 | * item 1 8 | * item 2 -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require 'rake/testtask' 3 | 4 | Rake::TestTask.new do |t| 5 | t.libs << 'test' 6 | end 7 | 8 | desc "Run tests" 9 | task :default => :test 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | *.bundle 11 | *.so 12 | *.o 13 | *.a 14 | mkmf.log 15 | *.iml 16 | *.gem -------------------------------------------------------------------------------- /bin/asciidoctor-confluence: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'rubygems' if RUBY_VERSION < '1.9' 4 | require File.join File.dirname(__FILE__), '../lib/asciidoctor/confluence/invoker' 5 | 6 | result_code = Asciidoctor::Confluence::Invoker.invoke ARGV 7 | exit result_code -------------------------------------------------------------------------------- /test/Asciidoctor/confluence/confluence_api_tests.rb: -------------------------------------------------------------------------------- 1 | require 'test/unit' 2 | require 'asciidoctor/confluence_api' 3 | 4 | class ConfluenceAPITests < Test::Unit::TestCase 5 | def test_build_content_api_without_ending_slash 6 | url = 'http://confluence.mydomain' 7 | api = Asciidoctor::Confluence::ConfluenceAPI.new({:host => url}, nil) 8 | assert_equal url+'/'+Asciidoctor::Confluence::ConfluenceAPI::API_CONTENT, api.url 9 | end 10 | 11 | def test_build_content_api_with_ending_slash 12 | url = 'http://confluence.mydomain/' 13 | api = Asciidoctor::Confluence::ConfluenceAPI.new({:host => url}, nil) 14 | assert_equal url+Asciidoctor::Confluence::ConfluenceAPI::API_CONTENT, api.url 15 | end 16 | 17 | 18 | end -------------------------------------------------------------------------------- /.rakeTasks: -------------------------------------------------------------------------------- 1 | 2 | 8 | -------------------------------------------------------------------------------- /lib/asciidoctor/page.rb: -------------------------------------------------------------------------------- 1 | class Page 2 | 3 | TYPE = 'page' 4 | REPRESENTATION = 'storage' 5 | @document 6 | 7 | attr_reader :page_id, :title, :space_key 8 | attr_writer :revision 9 | 10 | def initialize(space_key, title, document, page_id) 11 | @space_key = space_key 12 | @title = title 13 | @document = document 14 | @page_id = page_id 15 | @revision = nil 16 | end 17 | 18 | def to_json 19 | page = { 20 | :type => TYPE, 21 | :title => @title, 22 | :space => { 23 | :key => @space_key 24 | }, 25 | :body => { 26 | :storage => { 27 | :value => @document, 28 | :representation => REPRESENTATION 29 | } 30 | } 31 | } 32 | 33 | page[:version] = {:number => @revision} unless @revision.nil? 34 | page[:id] = @page_id unless @page_id.nil? 35 | 36 | JSON.generate page 37 | end 38 | end -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Guillaume Scheibel 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /lib/asciidoctor/confluence/invoker.rb: -------------------------------------------------------------------------------- 1 | require 'asciidoctor' 2 | require 'stringio' 3 | require 'asciidoctor/cli' 4 | require_relative './options' 5 | require_relative '../confluence/invoker' 6 | 7 | module Asciidoctor 8 | module Confluence 9 | 10 | class Invoker 11 | def self.invoke(args) 12 | begin 13 | orig_stdout, orig_stderr = $stdout, $stderr 14 | captured_stdout, captured_stderr = StringIO.new, StringIO.new 15 | $stdout, $stderr = captured_stdout, captured_stderr 16 | 17 | options = Asciidoctor::Confluence::Options.parse! args 18 | unless invoke_helper_or_version(args) 19 | publisher = Asciidoctor::Confluence::Publisher.new options 20 | publisher.publish 21 | end 22 | ensure 23 | $stderr = orig_stdout 24 | $stdout = orig_stderr 25 | 26 | $stderr.puts captured_stderr.string 27 | $stdout.puts captured_stdout.string 28 | end 29 | end 30 | 31 | def self.invoke_helper_or_version(args) 32 | helpers = %w(-h --help -V --version) 33 | args.size == 1 && helpers.include?(args[0]) 34 | end 35 | end 36 | 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /asciidoctor-confluence.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'asciidoctor/confluence/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "asciidoctor-confluence" 8 | spec.version = Asciidoctor::Confluence::VERSION 9 | spec.authors = ["Guillaume Scheibel"] 10 | spec.email = ["guillaume.scheibel@gmail.com"] 11 | spec.summary = "Publishing Asciidoctor content as Confluence page" 12 | spec.description = "Asciidoctor-Confluence allows to parse asciidoc files, transform them into HTML and then push them into a Confluence" 13 | spec.homepage = "http://asciidoctor.org" 14 | spec.license = "MIT" 15 | 16 | spec.files = `git ls-files -z`.split("\x0") 17 | spec.executables = ['asciidoctor-confluence'] #spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 18 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 19 | spec.require_paths = ["lib"] 20 | 21 | spec.add_development_dependency 'bundler', '~> 1.7' 22 | spec.add_development_dependency 'rake', '~> 10.4', '>= 10.4.2' 23 | spec.add_development_dependency 'test-unit', '~> 3.0', '>= 3.0.9' 24 | spec.add_development_dependency 'rspec', '~> 3.1.0', '>= 3.1' 25 | spec.add_development_dependency 'rspec-mocks', '~> 3.1.3', '>= 3.1' 26 | spec.add_development_dependency 'webmock', '~> 1.20.4', '>= 1.20' 27 | 28 | spec.add_runtime_dependency 'asciidoctor', '~> 1.5.2', '>= 1.5' 29 | spec.add_runtime_dependency 'faraday', '~> 0.9.1', '>= 0.9' 30 | spec.add_runtime_dependency 'json', '~> 1.8.2', '>= 1.8.2' 31 | end 32 | -------------------------------------------------------------------------------- /test/Asciidoctor/confluence/publisher_tests.rb: -------------------------------------------------------------------------------- 1 | require 'test-unit' 2 | require 'webmock/test_unit' 3 | require 'asciidoctor/confluence_api' 4 | require 'asciidoctor/confluence' 5 | 6 | #require 'asciidoctor-confluence/lib/asciidoctor/confluence' 7 | 8 | class PublisherTests < Test::Unit::TestCase 9 | def setup 10 | @orig_stderr = $stderr 11 | $stderr = StringIO.new 12 | 13 | @orig_stdout = $stdout 14 | $stdout = StringIO.new 15 | end 16 | 17 | def teardown 18 | $stderr = @orig_stderr 19 | @orig_stderr 20 | $stdout = @orig_stdout 21 | @orig_stdout = nil 22 | end 23 | 24 | def test_successful_publishing 25 | test_url = 'http://username:password@confluence.domain/'+Asciidoctor::Confluence::ConfluenceAPI::API_CONTENT 26 | host = 'http://confluence.domain/' 27 | webui = 'webui' 28 | response_body = JSON.generate ( { 29 | '_links' => { 30 | 'base' => host, 31 | 'webui' => webui 32 | } 33 | }) 34 | stub_request(:post, test_url).to_return(:status => 200, :body => response_body) 35 | auth = {:username => 'username', :password => 'password'} 36 | options = {:confluence => {:auth => auth, :host => host, :title => 'Asciidoctor Page'}, :input_files => ['test.adoc']} 37 | publisher = Asciidoctor::Confluence::Publisher.new options 38 | publish_result = publisher.publish 39 | assert_equal 0, publish_result 40 | assert_true $stdout.string.include? Asciidoctor::Confluence::Publisher::SUCCESSFUL_RESULT+host+webui 41 | end 42 | 43 | def test_failing_publishing 44 | test_url = 'http://username:password@confluence.domain/'+Asciidoctor::Confluence::ConfluenceAPI::API_CONTENT 45 | host = 'http://confluence.domain/' 46 | error_message = 'The page already exists' 47 | response_body = JSON.generate ( { 48 | 'message' => error_message 49 | }) 50 | stub_request(:post, test_url).to_return(:status => 400, :body => response_body) 51 | auth = {:username => 'username', :password => 'password'} 52 | options = {:confluence => {:auth => auth, :host => host, :title => 'Asciidoctor Page'}, :input_files => ['test.adoc']} 53 | publisher = Asciidoctor::Confluence::Publisher.new options 54 | publish_result = publisher.publish 55 | assert_equal 1, publish_result 56 | assert_true $stderr.string.include? error_message 57 | end 58 | end -------------------------------------------------------------------------------- /lib/asciidoctor/confluence.rb: -------------------------------------------------------------------------------- 1 | require_relative 'confluence/version' 2 | require_relative './page' 3 | require_relative './confluence_api' 4 | 5 | require 'asciidoctor' 6 | require 'faraday' 7 | require 'json' 8 | 9 | 10 | module Asciidoctor 11 | module Confluence 12 | 13 | class Publisher 14 | SUCCESSFUL_CREATE_RESULT = 'The page has been successfully created. It is available here: ' 15 | SUCCESSFUL_UPDATE_RESULT = 'The page has been successfully updated. It is available here: ' 16 | 17 | def initialize(options) 18 | @confluence_options = options[:confluence] 19 | @asciidoctor_options = options 20 | @asciidoctor_options[:to_file] = false 21 | @asciidoctor_options[:header_footer] = false 22 | 23 | if (options[:input_files].is_a? ::Array) && (options[:input_files].length == 1) 24 | @input_file = options[:input_files][0] 25 | else 26 | @input_file = options[:input_files] 27 | end 28 | end 29 | 30 | def publish 31 | document = Asciidoctor.convert_file @input_file, @asciidoctor_options 32 | page = Page.new @confluence_options[:space_key], @confluence_options[:title], document, @confluence_options[:page_id] 33 | api = ConfluenceAPI.new @confluence_options, page 34 | 35 | begin 36 | response = api.create_or_update_page @confluence_options[:update], @confluence_options[:page_id] 37 | 38 | response_body = JSON.parse response.body 39 | if response.success? 40 | url = response_body['_links']['base']+response_body['_links']['webui'] 41 | 42 | if @confluence_options[:update] 43 | $stdout.puts SUCCESSFUL_UPDATE_RESULT + url 44 | else 45 | $stdout.puts SUCCESSFUL_CREATE_RESULT + url 46 | end 47 | return 0 48 | else 49 | action = get_action_string 50 | show_error action, response_body['message'] 51 | return 1 52 | end 53 | rescue Exception => e 54 | show_error get_action_string, e.message 55 | end 56 | return 0 57 | end 58 | 59 | def get_action_string 60 | @confluence_options[:update] ? action = 'updated' : action = 'created' 61 | action 62 | end 63 | 64 | def show_error(action, message) 65 | $stderr.puts "An error occurred, the page has not been #{action} because:\n#{message}" 66 | end 67 | end 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /test/Asciidoctor/confluence/options_tests.rb: -------------------------------------------------------------------------------- 1 | require 'test/unit' 2 | require 'asciidoctor/confluence/options' 3 | 4 | class OptionsTests < Test::Unit::TestCase 5 | def setup 6 | @orig_stderr = $stderr 7 | $stderr = StringIO.new 8 | end 9 | 10 | def teardown 11 | $stderr = @orig_stderr 12 | @orig_stderr = nil 13 | end 14 | 15 | def test_init_options 16 | options = Asciidoctor::Confluence::Options.new 17 | host = 'http://hostname' 18 | space_key = 'key' 19 | title = 'title' 20 | username = 'username' 21 | password = 'pass' 22 | file_name = 'file.adoc' 23 | base_options = options.init_options ['--host', host, '--spaceKey', space_key, '--title', title, '--username', username, '--password', password, file_name] 24 | 25 | assert_equal 1, base_options.size 26 | assert_equal file_name, base_options[0] 27 | assert_equal host, options[:confluence][:host] 28 | assert_equal space_key, options[:confluence][:space_key] 29 | assert_equal title, options[:confluence][:title] 30 | assert_equal username, options[:confluence][:auth][:username] 31 | assert_equal password, options[:confluence][:auth][:password] 32 | end 33 | 34 | def test_with_full_options 35 | args = {:confluence => {:host => 'http://hostname/', :space_key => 'TEST_KEY', :title =>'Test title'}} 36 | options = Asciidoctor::Confluence::Options.new args 37 | res = options.check_mandatory_options 38 | assert_equal 1, res 39 | assert_true $stderr.string.nil_or_empty? 40 | 41 | end 42 | 43 | def test_host_not_present 44 | options = Asciidoctor::Confluence::Options.new 45 | res = options.check_mandatory_options 46 | assert_equal 0, res 47 | assert_true($stderr.string.include? Asciidoctor::Confluence::Options::HOST_MISSING) 48 | end 49 | 50 | def test_space_key_not_present 51 | args = {:confluence => {:host => 'http://hostname/'}} 52 | options = Asciidoctor::Confluence::Options.new args 53 | res = options.check_mandatory_options 54 | assert_equal 0, res 55 | assert_true($stderr.string.include? Asciidoctor::Confluence::Options::SPACE_KEY_MISSING) 56 | end 57 | 58 | def test_title_not_present 59 | args = {:confluence => {:host => 'http://hostname/', :space_key => 'TEST_KEY'}} 60 | options = Asciidoctor::Confluence::Options.new args 61 | res = options.check_mandatory_options 62 | assert_equal 0, res 63 | assert_true($stderr.string.include? Asciidoctor::Confluence::Options::TITLE_MISSING) 64 | end 65 | end -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | :version: 0.0.2 2 | :asciidoctor-base-version: 1.5.2 3 | :confluence-version: 5.x 4 | 5 | = Asciidoctor-Confluence {version} 6 | 7 | Asciidoctor-confluence is a ruby gem that takes Asciidoc files, parse them using https://github.com/asciidoctor/asciidoctor[Asciidoctor] and push the result into https://www.atlassian.com/software/confluence[Confluence]. 8 | This gem currently supports Asciidoctor {asciidoctor-base-version} + 9 | This gem is compatible with Confluence {confluence-version} 10 | 11 | == How to use it ? 12 | 13 | First you need to download and install the gem 14 | 15 | [source, ruby] 16 | ---- 17 | gem install asciidoctor-confluence 18 | ---- 19 | 20 | Then to create a page 21 | 22 | [source] 23 | ---- 24 | asciidoctor-confluence --host HOSTNAME --spaceKey SPACEKEY --title TITLE --username USERNAME --password PASSWORD file.adoc 25 | ---- 26 | 27 | To update a page 28 | [source] 29 | ---- 30 | asciidoctor-confluence --host HOSTNAME --spaceKey SPACEKEY --title TITLE --username USERNAME --password PASSWORD --update file.adoc 31 | #or 32 | asciidoctor-confluence --host HOSTNAME --spaceKey SPACEKEY --title TITLE --username USERNAME --password PASSWORD --update --pageid PAGEID file.adoc 33 | ---- 34 | 35 | Here is the list of arguments that can used with this gem 36 | 37 | .Gem parameters 38 | |=== 39 | |Argument | Is mandatory | Role | Example 40 | 41 | |host 42 | |yes 43 | |The hostname of the Confluence instance 44 | |http://confluence.mydomain/ 45 | 46 | |spaceKey 47 | |yes 48 | |The space wihtin the page will be created 49 | |'AS' in http://confluence.mydomain/display/AS/ 50 | 51 | |title 52 | |yes 53 | |The title of the Confluence page 54 | | 55 | 56 | |username 57 | |no 58 | |The username to use if the page has write restrictions 59 | | 60 | 61 | |password 62 | |no 63 | |The password associated to the account used to login into Confluence 64 | | 65 | 66 | |update 67 | |false 68 | |Indicate that the page must be updated instead of created. No values are required for this option 69 | | 70 | 71 | |pageid 72 | |no 73 | |The ID of the page you want to update, if it's not provided it will be determined using the space key and the title 74 | | 75 | |=== 76 | 77 | 78 | == Want to try it ? 79 | 80 | If you want to try asciidoctor-confluence you can either download the gem: 81 | [source] 82 | gem install asciidoctor-confluence 83 | 84 | Or install from the source 85 | 86 | . Install the gem locally (at the moment it has not been publish to rubygem) 87 | .. Clone the github repository locally `git clone https://github.com/gscheibel/asciidoctor-confluence.git` 88 | .. Built it `gem build asciidoctor-confluence.gemspec` 89 | .. Install it `gem install ./asciidoctor-confluence.{version}.gem` 90 | .. To check it has been done correctly `asciidoctor-confluence -v` should display `asciidoctor-confluence: {version}` 91 | . Have a Confluence instance 92 | .. If you don't have a Confluence server, you can use a Docker container (e.i.: https://registry.hub.docker.com/u/cptactionhank/atlassian-confluence/), the option requires therefore an Atlassian account so it can generate a trial licence key. -------------------------------------------------------------------------------- /lib/asciidoctor/confluence_api.rb: -------------------------------------------------------------------------------- 1 | module Asciidoctor 2 | module Confluence 3 | class ConfluenceAPI 4 | 5 | DEFAULT_CONTENT_TYPE = 'application/json' 6 | API_CONTENT = 'rest/api/content' 7 | 8 | attr_reader :url 9 | @page 10 | @auth 11 | 12 | def initialize(confluence_options, page) 13 | @url = build_api_content_url(confluence_options) 14 | @auth = confluence_options[:auth] unless confluence_options[:auth].nil? 15 | @page = page 16 | end 17 | 18 | def build_api_content_url(confluence_options) 19 | host = confluence_options[:host] 20 | host = host + '/' unless confluence_options[:host].end_with?('/') 21 | host+ API_CONTENT 22 | end 23 | 24 | def create_connection 25 | conn = Faraday.new do |faraday| 26 | faraday.request :url_encoded 27 | faraday.adapter Faraday.default_adapter 28 | end 29 | 30 | conn.basic_auth(@auth[:username], @auth[:password]) unless @auth.nil? 31 | conn 32 | end 33 | 34 | def create_or_update_page(update=false, page_id=nil) 35 | if update 36 | if page_id.nil? 37 | confluence_page = find_page_by_title_and_space(@page.space_key, @page.title) 38 | response_body = JSON.parse confluence_page.body 39 | results = response_body['results'] 40 | 41 | length = results.length 42 | 43 | if length == 1 44 | page_id = results[0]['id'] 45 | current_revision = results[0]['version']['number'] 46 | else 47 | plural = length > 0 ? 's' : '' 48 | raise Exception, "Error: #{length} page#{plural} entitled '#{@page.title}' found in the space '#{@page.space_key}'" 49 | end 50 | else 51 | confluence_page = find_page page_id 52 | response_body = JSON.parse confluence_page.body 53 | current_revision = response_body['version']['number'] 54 | end 55 | 56 | update_page page_id, current_revision 57 | else 58 | create_page 59 | end 60 | end 61 | 62 | def create_page 63 | conn = create_connection 64 | conn.post do |req| 65 | req.url @url 66 | req.headers['Content-Type'] = DEFAULT_CONTENT_TYPE 67 | req.body = @page.to_json 68 | end 69 | end 70 | 71 | def update_page(page_id, current_revision) 72 | @page.revision = current_revision.to_i+1 73 | 74 | conn = create_connection 75 | conn.put do |req| 76 | req.url "#{@url}/#{page_id}" 77 | req.headers['Content-Type'] = DEFAULT_CONTENT_TYPE 78 | req.body = @page.to_json 79 | end 80 | end 81 | 82 | def find_page_by_title_and_space(space_key, title) 83 | conn = create_connection 84 | conn.get do |req| 85 | req.url "#{@url}/?spaceKey=#{space_key}&title=#{title}&expand=version" 86 | req.headers['Content-Type'] = DEFAULT_CONTENT_TYPE 87 | end 88 | end 89 | 90 | def find_page(page_id) 91 | conn = create_connection 92 | conn.get do |req| 93 | req.url "#{@url}/#{page_id}" 94 | req.headers['Content-Type'] = DEFAULT_CONTENT_TYPE 95 | end 96 | end 97 | end 98 | end 99 | end -------------------------------------------------------------------------------- /lib/asciidoctor/confluence/options.rb: -------------------------------------------------------------------------------- 1 | require 'asciidoctor/cli/options' 2 | require_relative '../confluence' 3 | 4 | module Asciidoctor 5 | module Confluence 6 | 7 | class Options < Asciidoctor::Cli::Options 8 | 9 | HOST_MISSING = 'FAILED: The hostname of the Confluence instance is missing' 10 | SPACE_KEY_MISSING = 'FAILED: The spaceKey of the Confluence instance is missing' 11 | TITLE_MISSING = 'FAILED: The title of the Confluence page is missing' 12 | 13 | def initialize(options = {}) 14 | super options 15 | self[:confluence] = options[:confluence] || {:update => false} 16 | self[:confluence][:auth] = {} if self[:confluence][:auth].nil? 17 | end 18 | 19 | def parse!(args) 20 | init_options args 21 | unless args.empty? 22 | base_options = super args 23 | if (base_options.is_a? ::Integer) && base_options == -1 24 | $stderr.puts 'There are some issue with the asciidoctor command' 25 | end 26 | end 27 | 28 | self 29 | end 30 | 31 | def init_options(args) 32 | opts_parser = ::OptionParser.new do |opts| 33 | opts.banner = <<-EOS 34 | Usage: asciidoctor-confluence --host HOSTNAME --spaceKey SPACEKEY --title TITLE [ASCIIDOCTOR OPTIONS]... FILE... 35 | EOS 36 | 37 | opts.on('--host HOST', 'the hostname of the Confluence instance ') do |host| 38 | self[:confluence][:host] = host 39 | end 40 | 41 | opts.on('--spaceKey SPACEKEY', 'the Confluence space within the page will be created') do |spaceKey| 42 | self[:confluence][:space_key] = spaceKey 43 | end 44 | 45 | opts.on('--title TITLE', 'the title of the Confluence page') do |title| 46 | self[:confluence][:title] = title 47 | end 48 | 49 | opts.on('--pageid PAGEID', 'the id of the page to update') do |page_id| 50 | self[:confluence][:page_id] = page_id 51 | end 52 | 53 | opts.on('--update', 'indicate that the page must be updated instead of created') do 54 | self[:confluence][:update] = true 55 | end 56 | 57 | opts.on('--username USERNAME', 'the username used if credential are need to create the page') do |spaceKey| 58 | self[:confluence][:auth][:username] = spaceKey 59 | end 60 | 61 | opts.on('--password PASSWORD', 'the password used if credential are need to create the page') do |spaceKey| 62 | self[:confluence][:auth][:password] = spaceKey 63 | end 64 | 65 | opts.on_tail('-h', '--help', 'Show the full helper (including Asciidoctor helper)') do 66 | $stdout.puts opts, "\n\n" 67 | return Asciidoctor::Cli::Options.parse! ['-h'] 68 | end 69 | 70 | opts.on_tail('-V', '--version', 'display the version and runtime environment (or -v if no other flags or arguments)') do 71 | $stdout.puts "Asciidoctor-confluence v#{Asciidoctor::Confluence::VERSION}\n" 72 | return Asciidoctor::Cli::Options.parse! ['-V'] 73 | end 74 | 75 | end 76 | 77 | opts_parser.parse! args 78 | check_mandatory_options 79 | end 80 | 81 | 82 | def check_mandatory_options 83 | raise HOST_MISSING if self[:confluence][:host].nil? 84 | raise SPACE_KEY_MISSING if self[:confluence][:space_key].nil? 85 | raise TITLE_MISSING if self[:confluence][:title].nil? 86 | end 87 | 88 | def self.parse! (*args) 89 | Options.new.parse! args.flatten 90 | end 91 | end 92 | end 93 | end --------------------------------------------------------------------------------