Module: Beats::Command

Defined in:
lib/beats/command.rb,
lib/beats/commands/api.rb,
lib/beats/commands/auth.rb,
lib/beats/commands/base.rb,
lib/beats/commands/help.rb,
lib/beats/commands/ingest.rb,
lib/beats/commands/stream.rb,
lib/beats/commands/account.rb,
lib/beats/commands/version.rb,
lib/beats/commands/sentence.rb

Defined Under Namespace

Classes: Account, Api, Auth, Base, CommandFailed, Help, Ingest, InvalidCommand, Sentence, Stream, Version

Constant Summary collapse

DEFAULT_COMMAND =
'help'

Class Method Summary collapse

Class Method Details

.parse(command, *args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/beats/command.rb', line 13

def parse(command, *args)
  command = DEFAULT_COMMAND if command == ''
  parts = command.split(':')
  klass = command_class(parts.first)
  if klass.has_command?(parts.last)
    [klass.new(*args.flatten), parts.last.to_sym]
  elsif klass.has_command?('gem_execute')
    [klass.new(*args.flatten << parts.last), 'gem_execute'.to_sym]
  else
    raise InvalidCommand, command
  end
end

.run(command, *args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/beats/command.rb', line 26

def run(command, *args)
  object, method = parse(command, *args)
  object.send(method)
rescue RestClient::Unauthorized => e
  puts '!!! AUTHENTICATION REQUIRED !!!'
  run 'auth:login'
  retry
rescue RestClient::RequestTimeout
  error 'Request timed out. Please try again, or contact support if this issue persists.'
rescue RestClient::Exception => e
  error extract_error(e)
rescue SocketError => e
  error "Unable to connect to server. Your internet connection might be down."
rescue InvalidCommand => e
  error "Unknown command: #{e.to_s}"
rescue LoadError => e 
  error "Load error: #{e.to_s}"
rescue CommandFailed => e
  error e.message
rescue Interrupt => e
  error "\n[canceled]"
end