lib/sportdb/cli/main.rb in sportdb-2.1.0 vs lib/sportdb/cli/main.rb in sportdb-2.1.1
- old
+ new
@@ -58,10 +58,16 @@
desc 'Database name'
arg_name 'NAME'
default_value opts.db_name
flag [:n, :dbname]
+desc 'Datafile'
+arg_name 'FILE'
+default_value opts.datafile
+flag [:f, :datafile]
+
+
desc '(Debug) Show debug messages'
switch [:verbose], negatable: false ## todo: use -w for short form? check ruby interpreter if in use too?
desc 'Only show warnings, errors and fatal messages'
switch [:q, :quiet], negatable: false
@@ -85,21 +91,21 @@
command [:build,:b] do |c|
c.action do |g,o,args|
## check if datafile exists, if NOT assume working dir (./) is a package
- if File.file?( './Datafile' ) ## note use file? (exist? will also check for directory/folder!!)
- datafile = Datafile::Datafile.load_file( './Datafile' )
+ if File.file?( opts.datafile ) ## note use file? (exist? will also check for directory/folder!!)
+ datafile = Datafile::Datafile.load_file( opts.datafile )
datafile.download # datafile step 1 - download all datasets/zips
connect_to_db( opts )
SportDb.create_all
datafile.read # datafile step 2 - read all datasets
else
- puts "no ./Datafile found; try local build in >#{Dir.pwd}<"
+ puts "no datafile >#{opts.datafile}< found; trying local build in >#{Dir.pwd}<"
connect_to_db( opts )
SportDb.create_all
pack = SportDb::DirPackage.new( Dir.pwd ) ## note: pass in full path for now (and NOT ./) - why? why not?
@@ -115,17 +121,17 @@
command [:read,:r] do |c|
c.action do |g,o,args|
## check if datafile exists, if NOT assume working dir (./) is a package
- if File.file?( './Datafile' ) ## note use file? (exist? will also check for directory/folder!!)
+ if File.file?( opts.datafile ) ## note use file? (exist? will also check for directory/folder!!)
connect_to_db( opts )
- datafile = Datafile::Datafile.load_file( './Datafile' )
+ datafile = Datafile::Datafile.load_file( opts.datafile )
datafile.read
else
- puts "no ./Datafile found; try local read in >#{Dir.pwd}<"
+ puts "no datafile >#{opts.datafile}< found; trying local read in >#{Dir.pwd}<"
connect_to_db( opts )
pack = SportDb::DirPackage.new( Dir.pwd ) ## note: pass in full path for now (and NOT ./) - why? why not?
pack.read # read all datasets
@@ -141,11 +147,11 @@
c.action do |g,o,args|
# note: no database connection needed (check - needed for logs?? - not setup by default???)
- datafile = Datafile::Datafile.load_file( './Datafile' )
+ datafile = Datafile::Datafile.load_file( opts.datafile )
datafile.download
puts 'Done.'
end # action
end # command setup
@@ -160,9 +166,11 @@
## todo: required template name (defaults to eng2019-20) -- was worldcup2018
setup = args[0] || 'eng2019-20'
worker = Fetcher::Worker.new
worker.copy( "https://github.com/openfootball/datafile/raw/master/#{setup}.rb", './Datafile' )
+
+ ## todo/check: use custom datafile (opts.datafile) if present? why? why not?
## step 2: same as command build (todo - reuse code)
datafile = Datafile::Datafile.load_file( './Datafile' )
datafile.download # datafile step 1 - download all datasets/zips