Skip to content
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 value for option when no value is passed #381

Closed
sschuberth opened this issue Dec 7, 2022 · 3 comments · Fixed by #421
Closed

Default value for option when no value is passed #381

sschuberth opened this issue Dec 7, 2022 · 3 comments · Fixed by #421

Comments

@sschuberth
Copy link
Contributor

sschuberth commented Dec 7, 2022

Is there currently a way to achieve the following behavior (for an exemplary --foo string option):

  • If --foo is not specified on the CLI, set the variable to null.
  • If --foo is specified without a value, apply a default value.
  • If --foo is specified with a value, use that value.
@JakeWharton
Copy link

@sschuberth
Copy link
Contributor Author

Thanks for the answer and reference!

@sschuberth sschuberth changed the title Default vaue for option when no value is passed Default value for option when no value is passed Dec 7, 2022
@sschuberth
Copy link
Contributor Author

Unfortunately, optionalValue currently does not work when using the value of another option:

Exception in thread "main" java.lang.IllegalStateException: Cannot read from argument delegate before parsing command line
        at com.github.ajalt.clikt.parameters.internal.NullableLateinit.getValue(NullableLateinit.kt:18)
        at com.github.ajalt.clikt.parameters.arguments.ProcessedArgumentImpl.getValue(Argument.kt:174)
        at com.github.ajalt.clikt.parameters.arguments.ProcessedArgumentImpl.getValue(Argument.kt:188)
        at com.github.ajalt.clikt.parameters.arguments.ProcessedArgumentImpl.getValue(Argument.kt:155)
        at org.ossreviewtoolkit.helper.commands.classifications.ImportCommand.getProvider(ImportCommand.kt:48)
        at org.ossreviewtoolkit.helper.commands.classifications.ImportCommand.<init>(ImportCommand.kt:56)
        at org.ossreviewtoolkit.helper.commands.classifications.LicenseClassificationsCommand.<init>(LicenseClassificationsCommand.kt:32)
        at org.ossreviewtoolkit.helper.HelperMain.<init>(HelperMain.kt:89)
        at org.ossreviewtoolkit.helper.HelperMainKt.main(HelperMain.kt:54)

Would it make sense to get something like optionalValueLazy, similar to defaultLazy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants