Sha256: 488c4c387da75f37d96b61c305a3091c5bad2dc5ae62dc934e655864ef40fffe
Contents?: true
Size: 1.46 KB
Versions: 4
Compression:
Stored size: 1.46 KB
Contents
require 'optparse' require 'ostruct' module Imessage class Parser class << self def parse(options) OpenStruct.new.tap do |args| args.contacts = [] args.text = nil args.attachment = nil args.verbose = false opt_parser(args).parse!(options) end end private def opt_parser(args) OptionParser.new do |opts| opts.banner = "Usage: imessage [options]" opts.separator "" opts.separator "Specific options:" opts.on("-t", "--text [TEXT]", String, "The TEXT to deliver") do |text| args.text = text end opts.on("-a", "--attachment [ATTACHMENT]", String, "Add an attachment") do |attachment| if File.exists?(attachment) args.attachment = File.expand_path(attachment) else puts "Can not find file #{attachment}" exit(1) end end opts.on("-c", "--contacts x,y,z", Array, "Deliver message to these CONTACTS") do |contacts| args.contacts = contacts end opts.separator "" opts.separator "Common options:" opts.on("-h", "--help", "Prints this help") do puts opts exit end opts.on_tail("--version", "Show version") do puts "imessage v#{Imessage::VERSION}" exit end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
imessage-0.4.0 | lib/imessage/parser.rb |
imessage-0.3.2 | lib/imessage/parser.rb |
imessage-0.3.1 | lib/imessage/parser.rb |
imessage-0.3.0 | lib/imessage/parser.rb |