Class: AutoExpreso::CLI
- Inherits:
-
Object
- Object
- AutoExpreso::CLI
- Defined in:
- lib/autoexpreso/cli.rb
Overview
A Simple class for the executable version of the gem
Instance Method Summary collapse
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
- #login ⇒ Object
-
#parse ⇒ String
Parses the command-line arguments and runs the executable.
-
#set_options(opts) ⇒ Object
Configures the arguments for the command.
Constructor Details
#initialize(args) ⇒ CLI
Returns a new instance of CLI.
9 10 11 |
# File 'lib/autoexpreso/cli.rb', line 9 def initialize(args) @args = args end |
Instance Method Details
#login ⇒ Object
49 50 51 52 53 |
# File 'lib/autoexpreso/cli.rb', line 49 def login username = ask('Username: ') password = ask('Password: ') { |q| q.echo = '*' } AutoExpreso::Client.new.login(username, password) end |
#parse ⇒ String
Parses the command-line arguments and runs the executable
42 43 44 45 46 47 |
# File 'lib/autoexpreso/cli.rb', line 42 def parse opts = OptionParser.new(&method(:set_options)) opts.parse!(@args) return login if @login puts opts.help end |
#set_options(opts) ⇒ Object
Configures the arguments for the command
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/autoexpreso/cli.rb', line 15 def (opts) opts.version = AutoExpreso::VERSION opts. = <<MSG Usage: autoexpreso [OPTION] Description: Autoexpreso, Scrapes autoexpreso.com for your account status. Options: MSG opts.set_program_name 'AutoExpreso' opts.on_head('-l', '--login', 'Log into AutoExpreso') do @login = true end opts.on_tail('-v', '--version', 'display the version of AutoExpreso and exit') do puts opts.version exit end opts.on_tail('-h', '--help', 'print this help') do puts opts.help exit end end |