Class: Resty::Cli

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

Instance Method Summary collapse

Instance Method Details

#basic_auth_invalid?(options) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
# File 'lib/resty/cli.rb', line 34

def basic_auth_invalid?(options)
  username = options[:username]
  password = options[:password]
  (username && password.nil?) || (username.nil? && password)
end

#missing_host_or_alias?(options) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/resty/cli.rb', line 30

def missing_host_or_alias?(options)
  (options[:alias] && options[:host]) || (options[:alias].nil? && options[:host].nil?)
end

#runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/resty/cli.rb', line 6

def run
  options = Trollop::options do
    version "Version: #{Resty::VERSION}\n"
    opt :alias, "The per-host entry to use in ~/.ruby_resty.yml", type: :string, short: "-a"
    opt :headers, "The headers sent with each request. Ex: X-NYAN-CAT-SECRET-KEY:nyan_nyan",
      type: :strings, short: "-H"
    opt :host, "The hostname of the REST service. Ex: http://nyan.cat", type: :string, short: "-h"
    opt :username, "HTTP basic authentication username", type: :string, short: "-u"
    opt :password, "HTTP basic authentication password", type: :string, short: "-p"
    opt :verbose, "Verbose mode", short: "-v"
  end

  if missing_host_or_alias?(options)
    puts "Please specify an alias OR a host. Use --help for more info."
  elsif basic_auth_invalid?(options)
    puts "Please specify a username and password. Use --help for more info."
  else
    Resty::Repl.start(options)
  end

rescue ConfigFileError => e
  puts e.message
end