Class: TimeCop::OptionParser
- Inherits:
-
Object
- Object
- TimeCop::OptionParser
- Defined in:
- lib/time_cop/option_parser.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Instance Method Summary collapse
-
#initialize(args) ⇒ OptionParser
constructor
A new instance of OptionParser.
- #parse ⇒ Object
Constructor Details
#initialize(args) ⇒ OptionParser
Returns a new instance of OptionParser.
7 8 9 |
# File 'lib/time_cop/option_parser.rb', line 7 def initialize(args) @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
5 6 7 |
# File 'lib/time_cop/option_parser.rb', line 5 def args @args end |
Instance Method Details
#parse ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/time_cop/option_parser.rb', line 11 def parse = {} option_parser = ::OptionParser.new do |opts| opts.on("-u USERNAME", "--username=USERNAME", "Username to authenticate as") do |username| [:username] = username end opts.on("-p PASSWORD", "--password=PASSWORD", "Passsword to authenticate with") do |password| [:password] = password end opts.on("-e EMAIL", "--email=EMAIL", "Email of user to get report for") do |email| [:email] = email end opts.on('-i', '--interactive', 'Runs in interactive mode') do [:interactive] = true end opts.on("-h", "--help", "Prints help") do puts opts exit end end option_parser.parse(args) unless (([:username] && [:password]) || [:interactive]) puts "Please specify a username and password or run in interactive mode" puts option_parser exit end end |