-
Notifications
You must be signed in to change notification settings - Fork 18
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 command-line parser #123
Merged
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
d7d64e2
Add command-line parser
Xrayez c2fc422
Remove override keywords in `CommandLineParser`
Xrayez c7ff6ab
Fix shadowed variable when comparing option names
Xrayez 6f8d80a
Formatting and style changes to `CommandLineParser`
Xrayez e10edfd
Fix typo in `get_occurrence_count` in `CommandLineParser`
Xrayez 416d1e2
Documentation fixes for command-line parser related classes
Xrayez 807c142
Rename `parse_args` to `parse` in `CommandLineParser`
Xrayez 4fe0eb3
Add `CommandLineParser` test suite
Xrayez 02d8645
Rename `get_error()` to `get_error_text()` in `CommandLineParser`
Xrayez 7be1c72
Add test cases for `CommandLineParser`
Xrayez df0a2b3
Rename more method in `CommandLineParser`
Xrayez db474d3
Add short option and positional test cases in `CommandLineParser`
Xrayez d074e05
Remove dead code related to checkers in `CommandLineParser`
Xrayez 9c02f16
Make help format parameter optional in `CommandLineParser.get_help_te…
Xrayez e0f102a
Move one-line implementation to declaration in `CommandLineParser`
Xrayez 66e37de
Update docs for `CommandLineParser`
Xrayez 7141f6e
Use `ERR_PARSE_ERROR` for `CommandLineParser`
Xrayez 8b01b14
Merge `validate()` into `parse()` in `CommandLineParser`
Xrayez dcf414e
Add `new_option()` to `CommandLineParser`
Xrayez d6cb740
Change getter names to follow naming conventions in command line parser
Xrayez 1a0fa2d
Use `index` over `idx` for CLI option arguments
Xrayez 093b4d2
Declare `CommandLineParser` dependencies
Xrayez 76a7e5c
Add more test cases for command line parser
Xrayez b66bbef
Rename `add_option()` to `append_option()`, `new_option()` to `add_op…
Xrayez 05f4b44
Fix usage example of command-line parser
Xrayez 1b77d73
Further improve docs for command-line parser
Xrayez b05da1d
Add prefix test cases for command-line parser
Xrayez 514d73b
Fix `ParsedPrefix.is_exists()` name
Xrayez ff7ee37
Add important TODOs for Godot 4.0 regarding command-line parser
Xrayez 1a41e9d
Add utility methods for `CommandLineOption`
Xrayez 2eeadba
Validate disallowed default arguments in `CommandLineOption`
Xrayez 8e4595c
Add test case for unrecognized options
Xrayez 558dd3d
Move some variable closer to use in command-line parser
Xrayez 37b7478
Mark `help` and `version` as special meta options
Xrayez f539979
Make sure meta option was parsed on the command-line
Xrayez a4859a6
Expose `meta` property in `CommandLineOption`
Xrayez 20d3a30
Add positional options test case for command-line parser
Xrayez 90ea98a
Simplify implementation of `CommandLineParser.add_option()` method
Xrayez 9340536
Fix precedence of long prefix parsing in `CommandLineParser`
Xrayez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will not able to define a help method and required arguments without
validate
. This is how it done in other parsers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't removed validation code, but merged it at the end of
parse()
, also renamedvalidated
signal toparsed
for options, so more consolidation. As a user, I still don't quite get the usefulness of this to be honest. Could you elaborate?The validation doesn't look any much different from validation done in
parse()
to me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I understand. But without this separation, if you declare a
help
command and mark some other command as required, the help command will not work because it will fail on required check.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this separation you can check for the help / version commands first and then call
validate
to check if other arguments are valid.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, yeah I understand this now. But is it only useful for
help
/version
options, or are there other use cases where this separation may be required?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the text will be hardcoded :)
Then options will have a switch (maybe internal) to skip validation as I mentioned before.
As to me this behavior (with automatic validation skip) will be less obvious then a direct call to detect required variables (e.g.
validate
). But it just me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've personally never used
Boost.program_options
, but I did use Python'sargparse
. There, if you define an option which isrequired=True
, then somehow it still allows to parse--help
and it prints a message, so I assume Python does have an internal mechanism to handle such cases. Godot users are more familiar with Python, so I think we should go with this approach.Also, according to
argparse.required
documentation:So having API which allows to explicitly validate frowned upon approach for defining options might not be a good idea.
As I said,
parse()
already does a lot of validation checks for options/arguments prior tovalidate()
(see various internal_validate_*
methods), so it's also not 100% clear which checks are purely user-facing to make a better distinction, those that simply set_error_text
or justERR_FAIL_*
(incorrect usage of command-line parser itself).I'd personally like to keep API simpler if there's a possibility to make it simpler without losing functionality. If users say that
validate()
is needed, it could be added in future versions without breaking compatibility, I guess.I think this is the way to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... This makes.
On second thought a command option to skip validation if the command is specified not that bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added ability to mark options as "meta", see recent commits. Options that are meta are designed to get information about application itself, so if any such option is detected on the command-line, there's no need to check for required options, because meta options are not designed to interact with user options.
I haven't exposed it as a property, should probably stay internal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
I would allow user to set it, cost nothing, but it's up to you.