Beispiel #1
0
        public static int Main([NotNull] string[] args)
        {
            ConsoleCommandLogger.IsVerbose = HandleVerboseOption(ref args);
            HandleDebugSwitch(ref args);

            try
            {
                return(ExecuteCommand.Create(ref args).Execute(args));
            }
            catch (Exception ex)
            {
                // TODO ensure always a json response if --json is supplied
                if (ex is TargetInvocationException)
                {
                    ex = ex.InnerException;
                }

                if (!(ex is OperationException))
                {
                    ConsoleCommandLogger.Error(ex.ToString());
                }

                ConsoleCommandLogger.Error(ex.Message.Bold().Red());
                return(1);
            }
        }
Beispiel #2
0
        private static void ReportResults(IEnumerable <Type> contextTypes)
        {
            var any = false;

            foreach (var contextType in contextTypes)
            {
                ConsoleCommandLogger.Output(contextType.FullName as string);
                any = true;
            }

            if (!any)
            {
                ConsoleCommandLogger.Error("No DbContext was found");
            }
        }
Beispiel #3
0
        private static void ReportResults(IEnumerable <MigrationInfo> migrations)
        {
            var any = false;

            foreach (var migration in migrations)
            {
                ConsoleCommandLogger.Output(migration.Id as string);
                any = true;
            }

            if (!any)
            {
                ConsoleCommandLogger.Error("No migrations were found");
            }
        }
        public static void Configure([NotNull] CommandLineApplication command, [NotNull] CommonCommandOptions commonOptions)
        {
            command.Description = "Add a new migration";

            var name = command.Argument("[name]", "The name of the migration");

            var outputDir = command.Option(
                "-o|--output-dir <path>",
                "The directory (and sub-namespace) to use. If omitted, \"Migrations\" is used. Relative paths are relative the directory in which the command is executed.");
            var context = command.Option(
                "-c|--context <context>",
                "The DbContext to use. If omitted, the default DbContext is used");
            var environment = command.Option(
                "-e|--environment <environment>",
                "The environment to use. If omitted, \"Development\" is used.");
            var json = command.JsonOption();

            command.HelpOption();
            command.VerboseOption();

            command.OnExecute(
                () =>
            {
                if (string.IsNullOrEmpty(name.Value))
                {
                    ConsoleCommandLogger.Error(("Missing required argument '" + name.Name + "'").Bold().Red());
                    command.ShowHelp();

                    return(1);
                }

                return(Execute(commonOptions.Value(),
                               name.Value,
                               outputDir.Value(),
                               context.Value(),
                               environment.Value(),
                               json.HasValue()
                            ? (Action <MigrationFiles>)ReportJson
                            : null));
            });
        }
Beispiel #5
0
        public static void Configure([NotNull] CommandLineApplication command, [NotNull] CommonCommandOptions commonOptions)
        {
            command.Description = "Scaffolds a DbContext and entity type classes for a specified database";

            var connection = command.Argument(
                "[connection]",
                "The connection string of the database");
            var provider = command.Argument(
                "[provider]",
                "The provider to use. For example, Microsoft.EntityFrameworkCore.SqlServer");

            var dataAnnotations = command.Option(
                "-a|--data-annotations",
                "Use DataAnnotation attributes to configure the model where possible. If omitted, the output code will use only the fluent API.",
                CommandOptionType.NoValue);
            var context = command.Option(
                "-c|--context <name>",
                "Name of the generated DbContext class.");
            var force = command.Option(
                "-f|--force",
                "Force scaffolding to overwrite existing files. Otherwise, the code will only proceed if no output files would be overwritten.",
                CommandOptionType.NoValue);
            var outputDir = command.Option(
                "-o|--output-dir <path>",
                "Directory of the project where the classes should be output. If omitted, the top-level project directory is used.");
            var schemas = command.Option(
                "--schema <schema>",
                "Selects a schema for which to generate classes.",
                CommandOptionType.MultipleValue);
            var tables = command.Option(
                "-t|--table <schema.table>",
                "Selects a table for which to generate classes.",
                CommandOptionType.MultipleValue);
            var environment = command.Option(
                "-e|--environment <environment>",
                "The environment to use. If omitted, \"Development\" is used.");

            command.HelpOption();
            command.VerboseOption();

            command.OnExecute(
                () =>
            {
                if (string.IsNullOrEmpty(connection.Value))
                {
                    ConsoleCommandLogger.Error(("Missing required argument '" + connection.Name + "'").Bold().Red());
                    command.ShowHelp();

                    return(Task.FromResult(1));
                }
                if (string.IsNullOrEmpty(provider.Value))
                {
                    ConsoleCommandLogger.Error(("Missing required argument '" + provider.Name + "'").Bold().Red());
                    command.ShowHelp();

                    return(Task.FromResult(1));
                }

                return(ExecuteAsync(commonOptions.Value(),
                                    connection.Value,
                                    provider.Value,
                                    dataAnnotations.HasValue(),
                                    context.Value(),
                                    force.HasValue(),
                                    outputDir.Value(),
                                    schemas.Values,
                                    tables.Values,
                                    environment.Value()));
            });
        }