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

#loginObject



49
50
51
52
53
# File 'lib/autoexpreso/cli.rb', line 49

def 
  username = ask('Username:  ')
  password = ask('Password:  ') { |q| q.echo = '*' }
  AutoExpreso::Client.new.(username, password)
end

#parseString

Parses the command-line arguments and runs the executable

Returns:

  • (String)

    The short url or argument passed



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