Пример #1
0
        public void Run(string[] args)
        {
            var myEnv = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            if (args.Length == 0)
            {
                ListCommand.Run();
                return;
            }

            if (args[0] == "list" || args[0] == "-h" || args[0] == "--help")
            {
                ListCommand.Run();
                return;
            }

            if (args.Length == 2 && (args[0] == "new:api" || args[0] == "new:webapi"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    NewApiCommand.Help();
                }
                else
                {
                    var solutionDir = myEnv == "Dev" ? fileSystem.Path.Combine(@"C:", "Users", "Paul", "Documents", "testoutput") : fileSystem.Directory.GetCurrentDirectory();
                    NewApiCommand.Run(filePath, solutionDir, fileSystem);
                }
            }

            if (args.Length == 2 && (args[0] == "new:micro"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    NewMicroCommand.Help();
                }
                else
                {
                    var solutionDir = myEnv == "Dev" ? fileSystem.Path.Combine(@"C:", "Users", "Paul", "Documents", "testoutput") : fileSystem.Directory.GetCurrentDirectory();
                    NewMicroCommand.Run(filePath, solutionDir, fileSystem);
                }
            }

            if (args.Length == 2 && (args[0] == "add:entity" || args[0] == "add:entities"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    AddEntityCommand.Help();
                }
                else
                {
                    var solutionDir = myEnv == "Dev" ? fileSystem.Path.Combine(@"C:", "Users", "Paul", "Documents", "testoutput", "Lab.Api") : fileSystem.Directory.GetCurrentDirectory();
                    AddEntityCommand.Run(filePath, solutionDir, fileSystem);
                }
            }

            if (args.Length > 1 && (args[0] == "add:property"))
            {
                if (args[1] == "-h" || args[1] == "--help")
                {
                    AddEntityPropertyCommand.Help();
                }
                else
                {
                    var entityName  = "";
                    var newProperty = new EntityProperty();
                    Parser.Default.ParseArguments <AddPropertyOptions>(args)
                    .WithParsed(options =>
                    {
                        entityName  = options.Entity.UppercaseFirstLetter();
                        newProperty = new EntityProperty()
                        {
                            Name               = options.Name,
                            Type               = options.Type,
                            CanFilter          = options.CanFilter,
                            CanSort            = options.CanSort,
                            ForeignKeyPropName = options.ForeignKeyPropName
                        };
                    });

                    var solutionDir = myEnv == "Dev" ? fileSystem.Path.Combine(@"C:", "Users", "Paul", "Documents", "testoutput") : fileSystem.Directory.GetCurrentDirectory();
                    AddEntityPropertyCommand.Run(solutionDir, entityName, newProperty);
                }
            }
        }
Пример #2
0
        public void Run(string[] args)
        {
            var myEnv = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            if (args.Length == 0)
            {
                ListCommand.Run();
                return;
            }

            if (args[0] == "version" || args[0] == "--version")
            {
                WriteHelpHeader($"v{typeof(ProcessCommand).Assembly.GetName().Version}");
                return;
            }

            if (args[0] == "list" || args[0] == "-h" || args[0] == "--help")
            {
                ListCommand.Run();
                return;
            }

            if (args.Length == 2 && (args[0] == "new:api"))
            {
                WriteHelpHeader($"This command has been depricated. If you'd like to create a new project, use the `new:domain` command. If you want to add a new bounded context to an existing project, use the `add:bc` command. Run `craftsman list` for a full list of commands.");
            }

            if (args.Length >= 2 && (args[0] == "add:bc" || args[0] == "add:boundedcontext"))
            {
                var filePath  = args[1];
                var verbosity = GetVerbosityFromArgs <AddBcOptions>(args);

                if (filePath == "-h" || filePath == "--help")
                {
                    AddBoundedContextCommand.Help();
                }
                else
                {
                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }
                    AddBoundedContextCommand.Run(filePath, rootDir, fileSystem, verbosity);
                }
            }

            if (args.Length >= 2 && (args[0] == "new:domain"))
            {
                var filePath  = args[1];
                var verbosity = GetVerbosityFromArgs <AddBcOptions>(args);

                if (filePath == "-h" || filePath == "--help")
                {
                    AddBoundedContextCommand.Help();
                }
                else
                {
                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }
                    NewDomainProjectCommand.Run(filePath, rootDir, fileSystem, verbosity);
                }
            }

            if (args.Length == 2 && (args[0] == "add:entity" || args[0] == "add:entities"))
            {
                var filePath  = args[1];
                var verbosity = GetVerbosityFromArgs <AddEntityOptions>(args);

                if (filePath == "-h" || filePath == "--help")
                {
                    AddEntityCommand.Help();
                }
                else
                {
                    var solutionDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the solution directory.");
                        solutionDir = Console.ReadLine();
                    }

                    AddEntityCommand.Run(filePath, solutionDir, fileSystem, verbosity);
                }
            }

            if (args.Length > 1 && (args[0] == "add:property" || args[0] == "add:prop"))
            {
                if (args[1] == "-h" || args[1] == "--help")
                {
                    AddEntityPropertyCommand.Help();
                }
                else
                {
                    var entityName  = "";
                    var newProperty = new EntityProperty();
                    Parser.Default.ParseArguments <AddPropertyOptions>(args)
                    .WithParsed(options =>
                    {
                        entityName  = options.Entity.UppercaseFirstLetter();
                        newProperty = new EntityProperty()
                        {
                            Name               = options.Name,
                            Type               = options.Type,
                            CanFilter          = options.CanFilter,
                            CanSort            = options.CanSort,
                            ForeignKeyPropName = options.ForeignKeyPropName
                        };
                    });

                    var solutionDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the solution directory.");
                        solutionDir = Console.ReadLine();
                    }
                    AddEntityPropertyCommand.Run(solutionDir, entityName, newProperty);
                }
            }

            CheckForLatestVersion();
        }
Пример #3
0
        public void Run(string[] args)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                // this makes emojis come up more reliably. might get built into spectre better in the future, so give a go deleting this at some point
                // they seem to show up fine on osx and actually need this to be off to work there
                Console.OutputEncoding = Encoding.Unicode;
            }

            var myEnv = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            if (args.Length == 0)
            {
                ListCommand.Run();
                CheckForLatestVersion();
                return;
            }

            if (args[0] == "version" || args[0] == "--version")
            {
                WriteInfo($"v{GetInstalledCraftsmanVersion()}");
                CheckForLatestVersion();
                return;
            }

            if (args[0] == "list" || args[0] == "-h" || args[0] == "--help")
            {
                ListCommand.Run();
                CheckForLatestVersion();
                return;
            }

            if (args.Length >= 2 && (args[0] == "add:bc" || args[0] == "add:boundedcontext"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    AddBoundedContextCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();
                    var verbosity = GetVerbosityFromArgs <AddBcOptions>(args);

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }
                    AddBoundedContextCommand.Run(filePath, rootDir, fileSystem, verbosity);
                }
            }

            if (args.Length >= 2 && (args[0] == "add:authserver"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    AddAuthServerCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }
                    AddAuthServerCommand.Run(filePath, rootDir, fileSystem);
                }
            }

            if (args.Length >= 2 && (args[0] == "new:domain"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    NewDomainProjectCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();
                    var verbosity = GetVerbosityFromArgs <NewDomainOptions>(args);

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }
                    NewDomainProjectCommand.Run(filePath, rootDir, fileSystem, verbosity);
                }
            }

            if ((args[0] == "new:example" || args[0] == "example"))
            {
                if (args.Length > 1 && (args[1] == "-h" || args[1] == "--help"))
                {
                    NewExampleCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }
                    NewExampleCommand.Run(rootDir, fileSystem);
                }
            }

            if (args[0] == "register:producer")
            {
                if (args.Length > 1 && (args[1] == "-h" || args[1] == "--help"))
                {
                    RegisterProducerCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }
                    RegisterProducerCommand.Run(rootDir, fileSystem);
                }
            }

            if (args.Length == 2 && (args[0] == "add:entity" || args[0] == "add:entities"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    AddEntityCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();
                    var verbosity = GetVerbosityFromArgs <AddEntityOptions>(args);

                    var solutionDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the solution directory.");
                        solutionDir = Console.ReadLine();
                    }

                    AddEntityCommand.Run(filePath, solutionDir, fileSystem, verbosity);
                }
            }

            if ((args[0] == "add:bus"))
            {
                var filePath = "";
                if (args.Length >= 2)
                {
                    filePath = args[1];
                }

                if (filePath == "-h" || filePath == "--help")
                {
                    AddBusCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }

                    AddBusCommand.Run(filePath, rootDir, fileSystem);
                }
            }

            if ((args[0] == "add:message"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    AddMessageCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }

                    AddMessageCommand.Run(filePath, rootDir, fileSystem);
                }
            }

            if ((args[0] == "add:consumer" || args[0] == "add:consumers"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    AddConsumerCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }

                    AddConsumerCommand.Run(filePath, rootDir, fileSystem);
                }
            }

            if ((args[0] == "add:producer" || args[0] == "add:producers"))
            {
                var filePath = args[1];
                if (filePath == "-h" || filePath == "--help")
                {
                    AddProducerCommand.Help();
                }
                else
                {
                    CheckForLatestVersion();

                    var rootDir = fileSystem.Directory.GetCurrentDirectory();
                    if (myEnv == "Dev")
                    {
                        Console.WriteLine("Enter the root directory.");
                        rootDir = Console.ReadLine();
                    }

                    AddProducerCommand.Run(filePath, rootDir, fileSystem);
                }
            }

            if (args[0] == "add:feature" || args[0] == "new:feature")
            {
                if (args.Length > 1)
                {
                    var filePath = args[1];
                    if (filePath is "-h" or "--help")
                    {
                        AddFeatureCommand.Help();
                    }

                    return;
                }

                CheckForLatestVersion();

                var rootDir = fileSystem.Directory.GetCurrentDirectory();
                if (myEnv == "Dev")
                {
                    Console.WriteLine("Enter the root directory.");
                    rootDir = Console.ReadLine();
                }
                AddFeatureCommand.Run(rootDir, fileSystem);
            }
        }