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,
lib/terrimporter/configuration_loader.rb

Defined Under Namespace

Classes: Configuration, ConfigurationLoader, Downloader, Importer, Options

Class Method Summary collapse

Methods included from ConfigurationHelper

backup_config_file, base_config_path, config_default_name, config_example_path, config_search_paths, config_working_directory_exists?, config_working_directory_path, create_config_file, remove_config_file, schema_default_name, schema_file_path

Class Method Details

.build_options(arguments) ⇒ Object



93
94
95
96
97
98
# File 'lib/terrimporter.rb', line 93

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

todo refactor into smaller methods



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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/terrimporter.rb', line 35

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
      case options[:init]
        when :backup
          backup_config_file
        when :replace
          remove_config_file
      end
      create_config_file(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
    STAT.print_summary
    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