-
Notifications
You must be signed in to change notification settings - Fork 38
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 --config-json-path to accept flags specified in a JSON file. #265
Conversation
12d0a8e
to
7fe93d3
Compare
Note: I tried to keep the input parameters for |
Arf, that's sad... What's sadder is it wasn't done to the unordered_map until c++20 😥 So this explains the lack of support, at least from the Android NDK. |
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.
Thanks for this!
A few things to fix, but overall OK.
The the JSON overriding flags, even when specified after, this is fine IMO. Complexity to manage the ordering is not yet justified. But it should be documented.
src/ppx/command_line_parser.cpp
Outdated
std::string value = ss.str(); | ||
ss.str(""); | ||
|
||
if (value.length() > 0 && value.substr(0, 1) == "[") { |
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 probably shouldn't parse the data again. What about using functions like it->is_array()
.
5ff18a9
to
f0a7a69
Compare
Thank you for the feedback, I've tried to address it and made two major changes:
|
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.
some optional suggestions, otherwise lgtm
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.
Forgot to send the review, sorry!
c4be397
to
8706bea
Compare
Note: This PR is not ready for submitting. To summarize the result of the discussion Nathan and I had about the ordering for list arrays, we decided that combining the contents of the JSON file and the commandline flags is confusing, so any time that a list flag is used on the command-line it will completely overwrite the value for that flag specified inside the JSON file. Detailed example:
|
android/linux builds * Make mAllOptions strings and not string_views * Make the functions that need to search mAllOptions take input parameters of const std::string& instead
* JSON file flags are lower priority than flags specified on the command line * Using JSON is_array and is_object functions * Using round bracket syntax for initalization * Fix Parse() function * Better error reporting for parsing the JSON file * Fixed flag description typo
* Rename pConfigJsonPath to pConfigJsonPaths * Change commandline parsing to 2 initial passes for better readability
8706bea
to
306397a
Compare
and command line flags to overwrite json files after that.
306397a
to
dc32011
Compare
This is ready for review/merging. I don't have unit tests for commandline VS JSON file priority but I did check it manually and it should behave as described in the previous comment. |
Add flag --config-json-path to accept commandline flags that are specified in a JSON file. This flag can be used multiple times. The priority of any conflicting flags is as follows:
later flag on commandline > earlier flag on commandline > flag in later JSON file > flag in earlier JSON file
For flags that accept multiple values, the same priority is used and only flags specified in the same JSON file or flags all on the commandline will be combined.
Detailed changes:
mAllOptions
to holdstrings
instead ofstring_views
since there are now temporary strings originating from the JSON structure, changed some input parameters forCliOptions
member functions to match.CommandLineParser
methods to aid in parsing options (these are public for unit testing purposes)ParseJson
ParseOption
CliOptions
AddOption
overload that accepts one key and a vector of values to reduce the time needed to insert arrays. This function is only used by the JSON parsing flow. On the command line the flag must still be specified multiple times (--flag-name 1,2,3
is still invalid)OverwriteOptions
CommandLineParser::Parse
mJsonConfigFlagName
toCommandLineParser
so that the stringconfig-json-path
isn't specified in multiple places