I want to execute Ruby code if command line argument is present:
ruby sanity_checks.rb --trx-request -e staging_psp -g all
Ruby code:
def execute
    command_options = CommandOptionsProcessor.parse_command_options
    request_type    = command_options[:env]
    tested_env      = command_options[:trx-request]   // check here if flag is present
    tested_gateways = gateway_names(env: tested_env, gateway_list: command_options[:gateways])
    error_logs      = []
   if(request_type.nil?)
    tested_gateways.each do |gateway|
      ........
    end
   end
    raise error_logs.join("\n") if error_logs.any?
  end
How I can get the argument --trx-request and check is it present?
EDIT:
Command parser:
class CommandOptionsProcessor
  def self.parse_command_options
    command_options = {}
    opt_parser = OptionParser.new do |opt|
      opt.banner = 'Usage: ruby sanity_checks.rb [OPTIONS]'
      opt.separator  "Options:"
      opt.on('-e TEST_ENV', '--env TEST_ENV','Set tested environment (underscored).') do |setting|
        command_options[:env] = setting
      end
      opt.on('-g X,Y,Z', '--gateways X,Y,Z', Array, 'Set tested gateways (comma separated, no spaces).') do |setting|
        command_options[:gateways] = setting
      end
    end
    opt_parser.parse!(ARGV)
    command_options
  end
end
Can you advice?
 
    