-
Notifications
You must be signed in to change notification settings - Fork 124
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
Introduce ArgumentConfigSource #290
Conversation
It looks like Other requirements that should be considered:
I don't think these requirements are possible to solve, without providing metadata to the config source that defines exactly what arguments are expected and what their form and behavior is expected to be. |
0786eec
to
3ab9cc8
Compare
I reworded the commit message and added the missing test. I am not sure if a previous metadata is really needed, since we only care about the provided arguments and not if they are required or malformed, etc (input validation is out of scope of the ConfigSource implementation IMHO). About multiple values, isn't enough to return a comma-separated list of values (then the Converter would kick in to convert to the appropriate type)? |
0caf1a1
to
a245c29
Compare
Whether or not I agree that input validation is out of scope for ConfigSources (I don't BTW - consider that properties and YAML files must be well formed, for example), the config source still must make input validation at least be possible. That means at the very least the consuming party has to know which configuration properties were command line arguments, and possibly what order they occurred in. Arguments appearing multiple times need handling as well. At a point, the user is obligated to know so much special information about the fact that they are command line arguments rather than "regular" config, that having a config source hardly seems worth it, unless that all can be made transparent, similarly to how the classic static struct option long_options[] = {
{"add", required_argument, 0, 0 },
{"append", no_argument, 0, 0 },
{"delete", required_argument, 0, 0 },
{"verbose", no_argument, 0, 0 },
{"create", required_argument, 0, 'c'},
{"file", required_argument, 0, 0 },
{0, 0, 0, 0 }
};
c = getopt_long(argc, argv, "abc:d:012",
long_options, &option_index); This is enough to determine that the arguments and their values are well-formed, yet still allowing validation to happen at a later point. For SmallRye Config I'd take the above example one step farther, to be able to say things like:
...and so on like that. The well-formedness can be verified immediately by the config source, just like it is for YAML and friends. But both the validation piece and the detection of required-but-empty piece can then be handled cleanly by all the existing frameworks/mechanisms we have in place in Quarkus, and eventually will have in SmallRye Config, with no modifications.
Properly quoted, yes, that is how it would need to be done. But in order to know whether to quote the values, you have to know whether it's a list or not going in, otherwise list values will behave incorrectly when parsed as non-lists and vice versa, and it will also be impossible to detect whether an argument was illegally given more than once (as opposed to innocently containing a valid comma for example) after the fact of parsing. |
- Supports --arg-name=foo,--arg-name foo, -a, -a b and -a=b - Short arguments with no value should be supported corresponding to boolean properties e.g. -x - Supports multiple values (--foo=1 --foo=2 --foo=3)
I see. Do you have any preferred parser/library that would also perform this metadata validation? |
No, I would devise a builder API for the config source to specify the necessary information. Using POSIX and GNU as a guide, I'd start with the following requirements:
For reference & ideas: https://linux.die.net/man/3/getopt_long Future requirements:
|
I found the library that does what you're looking for: http://jopt-simple.github.io/jopt-simple/examples.html (it's the same used in OpenJDK). I'll close this PR and come up with a hopefully better solution |
This should check one of the boxes in quarkusio/quarkus#6497
cc @dmlloyd