module SyncReadme

Constants

VERSION

Public Class Methods

invoke(args) click to toggle source
# File lib/sync_readme.rb, line 13
def self.invoke(args)
  options = {}
  OptionParser.new do |opts|
    opts.banner = 'Usage: sync_readme [options] [profile]'

    opts.on('-u', '--user=username', String, 'Confluence username') do |user|
      ENV['CONFLUENCE_USERNAME'] = user
      ENV['CONFLUENCE_PASSWORD'] = ask("Password for #{user}: ") { |q| q.echo = false }
    end

    opts.on('-a', '--all', 'Run all configured syncronizations') do
      options[:all] = true
    end

    opts.on_tail('-h', '--help', 'Show help') do
      puts opts
      exit
    end
  end.parse!(args)

  ENV['CONFLUENCE_USERNAME'] ||= ask("Confluence username: ")
  ENV['CONFLUENCE_PASSWORD'] ||= ask("Password for #{ENV['CONFLUENCE_USERNAME']}: ") { |q| q.echo = false }

  default_profile = SyncReadme::Config.default

  if options[:all] || (args.empty? && default_profile.nil?)
    SyncReadme::Config.profiles.each do |profile|
      SyncReadme.perform(profile)
    end
  elsif args.empty?
    SyncReadme.perform(default_profile)
  else
    SyncReadme.perform(args.last)
  end

rescue SyncReadme::Error => sre
  STDERR.puts sre.message
  exit 1
end
perform(profile) click to toggle source
# File lib/sync_readme.rb, line 53
def self.perform(profile)
  config = SyncReadme::Config.new(profile)
  content = SyncReadme::Reader.new(config).html
  sync = SyncReadme::ConfluenceSync.new(config)
  sync.update_page_content(content)
end