Module: Fbfind

Defined in:
lib/fbtok/command-fbfind.rb

Class Method Summary collapse

Class Method Details

.main(args = ARGV) ⇒ Object



5
6
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/fbtok/command-fbfind.rb', line 5

def self.main( args=ARGV )

opts = {
    debug: false,
    file:  nil,
    seasons: [],
}


parser = OptionParser.new do |parser|
  parser.banner = "Usage: #{$PROGRAM_NAME} [options] DATAFILE or DIR"


  parser.on( "-q", "--quiet",
             "less debug output/messages (default: #{!opts[:debug]})" ) do |debug|
    opts[:debug] = false
  end
  parser.on( "--verbose", "--debug",
               "turn on verbose / debug output (default: #{opts[:debug]})" ) do |debug|
    opts[:debug] = true
  end

  parser.on( "--seasons SEASONS",
               "filter by seasons (default: #{opts[:seasons]})") do |seasons|
    opts[:seasons] = seasons
                        .split( /[,:]/ )
                        .map { |season| Season.parse(season.strip) }
  end


  parser.on( "-f FILE", "--file FILE",
                "read datafiles (pathspecs) via .csv file") do |file|
    opts[:file] = file
  end
end
parser.parse!( args )



if opts[:debug]
  puts "OPTS:"
  p opts
  puts "ARGV:"
  p args
end


# SportDb::Parser::Linter.debug = opts[:debug]
# SportDb::Parser::Linter.warn  = opts[:warn]



## todo/check - use packs or projects or such
##                instead of specs - why? why not?
specs =  if opts[:file]
            read_pathspecs( opts[:file] )
         else
            ## check for filepack
            filepack =  if File.file?( './filepack.txt')
                            read_filepack( './filepack.txt' )
                        else
                             nil
                        end

            path = SportDb::Pathspec.path(
                          ['/sports/sportdb/sport.db.v2/parser/fbtxt-specs',
                           '/sports/sportdb/sport.db.v2/parser/fbtxt-samples',
                           '/sports/openfootball'])

            build_pathspecs( args, path: path,
                                   filepack: filepack )
         end


if opts[:debug]
  puts
  puts "pathspecs:"
  pp specs
end


if opts[:seasons].size > 0
   specs = filter_pathspecs( specs, seasons: opts[:seasons] )
end

puts
specs.each_with_index do |rec,i|
    path = rec['path']
    datafiles = rec['datafiles']

    print "==> [#{i+1}/#{specs.size}] #{path}"
    print "  (incl. seasons #{opts[:seasons]})"     if opts[:seasons].size > 0
    print "...\n"
    pp datafiles
    puts "   #{datafiles.size} datafile(s)"
end

puts "bye"
end