public Migrator Parse(string[] args, Migrator migrator)
        {
            Options = new Dictionary<string, string>();
            var cli = new CommandParser();

            cli = CreateDefaultOpts(cli);
            cli = CreateCustomOpts(cli);

            cli.Parse(args);

            if (cli.UnknownCommands.Count > 0)
            {
                foreach (string unknown in cli.UnknownCommands)
                {
                    Console.WriteLine("Invalid command: " + unknown);
                }

                Console.WriteLine(cli.GetHelp());
                Environment.Exit(0);
            }
            else if (cli.MissingRequiredCommands.Count > 0)
            {
                foreach (string missing in cli.MissingRequiredCommands)
                {
                    Console.WriteLine("ERROR: Missing argument: " + missing);
                }

                Console.WriteLine(cli.GetHelp());
                Environment.Exit(0);
            }
            else if (_showHelp)
            {
                Console.WriteLine(cli.GetHelp());
                Environment.Exit(0);
            }

            migrator = InitMigrator(migrator);

            SetDefaultOptionsForMigrator(migrator);
            SetCustomOptionsForMigrator(migrator);

            string strategy = string.Empty;
            if (Options.ContainsKey("strategy"))
            {
                strategy = Options["strategy"];
            }

            migrator.Strategy = Factory.Create(strategy);

            return migrator;
        }
Esempio n. 2
0
 public void SetUp()
 {
     _migrator = new Migrator();
     _migrator.Guard = new Guard();
 }
        public Migrator SetDefaultOptionsForMigrator(Migrator migrator)
        {
            // if (options.ini)
            // ini_parser.file = new File(options.ini)
            // if (options.section)
            // ini_parser.use_section = options.section

            if (Options.ContainsKey("suffix"))
            {
                migrator.Guard.Suffix = Options["suffix"];
            }

            if (Options.ContainsKey("host"))
            {
                migrator.DbInterface.Executor.Host = Options["host"];
            }

            if (Options.ContainsKey("password"))
            {
                migrator.DbInterface.Executor.Password = Options["password"];
            }

            if (Options.ContainsKey("database"))
            {
                migrator.DbInterface.Executor.Database = Options["database"];
            }

            if (Options.ContainsKey("command"))
            {
                migrator.DbInterface.Executor.Command = Options["command"];
            }

            if (Options.ContainsKey("args"))
            {
                migrator.DbInterface.Executor.Args = Options["args"];
            }

            if (Options.ContainsKey("username"))
            {
                migrator.DbInterface.Executor.Username = Options["username"];
            }

            return migrator;
        }
 public virtual Migrator SetCustomOptionsForMigrator(Migrator migrator)
 {
     return migrator;
 }
 public virtual Migrator InitMigrator(Migrator migrator)
 {
     throw new Exception("InitMigrator() must be overwritten!");
 }