-
Notifications
You must be signed in to change notification settings - Fork 71
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
default
should be evaluated lazily(by passing a provider function, for example)
#69
Comments
If I understood you correctly, you want to use default method inside your logic application. |
Same heading, different example. I have e.g.
I get
There should be some means for the default of
My specific usecase is with specifying a root directory and then having default sub-directories. |
@sifraser a bit late of an answer, but this usecase seems impossible to solve by kotlinx-cli, as it needs to be able to compute all default values before user input for the --help. Here's what I did for a close use case: val DEFAULT_SUB_TOKEN = "<root>/subdirectory"
val root by parser.argument(ArgType.String, "root")
val sub by parser.argument(ArgType.String, "sub")
.default(DEFAULT_SUB_TOKEN)
val subPolicy =
get() = when (sub) {
DEFAULT_SUB_TOKEN -> Relative
else -> Absolute(sub)
}
sealed interface SubPolicy {
object Relative
data class Absolute(val directoryPath: String)
} This way, you get a decent default value being displayed in --help, and you can handle both cases as you wish in subsequent code. |
Reffering to
Example Use case - in order to resolve an option with a value that could be set from an enviroment variable, kotlinxcli will first need to get the already resolved value of the env var, and only then search the value inside args.
It means that:
If the default value would have been a provider function that only evaluates when the parser finds that the actual value is missing, it would be much easier to use and goes along side the approach we normaly see in kotlin(for example, a logger.info that accepts a function that returns a string).
There are a lot of cases where the desired behaviour is to compute the default value only if the user did not input anything specific and it seems pretty straight forward to implement inside this lib.
Hope that makes sense, cheers for all your hard and awesome work!
The text was updated successfully, but these errors were encountered: