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

Add --init cli argument to create new projects #25925

Closed
wants to merge 1 commit into from

Conversation

lupoDharkael
Copy link
Contributor

Solves #25797

I works as git init but you have to pass the name of the project as an argument. I creates project.godot, icon.png and default_env.tres in the directory you call this command.

main/main.cpp Outdated Show resolved Hide resolved
@Calinou
Copy link
Member

Calinou commented Feb 16, 2019

I wonder if the directory should be created by passing --init <path to new directory> instead. This way, people don't have to cd around if they want to create several projects at once. The project name could be inferred and capitalized from the last path fragment (e.g. creating a project in /tmp/my_game would automatically call it "My Game", using the same logic as properties when they're displayed by the editor).

@lupoDharkael
Copy link
Contributor Author

@Calinou yeah I though about it. The problem is the name of the folder doesn't have to be the same as the name of the project.
Maybe --init <project name> <path> and the path being an optional argument. But I don't know how could I indicate an optional argument in the --help.

@bojidar-bg
Copy link
Contributor

Optional arguments are usually indicated using [], so --init <project name> [<path>]

@lupoDharkael
Copy link
Contributor Author

Ok, I'm adding the optional path.

@lupoDharkael
Copy link
Contributor Author

It is ready now.

Copy link
Member

@hpvb hpvb left a comment

Choose a reason for hiding this comment

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

I think this needs some work. I don't think it's a good idea to hardcode the contents of these files. Godot already does something when saving a project for the first time, that is what it should do in this case also.

default_env_str += "[resource]\n";
default_env_str += "background_mode = 2\n";
default_env_str += "background_sky = SubResource( 1 )\n";
return default_env_str;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is the correct approach. This means that if we change anything in the 'real' default environment we now have to change it in two places. This should serialize a normal default environment instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just moved the code from project_manager.cpp as it was.
See:

f->store_line("[gd_resource type=\"Environment\" load_steps=2 format=2]");
f->store_line("[sub_resource type=\"ProceduralSky\" id=1]");
f->store_line("[resource]");
f->store_line("background_mode = 2");
f->store_line("background_sky = SubResource( 1 )");

Where can I find the default environment configuration?

Copy link
Contributor

Choose a reason for hiding this comment

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

I confirm that it was hard coded before, maybe default environment could be instanced and serialized to file that way?

@@ -276,6 +276,7 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print("\n");

OS::get_singleton()->print("Standalone tools:\n");
OS::get_singleton()->print(" -i, --init <name> [<path>] Create a new project.\n");
Copy link
Member

Choose a reason for hiding this comment

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

we already have a --path parameter. Should we reuse that instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would make it more semantic.
I wonder if we should have a CLI parser to validate input and format so we can separate that from the logic based on the content. The actual code handling the cli arguments feels a bit convoluted and hardcoded.
That would make easier to have proper error handling and not opening the editor when you pass an invalid argument.

Copy link
Member

@Calinou Calinou Feb 18, 2019

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, mixing godot -i test test and I don't really know which one is path and which one is project name, so seems logical...

To salvage the problem with whether it should create a folder by default, maybe this:
godot --init test --path (would this be empty?)

would allow to create project named test and making a directory for it, while
godot --init test --path .

would create a project inside current directory.

Or just omitting the path argument would force to create a folder named the same as project:
godot --init test

Copy link
Member

Choose a reason for hiding this comment

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

I agree that the --init command should not take an optional path argument.
It should also not default to creating a folder, unless the path given does not exist, in which .ase it should try to create it.

So:

// Create "test" project in current working directory
godot --init test
// Create "test" project in previously created "myfolder" directory
mkdir myfolder
godot --init test --path myfolder
// Create "test" project in myother/folder subdirectory, creating them as needed
godot --init test --path myother/folder

@Xrayez
Copy link
Contributor

Xrayez commented Apr 21, 2019

I tried this:
godot --init test test --editor

Expected to run editor after init, but nothing happens. Of course it would make more sense with --path argument:

godot --init test --path . --editor # create in current dir, name project as "test", run editor
godot --init test --editor # mkdir "test" automatically, name project as "test", run editor

@lupoDharkael
Copy link
Contributor Author

I'm waiting for #26213 to be reviewed and tested before I continue with this PR

@akien-mga akien-mga removed the request for review from reduz April 30, 2019 12:44
@@ -276,6 +276,7 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print("\n");

OS::get_singleton()->print("Standalone tools:\n");
OS::get_singleton()->print(" -i, --init <name> [<path>] Create a new project.\n");
Copy link
Member

Choose a reason for hiding this comment

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

This should be within #ifdef TOOLS_ENABLED (and same for the parsing of -i and --init).

@akien-mga
Copy link
Member

Moving to the next milestone as this PR still needs some work.

@akien-mga akien-mga modified the milestones: 3.2, 4.0 Oct 30, 2019
@aaronfranke aaronfranke marked this pull request as draft May 26, 2020 15:01
@aaronfranke
Copy link
Member

Since this PR depends on #26213, I will close this for now. It can be re-opened or re-created later.

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

Successfully merging this pull request may close these issues.

8 participants