diff --git a/magnet/Source/CommandHandler.cpp b/magnet/Source/CommandHandler.cpp index 0774845..c132e2d 100644 --- a/magnet/Source/CommandHandler.cpp +++ b/magnet/Source/CommandHandler.cpp @@ -135,7 +135,45 @@ namespace MG } while (true); - CreateNewProject(project); + std::cin.clear(); + + std::string generator = Platform::GetGenerator(); + + do + { + MG_LOG_HOST("Project Wizard", + generator + + " was detected as the default generator. Continue (1) or choose a different one later (2)?"); + Application::PrintPrompt(); + + std::string input; + std::getline(std::cin, input); + + if (!input.empty()) + { + switch (input[0]) + { + case '1': + MG_LOG_HOST("Project Wizard", "Continuing with default generator."); + break; + case '2': + MG_LOG_HOST("Project Wizard", + "Specify a different generator later by running `magnet generate -G `."); + generator = ""; + break; + default: + MG_LOG_HOST("Project Wizard", "Invalid answer."); + continue; + } + + break; + } + + break; + } + while (true); + + CreateNewProject(project, generator); } void CommandHandler::HandleGenerateCommand(const CommandHandlerProps& props) @@ -415,7 +453,7 @@ namespace MG return command == "new" || command == "help" || command == "version"; } - void CommandHandler::CreateNewProject(const Project& project) + void CommandHandler::CreateNewProject(const Project& project, const std::string& generator) { MG_LOG_HOST("Project Wizard", "Creating new C++ project..."); @@ -515,8 +553,29 @@ namespace MG return; } - MG_LOG_HOST("Project Wizard", name + " has been created.\nNext steps: `cd " + name + - " && magnet generate` to generate project files."); + std::string message = name + " has been created.\n"; + + if (generator.empty()) + { + message = "Next steps: `cd " + name + " && magnet generate -G ` to generate project files."; + MG_LOG_HOST("Project Wizard", message); + return; + } + + CommandHandlerProps props; + props.project = const_cast(&project); + props.nextArguments = { "-G" + generator }; + + // Move into the newly folder to perform Magnet commands. + std::filesystem::current_path(name); + + HandleGenerateCommand(props); + + props.nextArguments.clear(); + HandleBuildCommand(props); + + message = "Next steps: `cd " + name + " && magnet go` to launch your app."; + MG_LOG_HOST("Project Wizard", message); } bool CommandHandler::GenerateRootCMakeFile(const CommandHandlerProps& props) diff --git a/magnet/Source/CommandHandler.h b/magnet/Source/CommandHandler.h index aeee144..f7008f9 100644 --- a/magnet/Source/CommandHandler.h +++ b/magnet/Source/CommandHandler.h @@ -27,6 +27,7 @@ namespace MG std::vector nextArguments; friend class Application; + friend class CommandHandler; }; // Responsible for handling all of Magnet's command logic. @@ -49,10 +50,13 @@ namespace MG // Returns whether the given command is global, meaning it doesn't // require a project to be present. static bool IsCommandGlobal(const std::string& command); + private: // Creates a new project by initializing the template folder and // generating a unique config.yaml file inside the .magnet folder. - static void CreateNewProject(const Project& project); + // Immediately followed by generating all CMakeLists.txt files + // using the specified option and finally building the project. + static void CreateNewProject(const Project& project, const std::string& generator); // Creates a CMakeLists.txt file at the root of the project. static bool GenerateRootCMakeFile(const CommandHandlerProps& props); diff --git a/magnet/Source/Platform/LinuxPlatform.cpp b/magnet/Source/Platform/LinuxPlatform.cpp index a1459ec..1fe60df 100644 --- a/magnet/Source/Platform/LinuxPlatform.cpp +++ b/magnet/Source/Platform/LinuxPlatform.cpp @@ -34,6 +34,11 @@ namespace MG return p; } + std::string Platform::GetGenerator() + { + return "Ninja"; + } + std::string Platform::GetGenerateCommand(const std::string& configuration) { return "-DCMAKE_BUILD_TYPE=" + configuration + " "; diff --git a/magnet/Source/Platform/Platform.h b/magnet/Source/Platform/Platform.h index c302943..9b35d7d 100644 --- a/magnet/Source/Platform/Platform.h +++ b/magnet/Source/Platform/Platform.h @@ -10,9 +10,13 @@ namespace MG // Returns the real path to the executable. Does not include the executable name. static std::filesystem::path GetExecutablePath(); + // Returns the default generator for the current platform. + static std::string GetGenerator(); + // Returns the CMake generator command for the current platform. static std::string GetGenerateCommand(const std::string& configuration); + // Returns the command for launching the application. static std::string GetGoCommand(const std::string& appPath); }; } diff --git a/magnet/Source/Platform/WindowsPlatform.cpp b/magnet/Source/Platform/WindowsPlatform.cpp index d0e92aa..66fbd9b 100644 --- a/magnet/Source/Platform/WindowsPlatform.cpp +++ b/magnet/Source/Platform/WindowsPlatform.cpp @@ -21,9 +21,14 @@ namespace MG return p; } + std::string Platform::GetGenerator() + { + return "\"Visual Studio 17 2022\""; + } + std::string Platform::GetGenerateCommand([[maybe_unused]] const std::string& configuration) { - return "-G \"Visual Studio 17 2022\" -A x64"; + return "-A x64"; } std::string Platform::GetGoCommand(const std::string& appPath) diff --git a/magnet/Source/Platform/macOSPlatform.cpp b/magnet/Source/Platform/macOSPlatform.cpp index 72db555..3c61461 100644 --- a/magnet/Source/Platform/macOSPlatform.cpp +++ b/magnet/Source/Platform/macOSPlatform.cpp @@ -31,6 +31,11 @@ namespace MG return p; } + std::string Platform::GetGenerator() + { + return "Xcode"; + } + std::string Platform::GetGenerateCommand(const std::string& configuration) { return "-DCMAKE_BUILD_TYPE=" + configuration + " ";