Created
March 16, 2012 05:36
-
-
Save vranystepan/2048689 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'optparse' | |
options = {} | |
optparse = OptionParser.new do|opts| | |
opts.banner = "Usage: ruby #{File.basename(__FILE__)} -t <target ip address> -i <input file name> [-o <output file name>]" | |
opts.on( '-t', '--target HOST', 'Target\'s IP address' ) do|h| | |
options[:host] = h | |
end | |
opts.on('-i', '--input FILE', 'Input file name') do |f| | |
options[:input] = f | |
end | |
opts.on('-o', '--output FILE', 'Input file name') do |f| | |
options[:output] = f | |
end | |
end | |
begin | |
optparse.parse! | |
mandatory = [:host, :input] | |
missing = mandatory.select{ |param| options[param].nil? } | |
if not missing.empty? | |
puts "Missing options: #{missing.join(', ')}" | |
puts optparse | |
exit | |
end | |
rescue OptionParser::InvalidOption, OptionParser::MissingArgument | |
puts $!.to_s | |
puts optparse | |
exit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment