Skip to content

Optparse option aliases #705

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

Merged
merged 14 commits into from
May 27, 2025
Merged

Conversation

Curtis-Barnhart
Copy link
Contributor

#667 describes a regression where addons/gut/gut_cmdln.gd stopped recognizing the --script argument. This PR fixes this problem and also introduces argument aliases to the optparse system.
Any option can now be added with any number of aliases. Aliases will be checked to make sure they do not collide with other option names or aliases in the same way that option names are usually checked for collisions. An option's aliases will be printed out at the end of its help string.

@bitwes
Copy link
Owner

bitwes commented Apr 24, 2025

I've been wanting this feature for a bit. This will be great to have.

find_custom is a 4.4 feature and GUT requires 4.3 (also I'm using 4.3 still). I don't think this is a big enough feature to require 4.4 but I understand not wanting to work in 4.3. So, please either:

  • Change the implementation to work in Godot 4.3
    or
  • Make the PR against the Godot 4.4 branch.

@Curtis-Barnhart
Copy link
Contributor Author

Oh dear silly me. Probably should've thought about that first. Here's a fixed version for 4.3.

@bitwes
Copy link
Owner

bitwes commented May 17, 2025

Sorry for the delay. I checked this out a bit then got distracted with Godotcon. This works, but I think I would like the following changes:

  • Change the handling of op_name in the add function to handle a string value or an array.
  • When it is a string, you get a an option without an aliases.
  • When it is an array, then every value after the first is an alias.

This allows us to keep all the option names together which is easier to read. In my experience it is rare that you would want more than one alias for an option (I can't think of an example off the top of my head). By putting the optional array at the front, we can still support more aliases but don't have to use a single element array in usual use case.

This would change the usage to something like:

op.add("--name", "default", "description")
op.add(["--name", "-n"], "default", "description")
op.add(["--name", "--nombre", "--namna", "-n"], "default", "description")

@Curtis-Barnhart
Copy link
Contributor Author

Okay, it's been updated to have the specified behavior. I also added type hints and docstrings to all the user facing methods and rebuilt the class reference docs for them.

@bitwes
Copy link
Owner

bitwes commented May 27, 2025

This looks good. Thanks a lot for adding this.

@bitwes bitwes merged commit 9494bb7 into bitwes:main May 27, 2025
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.

2 participants