You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to be able to specify something like the following:
classGitHubOptions : OptionGroup() {
val provider =Provider.GitHubval hostAddress by option(
"--github-host",
help ="The host of the GitHub api"
).default(defaultGitHubHost)
val apiPath by option(
"--github-api-path",
help ="The root path of the GitHub api"
).default(defaultGitHubPath)
}
classGitLabOptions : OptionGroup() {
val provider =Provider.GitLabval hostAddress by option(
"--host",
help ="The host of the GitLab api"
).default(defaultGitLabHost)
val apiPath by option(
"--api-path",
help ="The root path of the GitLab api"
).default(defaultGitLabPath)
}
privateval provider by option("--provider", help ="Whether to scan projects in Github or GitLab")
.groupChoice(
"github" to GitHubOptions(),
"gitlab" to GitLabOptions()
).default("github")
The two option classes specify --host and --api-path - with defaults that need to differ depending on which is defined. Presently, I am forced to require the user to define a provider even though we know the default --host and --api-path for both providers in 90% of cases.
I have the additional issue that I can't actually name them --host and --api-path, they need to be unique even though they can never be specified together.
The text was updated successfully, but these errors were encountered:
I added defaultbyName to groupChoice/groupSwitch options in #175.
However, in your case I think groups might not be necessary. You could do something like this:
val hostAddress by option(
"--host",
help ="The host of the Git provider api"
)
val address get() = hostAddress ?: provider.defaultAddress()
val apiPath by option(
"--api-path",
help ="The root path of the Git provider api"
)
val path get() = apiPath ?: provider.defaultPath()
val provider by option("--provider", help ="Whether to scan projects in Github or GitLab")
.enum<Provider>().default(Provider.GitHub)
This would also make the help output more understandable than having separate groups.
Option names have to be unique across a command. They're all displayed in the help message, so it would be confusing to see the same option listed twice with different help text.
More importantly, it would be ambiguous to parse. Options are finalized (have their values set and validated) in the order they appear on the command line. That's important so that we can issue error messages correctly.
But that means if you have two options named --host, if the command line looks like --host=foo --provider=github, we would have no way to know which option host belongs to when we parse it. And we can't delay finalizing --host, because if the value of --host is invalid, we need to stop parsing immediately and show an error. If --provider is invalid or not specified, we wouldn't be able to parse --host either.
I'd like to be able to specify something like the following:
The two option classes specify
--host
and--api-path
- with defaults that need to differ depending on which is defined. Presently, I am forced to require the user to define a provider even though we know the default--host
and--api-path
for both providers in 90% of cases.I have the additional issue that I can't actually name them
--host
and--api-path
, they need to be unique even though they can never be specified together.The text was updated successfully, but these errors were encountered: