Class: AIPP::Executable Abstract

Inherits:
Object
  • Object
show all
Includes:
Debugger
Defined in:
lib/aipp/executable.rb

Overview

This class is abstract.

Instance Method Summary collapse

Methods included from Debugger

#info, #original_warn, #verbose_info, #warn, #with_debugger

Constructor Details

#initialize(exe_file) ⇒ Executable

Returns a new instance of Executable.



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
46
47
48
49
# File 'lib/aipp/executable.rb', line 7

def initialize(exe_file)
  @exe_file = exe_file
  help if ARGV.none? || ARGV.first == '--help'
  require_scope
  AIPP.options.replace(
    scope: scope,
    schema: schema,
    storage: Pathname(Dir.home).join('.aipp'),
    check_links: false,
    clean: false,
    force: false,
    mid: false,
    write_empty: false,
    quiet: false,
    verbose: false,
    debug_on_warning: false,
    debug_on_error: false
  )
  options if respond_to? :options
  OptionParser.new do |o|
    o.on('-r', '--region STRING', String, 'region (e.g. "LF")') { AIPP.options.region = _1.upcase }
    o.on('-s', '--section STRING', String, 'process this section only') { AIPP.options.section = _1.classify }
    o.on('-d', '--storage DIR', String, 'storage directory (default: "~/.aipp")') { AIPP.options.storage = Pathname(_1) }
    o.on('-o', '--output FILE', String, 'output file') { AIPP.options.output_file = _1 }
    option_parser(o)
    if schema == :ofmx
      o.on('-m', '--[no-]mid', 'insert mid attributes into all Uid elements (default: false)') { AIPP.options.mid = _1 }
      o.on('-0', '--[no-]empty', 'write empty OFMX files in case of no upstream data (default: false)') { AIPP.options.write_empty = _1 }
    end
    o.on('-h', '--[no-]check-links', 'check all links with HEAD requests (default: false)') { AIPP.options.check_links = _1 }
    o.on('-c', '--[no-]clean', 'clean cache and download from sources anew (default: false)') { AIPP.options.clean = _1 }
    o.on('-f', '--[no-]force', 'continue on non-fatal errors (default: false)') { AIPP.options.force = _1 }
    o.on('-q', '--[no-]quiet', 'suppress all informational output (default: false)') { AIPP.options.quiet = _1 }
    o.on('-v', '--[no-]verbose', 'verbose output including unsevere warnings (default: false)') { AIPP.options.verbose = _1 }
    o.on('-w', '--debug-on-warning [ID]', Integer, 'open debug session on warning with ID (default: false)') { AIPP.options.debug_on_warning = _1 || true }
    o.on('-e', '--[no-]debug-on-error', 'open debug session on error (default: false)') { AIPP.options.debug_on_error = _1 }
    o.on('-A', '--about', 'show author/license information and exit') { about }
    o.on('-R', '--readme', 'show README and exit') { readme }
    o.on('-L', '--list', 'list implemented regions') { list }
    o.on('-V', '--version', 'show version and exit') { version }
  end.parse!
  guard if respond_to? :guard
end

Instance Method Details

#runObject



51
52
53
54
55
56
57
58
59
# File 'lib/aipp/executable.rb', line 51

def run
  with_debugger do
    String.disable_colorization = !STDOUT.tty?
    starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    [:AIPP, AIPP.options.scope, :Runner].constantize.new.run
    ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    info("finished after %s" % Time.at(ending - starting).utc.strftime("%H:%M:%S"))
  end
end