Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/MAG-51: Ask for generator #24

Merged
merged 3 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 63 additions & 4 deletions magnet/Source/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name>`.");
generator = "";
break;
default:
MG_LOG_HOST("Project Wizard", "Invalid answer.");
continue;
}

break;
}

break;
}
while (true);

CreateNewProject(project, generator);
}

void CommandHandler::HandleGenerateCommand(const CommandHandlerProps& props)
Expand Down Expand Up @@ -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...");

Expand Down Expand Up @@ -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 <name>` to generate project files.";
MG_LOG_HOST("Project Wizard", message);
return;
}

CommandHandlerProps props;
props.project = const_cast<Project*>(&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)
Expand Down
6 changes: 5 additions & 1 deletion magnet/Source/CommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace MG
std::vector<std::string> nextArguments;

friend class Application;
friend class CommandHandler;
};

// Responsible for handling all of Magnet's command logic.
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions magnet/Source/Platform/LinuxPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 + " ";
Expand Down
4 changes: 4 additions & 0 deletions magnet/Source/Platform/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
7 changes: 6 additions & 1 deletion magnet/Source/Platform/WindowsPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions magnet/Source/Platform/macOSPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 + " ";
Expand Down