class Zugzwang::CLI
Public Instance Methods
create(database = 'lichess', *items)
click to toggle source
# File lib/zugzwang/cli.rb, line 13 def create(database = 'lichess', *items) if items.empty? puts "\n\e[1;91mERROR\e[0m: No files specified." if items.empty? return end database_path = sanitize_path(database) adapter = options[:adapter].to_sym if Zugzwang::ADAPTERS.include?(adapter) begin Zugzwang::Connection.new(database_path, adapter).populate(items) rescue Sequel::DatabaseConnectionError puts "\n\e[1;91mERROR\e[0m: Directory \e[1m#{File.dirname(database)}\e[0m does not exist." pass = false until pass response = ask("\e[1mPROMPT: \e[0mCreate directory \e[1m#{File.dirname(database_path)}\e[0m? [Y/n]") if %w[Y y YES Yes yes].include? response puts empty_directory(File.dirname(database_path)) Zugzwang::Connection.new(database_path,adapter).populate(items) pass = true elsif %w[N n NO No no].include? response pass = true end end end else puts "\n\e[1;91mERROR\e[0m: Database adapter argument should be one of [#{Zugzwang::ADAPTERS*', '}]." end end