public static void Run(string buildSolutionDirectory, IFileSystem fileSystem) { try { var promptResponse = RunPrompt(); var templateString = GetExampleDomain(promptResponse.name, promptResponse.type); var domainProject = FileParsingHelper.ReadYamlString <DomainProject>(templateString); var domainDirectory = $"{buildSolutionDirectory}{Path.DirectorySeparatorChar}{domainProject.DomainName}"; NewDomainProjectCommand.CreateNewDomainProject(domainDirectory, fileSystem, domainProject); ExampleTemplateBuilder.CreateYamlFile(domainDirectory, templateString, fileSystem); AnsiConsole.MarkupLine($"{Environment.NewLine}[bold yellow1]Your example project is project is ready![/]"); StarGithubRequest(); } catch (Exception e) { if (e is FileAlreadyExistsException || e is DirectoryAlreadyExistsException || e is InvalidSolutionNameException || e is FileNotFoundException || e is InvalidDbProviderException || e is InvalidFileTypeException || e is DataValidationErrorException || e is SolutiuonNameEntityMatchException) { WriteError($"{e.Message}"); } else { AnsiConsole.WriteException(e, new ExceptionSettings { Format = ExceptionFormats.ShortenEverything | ExceptionFormats.ShowLinks, Style = new ExceptionStyle { Exception = new Style().Foreground(Color.Grey), Message = new Style().Foreground(Color.White), NonEmphasized = new Style().Foreground(Color.Cornsilk1), Parenthesis = new Style().Foreground(Color.Cornsilk1), Method = new Style().Foreground(Color.Red), ParameterName = new Style().Foreground(Color.Cornsilk1), ParameterType = new Style().Foreground(Color.Red), Path = new Style().Foreground(Color.Red), LineNumber = new Style().Foreground(Color.Cornsilk1), } }); } } }
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(); }
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); } }