PageRenderTime 32ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/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. # --
  6. require "optparse"
  7. options = {${1::default => "args"}}
  8. ARGV.options do |opts|
  9. opts.banner = "Usage: #{File.basename(\$PROGRAM_NAME)} [OPTIONS]${2/^\s*$|(.*\S.*)/(?1: )/}${2:OTHER_ARGS}"
  10. opts.separator ""
  11. opts.separator "Specific Options:"
  12. $0
  13. opts.separator "Common Options:"
  14. opts.on( "-h", "--help",
  15. "Show this message." ) do
  16. puts opts
  17. exit
  18. end
  19. begin
  20. opts.parse!
  21. rescue
  22. puts opts
  23. exit
  24. end
  25. end