Class: Librr::CmdParser

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

Defined Under Namespace

Classes: Daemon

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.clientObject

Returns the value of attribute client.



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

def client
  @client
end

Class Method Details

.run!Object



81
82
83
84
# File 'lib/librr/cmd_parser.rb', line 81

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

Instance Method Details

#add(dir) ⇒ Object



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

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

#listObject



52
53
54
# File 'lib/librr/cmd_parser.rb', line 52

def list
  puts self.class.client.cmd(:list)
end

#reindexObject



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

def reindex
  self.class.client.cmd(:reindex)
end

#remove(dir) ⇒ Object



46
47
48
49
# File 'lib/librr/cmd_parser.rb', line 46

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

#search(text) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/librr/cmd_parser.rb', line 65

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