exe/aip2aixm in aipp-0.1.3 vs exe/aip2aixm in aipp-0.2.0
- old
+ new
@@ -1,60 +1,11 @@
#!/usr/bin/env ruby
require 'bundler/inline'
-require 'optparse'
-require 'yaml'
gemfile do
source 'https://rubygems.org'
ruby '>= 2.5'
gem 'aipp', '~> 0'
end
-class Executable
- attr_reader :fir, :aip, :airac, :ofm, :limit, :verbose
-
- def initialize
- @ogn = false
- @airac = AIPP::AIRAC.new(Date.today).date
- @limit = Float::INFINITY
- @verbose = false
- OptionParser.new do |o|
- o.banner = <<~END
- Download online AIP and convert it to AIXM for VFR.
- Usage: #{File.basename($0)} [options]
- END
- o.on('-A', '--about', 'author and license information') { puts 'Written by Sven Schwyn (bitcetera.com) and distributed under MIT license.'; exit }
- o.on('-l', '--list', "list available FIR/AIP and exit") { puts AIPP::Loader.list.to_yaml; exit }
- o.on('-f', '--fir STRING', String, 'FIR (flight information region, e.g. "LF")') { |v| @fir = v }
- o.on('-a', '--aip STRING', String, 'AIP (aeronautical information publication, e.g. "ENR-5.1")') { |v| @aip = v }
- o.on('-d', '--airac DATE', String, 'AIRAC date (e.g. "2018-01-04", default: current)') { |v| @airac = v }
- o.on('-o', '--[no-]ofm', 'Use OFM extensions (default: false)') { |v| @ofm = v }
- o.on('-L', '--limit INTEGER', Integer, 'Stop conversion after this many features') { |v| @limit = v }
- o.on('-D', '--[no-]debug', 'Enable debug mode (default: false)') { |v| $DEBUG = v }
- o.on('-v', '--[no-]verbose', 'Verbose error reporting (default: false)') { |v| @verbose = v }
- end.parse!
- fail(ArgumentError, "FIR must be supplied") unless @fir
- fail(ArgumentError, "AIP must be supplied") unless @aip
- fail(ArgumentError, "AIRAC date must be supplied") unless @airac
- end
-
- def run
- extensions = [(:ofm if ofm)].compact
- filename = [fir, aip, airac].join('_') + '.aixm'
- loader = AIPP::Loader.new(fir: fir, aip: aip, airac: airac, limit: limit)
- File.write(Pathname.new(Dir.pwd).join(filename), loader.aixm.to_aixm(*extensions))
- puts "#{loader.aixm.features.count} feature(s) written to #{filename}"
- end
-end
-
-begin
- executable = Executable.new
- executable.run
-rescue => exception
- if executable&.verbose
- raise exception
- else
- puts "#{File.basename($0)}: #{exception.message}"
- exit 1
- end
-end
+AIPP::Executable.new(schema: File.basename($0)[4..-1].to_sym).run