Created
September 30, 2014 22:56
-
-
Save sumdog/db0d4060990197876cc5 to your computer and use it in GitHub Desktop.
Ruby syntax error parsing args
This file contains hidden or 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
options = {} | |
opts = OptionParser.new do |opts| | |
opts.banner = 'Usage: create_env [-f] [-e (build|run)] [-d (mysql|postgres|mssql)] <environment name>' | |
opts.on_tail("-h", "--help", "Show this message") do | |
puts STDERR.opts | |
exit | |
end | |
opts.on('-f','--fixtures','Install fixtures') do |f| | |
options[:fixtures] = f | |
end | |
opts.on('-e','--env ENVIRONMENT',[:build,:run],'Environment type (build|run) [default: run]') do |e| | |
options[:environment] = e | |
end | |
opts.on('-d','--database DATABASE',[:mysql,:postgres,:mssql],'Database backend (mysql|postgres|mssql)') do |db| | |
options[:database] = db | |
end | |
end | |
## Validation | |
begin opts.parse! ARGV | |
rescue *[OptionParser::InvalidOption,OptionParser::InvalidArgument] => e | |
STDERR.puts e | |
STDERR.puts opts | |
exit 1 | |
end | |
if ARGV.length == 0 | |
STDERR.puts 'You must specify an environment name'.red | |
exit 1 | |
elsif ARGV.length != 1 | |
STDERR.puts ('Unknown trailing arguments: %s' %[ARGV.drop(1)]).red | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment