Created
August 1, 2018 17:23
-
-
Save buren/0b43b553ad3f52382ace7f4f3b548688 to your computer and use it in GitHub Desktop.
Atom snippet - Ruby optparse template
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
'.source.ruby': | |
'Insert Ruby optparser': | |
'prefix': 'optparse' | |
'body': | |
''' | |
require 'optparse' | |
options = {} | |
OptionParser.new do |parser| | |
parser.banner = 'Usage: ${1:script_name} --help' | |
parser.default_argv = ARGV | |
parser.on('--${2:arg0}=val0', String, '') do |string| | |
options[:${2:arg0}] = string | |
end | |
parser.on('--${3:arg1}=first,second', Array, '') do |array| | |
options[:${3:arg1}] = array | |
end | |
parser.on('--[no-]${4:arg2}', '') do |boolean| | |
options[:${4:arg2}] = boolean | |
end | |
parser.on('-h', '--help', 'How to use') do | |
puts parser | |
exit | |
end | |
end.parse! | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment