#!/usr/bin/env ruby require 'readline' require 'English' require 'slop' ENV['RACK_ENV'] ||= 'production' # display name for tools like `ps` $PROGRAM_NAME = 'genevalidatorapp' begin Slop.parse!(strict: true, help: true) do banner < e puts e exit! rescue GeneValidatorApp::NUM_THREADS_INCORRECT => e puts e unless num_threads? puts 'You can set the correct value by running:' puts puts ' genevalidatorapp -s -n ' puts end exit! rescue GeneValidatorApp::BIN_DIR_NOT_FOUND => e puts e unless bin? puts 'You can set the correct value by running:' puts puts ' genevalidatorapp -s -b ' puts end exit! rescue GeneValidatorApp::EXTENSION_FILE_NOT_FOUND => e puts e unless require? puts 'You can set the correct value by running:' puts puts ' genevalidatorapp -s -r ' puts end exit! rescue GeneValidatorApp::DATABASE_DIR_NOT_FOUND => e puts e unless database_dir? puts 'You can set the correct value by running:' puts puts ' genevalidatorapp -s -d ' puts end exit! rescue GeneValidatorApp::BLAST_NOT_INSTALLED, GeneValidatorApp::BLAST_NOT_EXECUTABLE, GeneValidatorApp::BLAST_NOT_COMPATIBLE => e # Show original error message first. puts puts e # Set a flag so that if we recovered from error resulting config can be # saved. Config will be saved unless invoked with -b option. fetch_option(:set).value = !bin? # Ask user if she already has BLAST+ downloaded. puts puts <> ').to_s.strip unless response.empty? unless File.basename(response) == 'bin' response = File.join(response, 'bin') end fetch_option(:bin).value = File.join(response) puts redo end rescue GeneValidatorApp::DATABASE_DIR_NOT_SET => e # Show original error message. puts puts e # Set a flag so that if we recovered from error resulting config can be # saved. Config will be saved unless invoked with -d option. fetch_option(:set).value = !database_dir? # Ask user for the directory containing sequences or BLAST+ # databases. puts puts <> ').to_s.strip fetch_option(:database_dir).value = response redo rescue GeneValidatorApp::NO_BLAST_DATABASE_FOUND, GeneValidatorApp::NO_PROTEIN_BLAST_DATABASE_FOUND => e unless list_databases? # Print error raised. puts puts e exit! end rescue GeneValidatorApp::BLAST_DATABASE_ERROR => e puts e exit! rescue => e # This will catch any unhandled error and some very special errors. # Ideally we will never hit this block. If we do, there's a bug in # GeneValidatorApp or something really weird going on. If we hit this # error block we show the stacktrace to the user requesting them to # post the same to our Google Group. puts < e puts e puts "Run '#{$PROGRAM_NAME} -h' for help with command line options." exit end