class AutoExpreso::CLI

A Simple class for the executable version of the gem

Public Class Methods

new(args) click to toggle source

@param args [Array<String>] The command-line arguments

# File lib/autoexpreso/cli.rb, line 9
def initialize(args)
  @args = args
end

Public Instance Methods

header() click to toggle source
# 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() click to toggle source
# File lib/autoexpreso/cli.rb, line 59
def login
  header

  email = ask('Email:  ')
  password = ask('Password:  ') { |q| q.echo = '*' }

  ae = AutoExpreso::Client.new
  ae.login(email, password)
  puts "Account Details:"

  @json ? ae.account_details(json: true) : ae.account_details
end
parse() click to toggle source

Parses the command-line arguments and runs the executable @return [String] The short url or argument passed

# 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) click to toggle source

Configures the arguments for the command @param opts [OptionParser]

# File lib/autoexpreso/cli.rb, line 15
    def set_options(opts)
      opts.version = AutoExpreso::VERSION
      opts.banner  = <<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