#!/usr/bin/env ruby # frozen_string_literal: true require 'optparse' require 'bundler/setup' require 'tac_scribe' options = { tacview_host: 'localhost', tacview_port: 42_674, tacview_password: nil, tacview_client_name: 'TacScribe', cinc_enabled: false, cinc_port: 9001, db_host: 'localhost', db_port: 5432, db_name: 'tac_scribe', verbose_logging: false, threads: 1, populate_airfields: false, whitelist: nil } OptionParser.new do |opts| opts.banner = 'Usage: ruby start_scribe [options]' opts.separator "\nTacview Options" opts.on('-h', '--tacview-host=host', 'Tacview server hostname / IP (Default: localhost)') do |v| options[:tacview_host] = v end opts.on('-p', '--tacview-port=port', 'Tacview server port (Default: 42674)') do |v| options[:tacview_port] = v end opts.on('-a', '--tacview-password=password', 'Tacview server password (Optional)') do |v| options[:tacview_password] = v end opts.on('-c', '--tacview-client-name=client', 'Client name (Default: TacScribe)') do |v| options[:tacview_client_name] = v end opts.separator "\nCommander-In-Chief Options" opts.on('-b', '--enable-cinc', 'Is Cinc enabled? (Default: false)') do |_v| options[:cinc_enabled] = true end opts.on('-m', '--cinc-port=port', 'Cinc server port (Default: 9001)') do |v| options[:cinc_port] = v end opts.separator "\nDatabase Options" opts.on('-o', '--db-host=host', 'Postgresql server hostname / IP (Default: localhost)') do |v| options[:db_host] = v end opts.on('-r', '--db-port=port', 'Postgresql server port (Default: 5432)') do |v| options[:db_port] = v end opts.on('-u', '--db-user=username', 'Postgresql username (Required)') do |v| options[:db_user] = v end opts.on('-s', '--db-password=password', 'Postgresql password (Required)') do |v| options[:db_password] = v end opts.on('-n', '--db-name=name', 'Postgresql database name (Default: tac_scribe)') do |v| options[:db_name] = v end opts.separator "\nMisc options" opts.on('-f', '--populate-airfields', 'Populate DCS airfield locations') do |_v| options[:populate_airfields] = true end opts.on('-t', '--threads=threads', 'Thread Count (Default: 1)') do |v| options[:threads] = v end opts.on('-v', '--verbose', 'Verbose logging') do |_v| options[:verbose] = true end opts.on('-w', '--whitelist=whitelist', 'Whitelist filename') do |v| options[:whitelist] = v end end.parse! %i[db_user db_password].each do |parameter| next unless !options[parameter] || !options[parameter].is_a?(String) || options[parameter].empty? puts "#{parameter.to_s.tr('_', '-')} required" exit(1) end if(options[:populate_airfields] && options[:cinc_enabled]) puts "You cannot populate airfields AND enable Cinc at the same time" exit(1) end TacScribe::Daemon.new( tacview_host: options[:tacview_host], tacview_port: options[:tacview_port], tacview_password: options[:tacview_password], tacview_client_name: options[:tacview_client_name], db_host: options[:db_host], db_port: options[:db_port], db_name: options[:db_name], db_user: options[:db_user], db_password: options[:db_password], verbose_logging: options[:verbose], thread_count: options[:threads].to_i, populate_airfields: options[:populate_airfields], whitelist: options[:whitelist], cinc_enabled: options[:cinc_enabled], cinc_port: options[:cinc_port] ).start_processing