Exemplo n.º 1
0
        /// <summary>
        /// Initializes the run options.
        /// </summary>
        /// <param name="args">The command line args.</param>
        /// <returns></returns>
        public void Init(string[] args)
        {
            //defaults
            Init();

            //parse up args
            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "-d":
                case "--data":
                    foreach (string table in args[++i].Split(','))
                    {
                        LoadData.Add(table);
                    }
                    break;

                case "--diffFile":
                    DiffFile = args[++i];
                    break;

                case "-f":
                case "--fullyScripted":
                    FullyScripted = true;
                    break;

                case "-h":
                case "--help":
                    Logger.Log("A tool to run scripts on a Microsoft SQL Server 2000 server", OutputLevel.Errors);
                    Logger.Log("Usage: SQLUpdater <args> [-t] <target> [-r] [reference]", OutputLevel.Errors);
                    Logger.Log("\t-d <name[,name]>: Tables to load data from", OutputLevel.Errors);
                    Logger.Log("\t-f: the database is fully scripted", OutputLevel.Errors);
                    Logger.Log("\t-h: display this help message and exit", OutputLevel.Errors);
                    Logger.Log("\t-l <level>: transaction level (None, TableOnly, Everything)", OutputLevel.Errors);
                    Logger.Log("\t-o <level>: output level (Errors, Differences, Updates, Reads)", OutputLevel.Errors);
                    Logger.Log("\t-s <directory>: directory to store scripts in before execution", OutputLevel.Errors);
                    Logger.Log("\t-w <name[,name]>: objects to write out changes to", OutputLevel.Errors);
                    Logger.Log("\t--diffFile <filename>: name of a single file to store a difference summary in", OutputLevel.Errors);
                    Logger.Log("\t--ignore <name[,name]>: script files to ignore", OutputLevel.Errors);
                    Logger.Log("\t--minimalDependencies: only recreate otherwise dropped objects", OutputLevel.Errors);
                    Logger.Log("\t--parserOutput <directory>: directory for debugging parser output", OutputLevel.Errors);
                    Logger.Log("\t--scriptFile <filename>: name of a single file to store scripts in in conjunction with -s", OutputLevel.Errors);
                    Logger.Log("\t--test: run in test mode without updating the database", OutputLevel.Errors);
                    Environment.Exit(0);
                    break;

                case "--ignore":
                    foreach (string name in args[++i].Split(','))
                    {
                        IgnoreFiles.Add(name);
                    }
                    break;

                case "-l":
                    TransactionLevel = (TransactionLevel)Enum.Parse(typeof(TransactionLevel), args[++i]);
                    break;

                case "-m":
                case "--minimalDependencies":
                    MinimalDependencies = true;
                    break;

                case "-o":
                case "--outputlevel":
                    OutputLevel = (OutputLevel)Enum.Parse(typeof(OutputLevel), args[++i]);
                    break;

                case "--parserOutput":
                    ParserOutput = args[++i];
                    break;

                case "-r":
                    AddConnection(args[++i], Connections.References);
                    break;

                case "-s":
                    ScriptOutputDirectory = args[++i];
                    if (!ScriptOutputDirectory.EndsWith("\\"))
                    {
                        ScriptOutputDirectory = ScriptOutputDirectory + "\\";
                    }
                    break;

                case "--scriptFile":
                    ScriptFile = args[++i];
                    break;

                case "-t":
                    AddConnection(args[++i], Connections.Targets);
                    break;

                case "--test":
                    Test = true;
                    break;

                case "-w":
                case "--write":
                    foreach (string name in args[++i].Split(','))
                    {
                        WriteObjects.Add(name);
                    }
                    break;

                default:
                    if (args[i][0] == '-' || (Connections.References.Count > 0 && Connections.Targets.Count > 0))
                    {
                        Logger.Log("Unknown argument: " + args[i], OutputLevel.Errors);
                        Environment.Exit(-1);
                    }
                    else
                    {
                        if (Connections.Targets.Count == 0)
                        {
                            AddConnection(args[i], Connections.Targets);
                        }
                        else
                        {
                            AddConnection(args[i], Connections.References);
                        }
                    }
                    break;
                }
            }
        }