#!/usr/bin/env ruby # frozen_string_literal: true require 'thor' require 'master_data_tool' environment_path = "#{Dir.pwd}/config/environment" require environment_path module MasterDataTool class CLI < Thor option :dry_run, default: nil, type: :boolean option :verify, default: nil, type: :boolean option :only_import_tables, default: nil, type: :array option :except_import_tables, default: nil, type: :array option :only_verify_tables, default: nil, type: :array option :except_verify_tables, default: nil, type: :array option :skip_no_change, default: nil, type: :boolean option :silent, default: nil, type: :boolean option :override_identifier, default: nil, type: :string option :delete_all_ignore_foreign_key, default: nil, type: :boolean desc 'import', 'import' def import new_options = MasterDataTool.config.default_import_options.with_indifferent_access.merge(options) executor = MasterDataTool::Import::Executor.new(**new_options.symbolize_keys) executor.execute end option :ignore_empty_table, default: true, type: :boolean option :ignore_tables, default: [], type: :array option :ignore_column_names, default: [], type: :array option :only_tables, default: nil, type: :array option :verbose, default: false, type: :boolean desc 'dump', 'dump' def dump ignore_empty_table = options[:ignore_empty_table] ignore_tables = options[:ignore_tables] ignore_column_names = options[:ignore_column_names] only_tables = options[:only_tables] verbose = options[:verbose] executor = MasterDataTool::Dump::Executor.new( ignore_empty_table: ignore_empty_table, ignore_tables: ignore_tables, ignore_column_names: ignore_column_names, only_tables: only_tables, verbose: verbose ) errors = executor.execute return if errors.empty? message = errors.map { |error| "table:#{error.table}\tmessage:#{error.exception.message}" }.join("\n") raise message end end end MasterDataTool::CLI.start(ARGV)