Class: Librr::CmdParser

Inherits:
Thor
  • Object
show all
Defined in:
lib/librr/cmd_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run!Object



57
58
59
60
# File 'lib/librr/cmd_parser.rb', line 57

def self.run!
  @@client = Librr::CmdClient.new('localhost', Settings.runner_port)
  self.start(ARGV)
end

Instance Method Details

#add(dir) ⇒ Object



23
24
25
26
# File 'lib/librr/cmd_parser.rb', line 23

def add(dir)
  puts "indexing: #{dir}"
  @@client.cmd(:add, dir: File.expand_path(dir))
end

#listObject



35
36
37
# File 'lib/librr/cmd_parser.rb', line 35

def list
  puts @@client.cmd(:list)
end

#reindexObject



40
41
42
# File 'lib/librr/cmd_parser.rb', line 40

def reindex
  @@client.cmd(:reindex)
end

#remove(dir) ⇒ Object



29
30
31
32
# File 'lib/librr/cmd_parser.rb', line 29

def remove(dir)
  puts "removing: #{dir}"
  @@client.cmd(:remove, dir: File.expand_path(dir))
end

#search(text) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/librr/cmd_parser.rb', line 47

def search(text)
  puts "searching: #{text}"
  results = @@client.cmd(:search, text: text, all: options[:all], rows: options[:rows])
  if results.empty?
    puts "find no result"
  else
    puts results.map{|v| v.join(":")}
  end
end

#startObject



10
11
12
13
14
# File 'lib/librr/cmd_parser.rb', line 10

def start
  if @@client.check_start(options[:sync])
    puts 'server already started..'
  end
end

#stopObject



17
18
19
20
# File 'lib/librr/cmd_parser.rb', line 17

def stop
  puts 'stopping..'
  @@client.cmd(:stop) rescue nil
end