Class: AutoExpreso::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/autoexpreso/cli.rb

Overview

A Simple class for the executable version of the gem

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.

Parameters:

  • args (Array<String>)

    The command-line arguments



9
10
11
# File 'lib/autoexpreso/cli.rb', line 9

def initialize(args)
  @args = args
end

Instance Method Details

#headerObject



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

#loginObject



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/autoexpreso/cli.rb', line 59

def 
  header

  username = ask('Username:  ')
  password = ask('Password:  ') { |q| q.echo = '*' }

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

  @json ? ae.(json: true) : ae.
end

#parseString

Parses the command-line arguments and runs the executable

Returns:

  • (String)

    The short url or argument passed



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  if @login
  puts opts.help
end

#set_options(opts) ⇒ Object

Configures the arguments for the command

Parameters:

  • opts (OptionParser)


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 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