Comments (4)
Good question. You can, but it's a little more involved. eagerOption
is just a convenience for registerOption(option(eager=true))
, so you can use the lazy help{}
method if you do that yourself. I updated the PR with an example. Let me know if that's clear now.
from clikt.
Sure! I added docs on customizing the help option in #480. Take a look and let me know if that answers your question.
from clikt.
Hey thanks a lot for the quick reply!
Changing the help option behavior
If you want to run some code when the help option is invoked, or change its behavior, you can define
the option yourself. The default help option is an [eager option][eager-options] that throws a
[PrintHelpMessage], so if you wanted to log some information when the help option is invoked, you
could do something like this:=== "Example"
class CustomHelpCommand : TestCommand() {
init {
eagerOption("-h", "--help") {
echo("about to print help")
throw PrintHelpMessage(context)
}
}
}
This suggestion is really nice and it allows me to execute some code when the eager option runs but I was wondering if there is a way to access the default localized help text that would be shown with the default implementation. It's not big deal, I can just hardcode "Show this message and exit"
, but I was wondering if there is a cleaner solution.
from clikt.
Perfect, thanks a lot for the help and for the library!
from clikt.
Related Issues (20)
- Feature request: choosing from options using arrow keys or fuzzy find HOT 1
- [QUESTION] Validate input arguments without running the command HOT 1
- Support path arguments for native HOT 3
- Other ways to construct a CliktCommand object HOT 4
- Disable prompt() globally HOT 3
- Cooccuring option group with required options is passed as nullable HOT 3
- Suspending command support HOT 16
- Question: by option().multiple().groupChoice() ? HOT 5
- Question: one single argument for multiple repeating subcommands HOT 1
- clikt 4.X grew in jar size to over 8mb HOT 8
- Mutually exclusive options in OptionGroup HOT 1
- 4.4.0 CHANGELOG correct?
- Control inputInteractive and outputInteractive in CliktTesting
- No way to timeout on missing input HOT 2
- Error message "java.lang.NoClassDefFoundError: java/lang/management/ManagementFactory" when running as distributable HOT 5
- Is clikt-core published? HOT 5
- Add imports to example Clikt program HOT 2
- Kotlin-Native charset error on Windows HOT 4
- Argument Files (@argfiles) Fail On Redirects (e.g., @<(echo foo)) HOT 1
- Feature request: `associateBy` (or some way of returning other `Map<K, V>` types when using `associate`) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clikt.