Class: TerrImporter::Application::Options

Inherits:
Hash
  • Object
show all
Defined in:
lib/terrimporter/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Options

Returns a new instance of Options.



6
7
8
9
10
11
12
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
# File 'lib/terrimporter/options.rb', line 6

def initialize(args)
  super()
  @orig_args = args.clone
  self[:verbose] = false
  self[:show_help] = false

  require 'optparse'
  @opts = OptionParser.new do |o|
    o.banner = "Usage: #{File.basename($0)} [options] \n" +
    "Use #{File.basename($0)} [application_url] --init to initialize importer before first usage."
    o.separator ''
    o.separator 'Common options:'
    o.on('-a', '--all', 'import everything configured; javascripts, css files and images') do
      self[:import_css] = true
      self[:import_js] = true
      self[:import_images] = true
      self[:import_modules] = true
    end
    o.on('-c', '--css', 'import configured css files') { self[:import_css] = true }
    o.on('-i', '--img', 'import configured image files') { self[:import_images] = true }
    o.on('-j', '--js', 'import configured javascript files') { self[:import_js] = true }
    o.on('-m', '--module', 'import configured module files') { self[:import_modules] = true }
    o.on('--init [CONFIG_EXISTS]', [:backup, :replace], 'create configuration file in current working directory. use optional argument to force file replacement (backup, replace)') { |init| self[:init] = init || true }
    o.on('-f', '--config CONFIG_FILE', 'use alternative configuration file') { |config_file| self[:config_file] = config_file }
    o.separator ''
    o.separator 'Additional configuration:'
    o.on('-v', '--[no-]verbose', 'run verbosely') { |v| self[:verbose] = v }
    o.on('--version', 'Show version') { self[:show_version] = true }
    o.on_tail('-h', '--help', 'display this help and exit') { self[:show_help] = true }
  end

  begin
    @opts.parse!(args)
    self[:application_url] = args.shift
  rescue OptionParser::InvalidOption => e
    self[:invalid_option] = e.message
  rescue OptionParser::InvalidArgument => e
    self[:invalid_argument] = e.message
  end
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



4
5
6
# File 'lib/terrimporter/options.rb', line 4

def opts
  @opts
end

#orig_argsObject (readonly)

Returns the value of attribute orig_args.



4
5
6
# File 'lib/terrimporter/options.rb', line 4

def orig_args
  @orig_args
end

Instance Method Details

#merge(other) ⇒ Object



47
48
49
# File 'lib/terrimporter/options.rb', line 47

def merge(other)
  self.class.new(@orig_args + other.orig_args)
end