Пример #1
0
        public static void RegisterWithApp(CommandLineApplication app)
        {
            app.Command("copy", cmdApp =>
            {
                cmdApp.Description = "Copies a project to a directory. Used to dump the schema of a database (using --source db)." + Environment.NewLine +
                                     "The output directory can be compared using the diff command.";

                var sourceOptions    = DiffCommand.RegisterProjectOptions(cmdApp, "source");
                var optionOutputPath = cmdApp.Option("--output <PATH>", "Where to save the output", CommandOptionType.SingleValue);

                cmdApp.OnExecute(() =>
                {
                    var sourceProject = DiffCommand.GetProjectFromArguments(cmdApp, "source", sourceOptions);
                    if (sourceProject == null)
                    {
                        return(1);
                    }

                    if (string.IsNullOrEmpty(optionOutputPath.Value()))
                    {
                        Console.WriteLine($"--output must be specified");
                        cmdApp.ShowHelp();
                        return(2);
                    }

                    DbProjectFileSystem.SaveAsNewDirectory(sourceProject, optionOutputPath.Value());
                    return(0);
                });
            });
        }
Пример #2
0
        internal static DbProject GetProjectFromArguments(CommandLineApplication cmdApp, string prefix, DbProjectCmdArguments args)
        {
            if (args.Type.Value() == "fs")
            {
                if (string.IsNullOrEmpty(args.Path.Value()))
                {
                    Console.WriteLine($"--{prefix}-fs-path must specify the input directory");
                    cmdApp.ShowHelp();
                    return(null);
                }

                return(DbProjectFileSystem.CreateFromDirectory(args.Path.Value()));
            }
            else if (args.Type.Value() == "db")
            {
                if (string.IsNullOrEmpty(args.ConnectionString.Value()))
                {
                    Console.WriteLine($"--{prefix}-db-cs must specify the MySQL connection string");
                    cmdApp.ShowHelp();
                    return(null);
                }

                var dbInfo = new MySqlArguments()
                {
                    ConnectionString = args.ConnectionString.Value(),
                    UseSshTunnel     = args.SshHost.Values.Count > 0,
                    SshHost          = args.SshHost.Value(),
                    SshPort          = uint.Parse(args.SshHost.Value()),
                    SshUserName      = args.SshUserName.Value(),
                    SshPassword      = args.SshPassword.Value(),
                };

                return(DbProjectMySql.CreateFromDatabase(dbInfo));
            }
            else if (args.Type.Value() == "null")
            {
                return(new DbProject()
                {
                    Statements = new List <Statement>(),
                });
            }
            else
            {
                Console.WriteLine($"Expected --{prefix} fs or --{prefix} db or --{prefix} null");
                cmdApp.ShowHelp();
                return(null);
            }
        }