<commit_before>package ru.yandex.mysqlDiff


import java.io.File
import scalax.io._

import diff._
import model._
import script._
import jdbc._

object Diff {
    val helpBanner: String = "MySQL diff maker\n" +
        "How to use:\n" +
        "mysqlDiff.sh from_file|from_jdbc_url to_file|to_jdbc_url"

    def main(args: Array[String]) {
        if (args.length != 2) {
            System.err.println(helpBanner)
            System.exit(1)
        } else {
            val fromArgs = args(0)
            val toArgs = args(1)
            if (fromArgs == null || fromArgs.trim == "" || toArgs == null|| toArgs.trim == "") {
                System.err.println(helpBanner)
                System.exit(1)
            } else {
                try {
                    var fromdb = getModelFromArgsLine(args(0))
                    var todb = getModelFromArgsLine(args(1))
                    Console.println("-- Start diff script from " + fromArgs  + " to " + toArgs + "\n")

                    val dbDiff = DiffMaker.compareDatabases(fromdb, todb)

                    val script = DiffSerializer.serialize(fromdb, todb, dbDiff)

                    println(script)

                    Console.println("-- End of diff script from " + fromArgs  + " to " + toArgs)
                } catch {
                    case e: MysqlDiffException => {
                        System.err.println("An error while diff building")
                        System.err.println(e.message)
                        System.exit(2)
                    }
                }
            }
        }
    }

    def getModelFromArgsLine(arg: String): DatabaseModel = {
        if (arg.toLowerCase.startsWith("jdbc:"))
            JdbcModelExtractor.parse(arg.trim)
        else {
            val sourceF = new File(arg)
            if (!sourceF.isFile)  throw new MysqlDiffException("\"" + arg + "\" file is not a file.")
            var str = new FileExtras(sourceF).slurp
            model.ModelParser.parseModel(str)
        }
    }

}<commit_msg>[svn r897] cmd arg to compare only one table<commit_after>package ru.yandex.mysqlDiff


import java.io.File
import scalax.io._

import diff._
import model._
import script._
import jdbc._

object Diff {
    val helpBanner: String = "MySQL diff maker\n" +
        "How to use:\n" +
        "mysqlDiff.sh from_file|from_jdbc_url to_file|to_jdbc_url"

    def main(args: Array[String]) {
        def usage() {
            Console.err.println("mysql-diff.sh from_file|from_jdbc_url to_file|to_jdbc_url <table>")
        }
        
        val (fromdb, todb) = args match {
            case Seq(from, to) =>
                (getModelFromArgsLine(from), getModelFromArgsLine(to))
            case Seq(from, to, table) =>
                (getModelFromArgsLine(from, table), getModelFromArgsLine(to, table))
            case _ =>
                usage()
                exit(1)
        }
        
        val dbDiff = DiffMaker.compareDatabases(fromdb, todb)

        val script = DiffSerializer.serialize(fromdb, todb, dbDiff)

        print(script)

    }
    
    def getModelFromArgsLine(arg: String): DatabaseModel = {
        if (arg.startsWith("jdbc:"))
            JdbcModelExtractor.parse(arg)
        else {
            var str = ReaderResource.file(arg).slurp
            model.ModelParser.parseModel(str)
        }
    }
    
    def getModelFromArgsLine(arg: String, table: String) = {
        if (arg.startsWith("jdbc:"))
            new DatabaseModel("xx", List(JdbcModelExtractor.parseTable(table, arg)))
        else {
            var str = ReaderResource.file(arg).slurp
            val tableModel = model.ModelParser.parseModel(str).declarations.filter(_.name == table).first
            new DatabaseModel("xx", List(tableModel))
        }
    }
}

// vim: set ts=4 sw=4 et:
{'fraction_non_alphanumeric': 0.10874704491725769, 'fraction_numerical': 0.0036774363015497765, 'mean_word_length': 1.7714701601164484, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1206629', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1104, 'n_words': 242}