Skip to content

feat: Launch selected Godot version straight from the CLI! - #108

Draft
TheDevRatt wants to merge 1 commit into
chickensoft-games:mainfrom
TheDevRatt:feat/godot-launch-command
Draft

feat: Launch selected Godot version straight from the CLI!#108
TheDevRatt wants to merge 1 commit into
chickensoft-games:mainfrom
TheDevRatt:feat/godot-launch-command

Conversation

@TheDevRatt

Copy link
Copy Markdown
Member

Heya! This is a dual Issue/Feature for GodotEnv. SymLinks aren't working the way they're supposed to on Windows, so I decided (as an avid hater of shortcuts on my beautiful wallpaper) to include a new function inside of the cli that lets you launch your selected Godot version.

I included also, a "detached" mode in the process runner so that after launching the terminal doesn't just sit and wait around due to the application being launched.

This launches the Godot executable based on the environment variable, I've only tested this on windows - but I'm fairly certain Mac and Linux should work as well. Also, I wrote a test to ensure that the command works although it gave me a LOT of headaches and I had to rely pretty heavily on AI for the test specifically, so if something doesn't look right there, that is likely why.

Let me know what you think!

@TheDevRatt TheDevRatt changed the title Feat: Launch selected Godot version straight from the CLI! feat: Launch selected Godot version straight from the CLI! Mar 27, 2025

@wlsnmrk wlsnmrk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! I've provided some suggestions and comments.

}

[Fact]
public async Task Launches_Godot_When_Env_Variable_Is_Valid() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test names in Chickensoft projects are usually just PascalCase, with no underscores.

}

[Fact]
public async Task Fails_When_GODOT_Target_Does_Not_Exist() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the underscores, I'd suggest using EnvVariable or something in place of GODOT -- all-caps isn't preferred, but PascalCase could lead to confusion between Godot itself and the environment variable.

public async ValueTask ExecuteAsync(IConsole console) {
var log = ExecutionContext.CreateLog(console);

string? godotPath = Environment.GetEnvironmentVariable("GODOT");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this, I would suggest we wait til #101 is merged and then do:

Suggested change
string? godotPath = Environment.GetEnvironmentVariable("GODOT");
var godotRepo = ExecutionContext.Godot.GodotRepo;
var godotPath = godotRepo.GodotSymlinkTarget;

And then update tests to match. (The reason to wait on #101 is that GodotSymlinkTarget is broken on Windows until that's in.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this change, why should we reference the SymLink and not the environment variable directly? It was my understanding after speaking with @jolexxa that we should reference off of the EnvVariable?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, okay. Wait for @jolexxa to weigh in, but in terms of my rationale:

  1. The environment variable should be pointing to the symlink. (If it isn't, the user's system is configured in a way that's incompatible with GodotEnv.) Given that, we may as well use the symlink directly, instead of referring to the environment variable that's referring to the symlink.
  2. If the user is launching from CLI with GodotEnv, they should expect GodotEnv to behave in a way that's consistent with the rest of its behavior. Unless I've missed something, there are relatively few places in the codebase where GodotEnv actually uses the GODOT environment variable; it sets it and will print it on the user's request, but that's about it. On the other hand, the GodotRepository uses the symlink location and target for managing the installations, changing the environment variable, and updating the start menu/desktop shortcuts. So all in all, I think it's more consistent with the rest of GodotEnv's behavior to use the symlink here too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheDevRatt what Mark said, essentially. The env var is for the user to launch Godot via the symlink and for use in vscode launch configs or any other scripts that need to point to Godot. Since we are managing the symlink, we can just access it directly.

string? godotPath = Environment.GetEnvironmentVariable("GODOT");

if (string.IsNullOrWhiteSpace(godotPath)) {
log.Err("❌ The GODOT environment variable is not set.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think (not 100% sure) that @jolexxa has "removing emoji from the output" on her roadmap for GodotEnv, so we may not want to add new ones. Maybe she can confirm if I'm remembering that correctly, though.

Comment on lines +35 to +37
if (SystemInfo.OS == OSType.Windows && !godotPath.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) {
godotPath += ".exe";
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here again I'd suggest waiting for #101 - this will also be handled by GodotRepository.GodotSymlinkTarget once that's merged, so we won't need this block at all.

}

log.Print($"🚀 Launching Godot from {godotPath}...");
await ExecutionContext.Godot.GodotRepo.ProcessRunner.RunDetached(godotPath, []);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await ExecutionContext.Godot.GodotRepo.ProcessRunner.RunDetached(godotPath, []);
var computer = ExecutionContext.Godot.Platform.Computer;
var shell = computer.CreateShell(ExecutionContext.WorkingDir);
shell.RunDetached(godotPath, []);

This suggestion will require implementing Shell.RunDetached(string executable, string[] args) and adding it to IShell.

@TheDevRatt
TheDevRatt marked this pull request as draft April 1, 2025 21:56
@TheDevRatt

Copy link
Copy Markdown
Member Author

Converted to draft while I wait on #101.

@wlsnmrk

wlsnmrk commented Apr 8, 2025

Copy link
Copy Markdown
Contributor

@TheDevRatt just wanted to let you know that #101 has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants