Module: SyncReadme

Defined in:
lib/sync_readme.rb,
lib/sync_readme/config.rb,
lib/sync_readme/errors.rb,
lib/sync_readme/reader.rb,
lib/sync_readme/version.rb,
lib/sync_readme/confluence_sync.rb

Defined Under Namespace

Classes: Config, ConfluenceSync, Error, NoConfigurationError, Reader

Constant Summary collapse

VERSION =
'1.1.0'.freeze

Class Method Summary collapse

Class Method Details

.invoke(args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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) ⇒ Object



53
54
55
56
57
58
# 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