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
- #header ⇒ Object
-
#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
#header ⇒ Object
53 54 55 56 57 |
# File 'lib/autoexpreso/cli.rb', line 53 def header stars = "*" * 50 details = "\t Enter your account details\n\n" puts stars, "\t\t AutoExpreso", stars, "\n", details end |
#login ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/autoexpreso/cli.rb', line 59 def login header username = ask('Username: ') password = ask('Password: ') { |q| q.echo = '*' } ae = AutoExpreso::Client.new ae.login(username, password) puts "Account Details:" @json ? ae.account_details(json: true) : ae.account_details end |
#parse ⇒ String
Parses the command-line arguments and runs the executable
46 47 48 49 50 51 |
# File 'lib/autoexpreso/cli.rb', line 46 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 39 40 41 42 |
# 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_head('-j', '--json', 'Return account details as json') do @json = 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 |