Class: Tidtools::TidgrepCli

Inherits:
Object
  • Object
show all
Defined in:
lib/tidtools/tidgrep_cli.rb

Class Method Summary collapse

Class Method Details

.execute(stdout, arguments = []) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/tidtools/tidgrep_cli.rb', line 7

def self.execute(stdout, arguments=[])
  file_names = ENV['TIDDLYWIKI_PATHS'].split(";")
  file_no = 0
  title = nil
  regexp_option = 0
  report = false 
  match_rule = "line"
  is_comp = false
  kcode = Platform.get_shell_kcode
  
  opt = OptionParser.new('tidgrep [option] keyword')
  opt.on('-f TIDDLYWIKI_PATHS', '--filename TIDDLYWIKI_PATHS', 'TiddlyWiki path names') {|v| file_names = v.split }
  opt.on('-n SELECT_NO', '--fileno SELECT_NO', 'file select number. (0 is all. 1,2,3,4.. is select only one.)') {|v| file_no = v.to_i }
  opt.on('-t TITLE', '--title TITLE', 'match title') {|v| title = v }
  opt.on('-i', '--ignore', 'ignore case') {|v| regexp_option |= Regexp::IGNORECASE }
  opt.on('-r', '--report', 'disp report') {|v| report = true }
  opt.on('-m MATCH_RULE', '--match MATCH_RULE', 'match rule [line, tiddle, tweet]') {|v| match_rule = v }
  opt.on('-c', '--comp', 'compression disp') {|v| is_comp = true; report = true }
  opt.parse!(arguments)

  obj = Tidgrep.new(stdout,
                    file_names,
                    file_no,
                    title,
                    regexp_option,
                    report,
                    match_rule,
                    is_comp,
                    arguments,
                    kcode)

  if obj.validOption?
    obj.execute
  else
    stdout.puts opt.help
  end
end