Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created April 14, 2016 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/b9a917465644d8e18d043f5500f1329b to your computer and use it in GitHub Desktop.
Save anonymous/b9a917465644d8e18d043f5500f1329b to your computer and use it in GitHub Desktop.
def checkFlagValue(flag,value)
# Remove the = symbol, which OptionParser leaves there if you use the shortflag (-p)
value=value.gsub('=','')
if value.empty?
usage("Missing value for --#{flag}")
end
return value
end
# If we have the correct number of arguments let's make sure we have the required options.
Arguments = OptionParser.new do |opt|
opt.on('--profile PROFILE',"The AWS profile to connect to.") do |o|
profile=checkFlagValue('profile',o)
end
opt.on('--region [REGION]','The AWS region to use.') do |o|
region=checkFlagValue('region',o)
end
opt.on('--retention-days [DAYS]','The number of days to hold the snapshots.') do |o|
retention_days=checkFlagValue('retention_days',o)
end
opt.on('--[no-]dry-run','Test rather than actually running.') do |o|
dry_run = true
end
opt.on('--instance instance','The instance id you want to snapshot') do |o|
instance = o
end
end.parse!
def usage(optional_message = nil)
unless optional_message.nil?
puts optional_message
end
puts Arguments.help
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment