#!/usr/bin/env ruby require "arxutils_sqlite3" require "simpleoptparse" require "pp" require "ykutils" require "ykxutils" config = Arxutils_Sqlite3::Config.new cli = Arxutils_Sqlite3::Cli.new(config) config.require_opts_file begin require "dbrelation" rescue LoadError => ex pp ex.message end klass = nil setting = config.load_setting_yaml_file klass = setting[:klass] # DBセットアップクラス config.require_dbsetup_file banner = "Usage: bundle exec arxutils_sqlite3 --cmd=(s|c|m|i|d|b) -y yaml_file --klass=class" opts = @opts ? @opts : {} opts["dbconfig"] = Arxutils_Sqlite3::Config::DBCONFIG_SQLITE3 Simpleoptparse::Simpleoptparse.parse(ARGV, opts, banner, Arxutils_Sqlite3::VERSION, nil) do |parser| parser.on("--cmd X", %w[s c m i d b]) { |x| opts["cmd"] = x } parser.on("-y yaml_file", "--yaml yaml_file") { |x| opts["yaml"] = x } parser.on("--klass klass") { |x| opts["klass"] = x } end klass = opts["klass"] if opts["klass"] env = ENV.fetch("ENV", nil) env ||= "production" case opts["cmd"] when "s" config.check_file_exist(Arxutils_Sqlite3::Config::DEST_OPTS_FILE, banner, 10) if opts["klass"].nil? || opts["klass"].strip == "" puts banner exit 20 end cli.setup(klass) when "c" dbconfig = opts["dbconfig"] relation = opts["relation"] cli.makeconfig(dbconfig, relation, banner, 30, opts) when "m" yaml_fname = opts["yaml"] relation = opts[:relation] dbconfig = opts["dbconfig"] if yaml_fname.nil? || yaml_fname.strip == "" puts banner exit 40 end yaml_pn = Pathname.new(yaml_fname) config.check_file_not_exist(yaml_pn, banner, 55) cli.migrate(yaml_pn, relation, klass, dbconfig, env) when "i" dbconfig = opts["dbconfig"] cli.integrate(dbconfig, env) when "d" db_scheme_ary = nil dbconfig = opts["dbconfig"] relation = opts["relation"] cli.delete(dbconfig, db_scheme_ary, relation) when "b" db_scheme_ary = nil dbconfig = opts["dbconfig"] relation = opts["relation"] cli.delete_db(dbconfig, db_scheme_ary, relation) else puts "Invalid command(#{opts["cmd"]}) specified!!" end