Comments (4)
Thanks for the example. There are lots of annotation based CLI libraries out there, and I touched on the disadvantages of them in the docs. They require reflection and code generation, they're less type safe, and are harder to customize than Clikt. But feel free to use one if you prefer; Clikt will never be an annotation based library.
It seems that the folks who have issues with Clikt's inheritance are trying to use a CliktCommand as their data model. Clikt is UI, and like all UI, coupling it to your data layer can make it harder to test. You probably wouldn't define your data model in HTML fields on DOM nodes, or on properties on an Android View.
It's easy to make a plain data class from a command:
fun MyCommand.toModel() = MyModel(
foo=foo,
bar=bar,
//...
)
val model = MyCommand().apply{ main(argv) }.toModel()
from clikt.
Another solution is to use composition instead of inheritance.
What exactly would that solution look like?
from clikt.
Similar to this #453 (comment)
If I can create a data object
data class Configuration(val @Option("clazz", type=String...) clazz: String, val: report: String, val targetArgs: AlgoOption) { // if we can configure the options through argument annotations.
init(args: CliKt) { // If CliKt can generate this constructor automatically...
init(args.clazz, args.report, args.algo)
}
}
and construct the data class through clikt in my main program
val config: Configuration = parser.parse(args)
Then I can just construct my Configuration
object in unit tests freely.
val config = Configuration("", ...)
from clikt.
I see, Thanks for your explanation. It makes sense to me.
from clikt.
Related Issues (20)
- [QUESTION] Validate input arguments without running the command HOT 1
- Support path arguments for native HOT 3
- 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
- Aliases should support tokens that look like other options
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.