lib/beerdb/cli/main.rb in beerdb-1.0.0 vs lib/beerdb/cli/main.rb in beerdb-1.0.1
- old
+ new
@@ -10,11 +10,11 @@
def initialize
LogUtils::Logger.root.level = :info # set logging level to info
end
def run( args )
- puts BeerDbCli.banner
+ puts BeerDbTool.banner
Toolii.run( args )
end
end
@@ -30,20 +30,13 @@
def self.connect_to_db( options )
puts "working directory: #{Dir.pwd}"
- config = {
- adapter: 'sqlite3',
- database: "#{options.db_path}/#{options.db_name}"
- }
+ BeerDb.connect( adapter: 'sqlite3',
+ database: "#{options.db_path}/#{options.db_name}" )
- puts "Connecting to db using settings: "
- pp config
-
- BeerDb.connect( config )
-
LogDb.setup # start logging to db (that is, save logs in logs table in db)
end
@@ -51,11 +44,11 @@
opts = BeerDb::Opts.new
program_desc 'beer.db command line tool'
-version BeerDbCli::VERSION
+version BeerDbTool::VERSION
### global option (required)
## todo: add check that path is valid?? possible?
@@ -108,10 +101,11 @@
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|
@@ -129,11 +123,11 @@
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)
+ ## todo: required template name (defaults to at)
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' )
@@ -176,39 +170,12 @@
puts 'Done.'
end # action
end # command create
-desc "Create DB schema 'n' load all world and beer data"
-arg_name 'NAME' # optional setup profile name
-command [:setup,:s] do |c|
- c.desc 'Beer data path'
- c.arg_name 'PATH'
- c.default_value opts.data_path
- c.flag [:i,:include]
- c.desc 'World data path'
- c.arg_name 'PATH'
- c.flag [:worldinclude] ## todo: use --world-include - how? find better name? add :'world-include' ???
-
- c.action do |g,o,args|
-
- connect_to_db( opts )
-
- ## todo: document optional setup profile arg (defaults to all)
- setup = args[0] || 'all'
-
- BeerDb.create_all
-
- WorldDb.read_all( opts.world_data_path )
- BeerDb.read_setup( "setups/#{setup}", opts.data_path )
- puts 'Done.'
- end # action
-end # command setup
-
-
desc 'Update all beer data'
arg_name 'NAME' # optional setup profile name
command [:update,:up,:u] do |c|
c.desc 'Beer data path'
@@ -259,48 +226,11 @@
end
end # command load
-## fix/todo: add server alias (serve/server)
-desc 'Start web service (HTTP JSON API)'
-command [:serve,:server] do |c|
-
- c.action do |g,o,args|
-
- connect_to_db( opts )
-
- # NB: server (HTTP service) not included in standard default require
- require 'beerdb/service'
-
-# make sure connections get closed after every request e.g.
-#
-# after do
-# ActiveRecord::Base.connection.close
-# end
-#
-
- puts 'before add middleware ConnectionManagement'
- BeerDb::Service.use ActiveRecord::ConnectionAdapters::ConnectionManagement
- puts 'after add middleware ConnectionManagement'
- ## todo: check if we can check on/dump middleware stack
-
- ## rack middleware might not work with multi-threaded thin web server; close it ourselfs
- BeerDb::Service.after do
- puts " #{Thread.current.object_id} -- make sure db connections gets closed after request"
- # todo: check if connection is open - how?
- ActiveRecord::Base.connection.close
- end
-
- BeerDb::Service.run!
-
- puts 'Done.'
- end
-end # command serve
-
-
desc 'Show stats'
command :stats do |c|
c.action do |g,o,args|
connect_to_db( opts )
@@ -316,12 +246,14 @@
command :props do |c|
c.action do |g,o,args|
connect_to_db( opts )
- ### fix: use ConfDb.props or similar !!!
- ### BeerDb.props
+ ## fix: use ConfDb.dump or similar
+ ConfDb::Models::Prop.all.each do |prop|
+ puts "#{prop.key} | #{prop.value}"
+ end
puts 'Done.'
end
end
@@ -330,9 +262,10 @@
command :logs do |c|
c.action do |g,o,args|
connect_to_db( opts )
+ ## fix: use LogDb.dump or similar
LogDb::Models::Log.all.each do |log|
puts "[#{log.level}] -- #{log.msg}"
end
puts 'Done.'