lib/beerdb/cli/main.rb in beerdb-0.10.0 vs lib/beerdb/cli/main.rb in beerdb-0.10.1

- old
+ new

@@ -74,9 +74,86 @@ desc 'Only show warnings, errors and fatal messages' switch [:q, :quiet], negatable: false +desc "Build DB (download/create/read); use ./Datafile - zips get downloaded to ./tmp" +command [:build,:b] do |c| + + c.action do |g,o,args| + + datafile = Datafile::Datafile.load_file( './Datafile' ) + datafile.download # datafile step 1 - download all datasets/zips + + connect_to_db( opts ) + + BeerDb.create_all + + datafile.read # datafile step 2 - read all datasets + + puts 'Done.' + end # action +end # command setup + + +desc "Read datasets; use ./Datafile - zips required in ./tmp" +command [:read,:r] do |c| + + c.action do |g,o,args| + + connect_to_db( opts ) + + datafile = Datafile::Datafile.load_file( './Datafile' ) + datafile.read + + puts 'Done.' + end # action +end # command setup + +desc "Download datasets; use ./Datafile - zips get downloaded to ./tmp" +command [:download,:dl] do |c| + + 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.download + + puts 'Done.' + end # action +end # command setup + + +desc "Build DB w/ quick starter Datafile templates" +arg_name 'NAME' # optional setup profile name +command [:new,:n] do |c| + + c.action do |g,o,args| + + ## todo: required template name (defaults to worldcup2014) + setup = args[0] || 'at' + + worker = Fetcher::Worker.new + ## note: lets use http:// instead of https:// for now - lets us use person proxy (NOT working w/ https for now) + worker.copy( "http://github.com/openbeer/datafile/raw/master/#{setup}.rb", './Datafile' ) + + ## step 2: same as command build (todo - reuse code) + datafile = Datafile::Datafile.load_file( './Datafile' ) + datafile.download # datafile step 1 - download all datasets/zips + + connect_to_db( opts ) ### todo: check let connect go first?? - for logging (logs) to db ??? + + BeerDb.create_all + + datafile.read # datafile step 2 - read all datasets + + puts 'Done.' + end # action +end # command setup + + + desc 'Create DB schema' command [:create] do |c| c.desc 'Extra tables (notes,drinks,marks,users)' c.switch [:extras], negatable: false