Class: TerrImporter::Application

Inherits:
Object
  • Object
show all
Extended by:
ConfigurationHelper, Shellwords
Defined in:
lib/terrimporter.rb,
lib/terrimporter/options.rb,
lib/terrimporter/importer.rb,
lib/terrimporter/downloader.rb,
lib/terrimporter/configuration.rb

Defined Under Namespace

Classes: Configuration, Downloader, Importer, Options

Class Method Summary collapse

Methods included from ConfigurationHelper

config_default_name, config_example_path, config_working_directory_exists?, config_working_directory_path, create_config_file, schema_default_name, schema_file_path

Class Method Details

.build_options(arguments) ⇒ Object



77
78
79
80
81
82
# File 'lib/terrimporter.rb', line 77

def build_options(arguments)
  env_opts_string = ENV['TERRIMPORTER_OPTS'] || ""
  env_opts = TerrImporter::Application::Options.new(shellwords(env_opts_string))
  argument_opts = TerrImporter::Application::Options.new(arguments)
  env_opts.merge(argument_opts)
end

.run!(*arguments) ⇒ Object



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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/terrimporter.rb', line 25

def run!(*arguments)
  options = build_options(arguments)

  begin
    if !options[:init].nil?
      if config_working_directory_exists? and options[:init] != :backup and options[:init] != :replace
        raise TerrImporter::ConfigurationError, "Configuration already exists, use the override or backup option"
      end
      create_config_file(options[:init], options[:application_url])
      return 0
    end

    case options[:verbose]
      when true
        LOG.level = :debug
      when false
        LOG.level = :info
    end


    if options[:invalid_argument]
      $stderr.puts options[:invalid_argument]
      options[:show_help] = true
    end

    if options[:invalid_option]
      $stderr.puts options[:invalid_option]
      options[:show_help] = true
    end

    if options[:show_help]
      $stderr.puts options.opts
      return 1
    end

    if options[:show_version]
      puts TerrImporter::VERSION
      return 0
    end

    importer = TerrImporter::Application::Importer.new(options)
    importer.run
    return 0
  rescue TerrImporter::ConfigurationError
    $stderr.puts %Q{Configuration Error #{ $!.message }}
    return 1
  rescue TerrImporter::DefaultError
    $stderr.puts %Q{Unspecified Error #{ $!.message }}
    return 1
  end
end