PageRenderTime 102ms CodeModel.GetById 40ms app.highlight 1ms RepoModel.GetById 59ms app.codeStats 1ms

/ruby-mode/Files/option_parse { .. } (optp).yasnippet

http://github.com/ridgetang/snippets
Unknown | 32 lines | 25 code | 7 blank | 0 comment | 0 complexity | cf0116eecc51cf79583b43976df58873 MD5 | raw file
 1# -*- mode: snippet -*-
 2# key: optp
 3# contributor: Translated from TextMate Snippet
 4# name: option_parse { .. }
 5# --
 6require "optparse"
 7
 8options = {${1::default => "args"}}
 9
10ARGV.options do |opts|
11	opts.banner = "Usage:  #{File.basename(\$PROGRAM_NAME)} [OPTIONS]${2/^\s*$|(.*\S.*)/(?1: )/}${2:OTHER_ARGS}"
12	
13	opts.separator ""
14	opts.separator "Specific Options:"
15	
16	$0
17	
18	opts.separator "Common Options:"
19	
20	opts.on( "-h", "--help",
21	         "Show this message." ) do
22		puts opts
23		exit
24	end
25	
26	begin
27		opts.parse!
28	rescue
29		puts opts
30		exit
31	end
32end