-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
[WIP] Add command parser #26213
[WIP] Add command parser #26213
Conversation
Didn't read the description, I guess this is still WIP. This is great any ways and it would be great if the main |
I'm adding a [WIP] to the title of the PR so it is more clear. |
Nice work! 🙂 If that makes sense, would it be possible to expose the command-line parsing interface to GDScript so that it can be used directly in projects? I can see it being useful to quickly jump to a specific level in a game (or similar). |
@Calinou I'll leave the potential GDScript API for a future issue so it can be debated. It would require some minor tweaks in the parser. @neikeq having the modules register their commands would be ideal but I'm a little lost about how it could be done as it would require the registration to be ready early on |
Hmm, It's indeed not that simple since command line is parsed before calling |
e189ed6
to
bfc00a1
Compare
2df7dcb
to
0f8b691
Compare
I've exposed the argument check functions so they can be reused when the command registration in modules is implemented. |
Ok so this is ready for testing. The get_cmdline_args thing still needs feedback. Once this is merged I'll start working on the PR so godot modules can register their commands in the parser. |
@akien-mga I'm reworking this PR based on the feedback of the proposal and this issue and I'm adapting the code I didn't touch in the actual state of the PR (for example the usage of cmdline in the engine tests) I have a doubt about a check condition you implemented: godot/main/tests/test_math.cpp Lines 489 to 496 in 5ca7460
What should that |
I also think this PR should be moved to the 4.0 milestone. |
Yeah that's 4.0 material indeed, I just didn't want to change milestone before taking time to review any of the proposed changes... But time is scarce :) I fully support the idea to refactor our command line interface as it's currently very limited and unforgiving. Haven't checked this PR's code yet so I can't comment on the implementation, but it's likely going in the right direction :)
I didn't implement this test, I only fixed up some issues. I also have no clue about what kind of files is expected here, but I guess it used to be a custom GDScript file with some math stuff to evaluate. These tests are also obsolete and will be replaced in the future, so I wouldn't bother too much about the |
I think I'll need to change the cmdline from |
1723a4e
to
5484323
Compare
@lupoDharkael The majority of the core refactoring work done by the core devs is finished, so anytime soon would be a good time to rebase this. |
I was waiting because I expected a lot of things to be changed not knowing when will this be considered to be reviewed more in depth. |
Requesting rebase. |
Oh I forgot about this one. I'll try to find time to resume this PR |
@lupoDharkael, are you still interested in it? Maybe some of us can just pick this PR and continue working on it? |
I don't know if I'll be able to resume this work soon as I have university exams and other stuff going on. I wouldn't mind If someone would like to continue my work. |
No problem. Could you briefly provide a description of what is already done (architecture, maybe how it works is short) and what needs to be completed? |
My first comment in this PR contains a very basic overview of the parser but I'll try to describe everything better.
CommandFlagEvery object of this type contains the information of a command. CommandParserHere is a breakdown of the member variables of the class:
The parse()This function is concise and I think this doesn't need very much explanation, it does the following:
Considerations
|
Thank you a lot! I will try. Should I open another PR or or will you add me as a contributor to your fork? |
I think it would be better to open a new one as this has a lot of comments already and it makes navigation through the feedback a bit harder. |
I think it's better to take this PR as a reference for implementation, if you attempt to rebase the branch to resolve conflicts then it's easy to miss out potential fixes and enhancements made to |
It's a lot of work to adapt main.cpp |
The changes on: |
Thanks for the tips. Almost a year has passed and there was a lot of commits related to
I noticed that |
This PR only receives a single argument as that's how it was when I wrote it.
this change also affects |
Thank you! |
Still working on it. I refactored code a lot, improved error checking, added usage generation, support for positional arguments (it's better to support it instead of manually checking for scene / script), multiply arguments, default values, required arguments, compound arguments ( |
That was fast :) |
I decided to add a couple of additional features before posting :) Finally finished: #44594. |
Port of godotengine/godot#26213 to Godot 3.x. Co-authored-by: Shatur95 <[email protected]> Co-authored-by: lupoDharkael <[email protected]>
Initial work for #20000
Proposal: godotengine/godot-proposals#137
The parser is pretty simple. We have the class
CommandFlag
which represents a single commands and its properties (the code is self explanatory). The classCommandParser
contains the list ofCommandFlag
and process the arguments in theparse
method.The method
init_defaults
adds all the commands of the engine.With a centralised point with all the data of the commands the --help can be generated dynamically. This has some advantages such as proper alignment of descriptions based on the largest line, and even splitting the lines if they exceed the 80 characters.
Engine arguments and project arguments are separated by a -- as it was suggested in the issue:
godot --godot-command -- project-command 333 4
TODO:
CommandFlag
checkers from gdscript.