-
Notifications
You must be signed in to change notification settings - Fork 14
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
Can a command's default arguments be loaded from config yaml? #24
Comments
I think there's a discussion about this somewhere, but I can't recall where. The issue with default options is that it is non-ambiguous how to override the defaults. For arguments, it's not so clear. This feature could potentially be provided if there was a clear definition of how it should work. |
That's an excellent point, it sounds like a challenging problem to solve. Just thinking out loud a bit here, trying to work through the problem space... Case 0: command w/ a single required argument, no default provided.Nothing special here; the command execution fails with error message about missing argument, unless there is an argument present on the command line. Case 1: command w/ a single required argument, default provided in config.ymlThe default argument is loaded from config unless there is an argument present on the command line.
Case 2: command w/ two required arguments, second argument has a default in config.ymlIt seems exceedingly rare that you'd ever design something with two arguments where the first argument is variable, and the second argument has a default. But anyway, to handle this, config.yml would need to use a keyed index to know which of the two arguments you're providing a default for.
Case 3: command w/ two required arguments, first argument has a default in config.ymlThings fall apart here. There is absolutely no way for the end user to specify a second (or third or forth) argument without also providing (and therefore overriding) the first default argument that was stored in code. The only time this would work is if arguments 2 and 3 were not required and the end user didnt provide any arguments, would the default argument 1 be picked up from the config file. Case 4: command w/ two required arguments, both have defaults in config.ymlSimilar to case 3, this falls apart as soon as the developer wants to override the second argument on the command line. You can't do that unless you override both arguments. To support case four, we wouldn't necessarily need indexed items like case 2, and would only need something similar to case 1
Maybe if case 3 and 4 are just documented as inherent limitations, this could be coded, and it would work for the vast majority of cases. did I miss any cases? |
Case 3 we can definitely say is not supported -- as with programming languages, you must provide defaults from right to left. Case 4 we can also dispense with. Can we handle cases where the command takes variable arguments (e.g. |
Good question, I don't see why not... so: Case 5: command w/ variable number of arguments, any number of which have defaults in config.ymlThis is mostly just an extension of case 1 and case 4, whereby the assumption is that the commands would need to be defined top-to-bottom in yaml list format (similar to left-to-right on command line).
I thought of another case that might need thinking about -- maybe it would be ok though: Case 6: default arguments placed in command groupFor functional parity with how options can be placed up-the-chain inside the command group and inherited downward to all commands, I wonder how this would work for arguments. For instance (from the example below): A) would my:foo override argumentA with argumentC and inherit argumentB (this is similar in theory to how option inheritance works) OR B) would the fact that the child command implements
|
Did you mean left to right? |
Oh wait. I think i get you -- right to left:
Not sure how that translates into the defaults in YAML though. I'm getting confused 😟 |
In programming languages, you must define default arguments from right to left, is what I meant. Argument n-1 cannot have a default value unless argument n has a default value. You must provide arguments (overriding defaults, if any) from left to right. |
Hi Greg,
Given the following CLI command:
I know this package helps to read the command's default options from config.yml like this:
But is it possible to store the default arguments in yaml? I couldn't find any documentation or examples of how to do this.
The text was updated successfully, but these errors were encountered: