ProductPromotion
Logo

Kotlin

made by https://0x3d.site

GitHub - jimschubert/kopper: A simple Kotlin option parser
A simple Kotlin option parser. Contribute to jimschubert/kopper development by creating an account on GitHub.
Visit Site

GitHub - jimschubert/kopper: A simple Kotlin option parser

GitHub - jimschubert/kopper: A simple Kotlin option parser

Kopper

A simple Kotlin option parser

Maven Central

Maven Central

kopper is the simple Kotlin option parser library.

kopper-typed extends the kopper library to support delegated properties and parsing as simple as constructing an object. It includes the additional dependency of kotlin-reflect.

Examples

Manual parsing…

import us.jimschubert.kopper.*

fun main(args: Array<String>) {
    val parser = Parser()
    parser.setName("Kopper CLI")
    parser.setApplicationDescription("Kopper example application")

    parser.flag("q", listOf("quiet", "silent"), description = "Run silently")
    parser.option("f", listOf("file"), description = "File name")
    parser.flag("a", listOf("allowEmpty"))

    println(parser.printHelp())

    val arguments = parser.parse(arrayOf("-f", "asdf.txt", "--quiet=true", "trailing", "arguments" ))

    println("q=${arguments.flag("q")}")
    println("quiet=${arguments.flag("quiet")}")
    println("silent=${arguments.flag("silent")}")
    println("f=${arguments.option("f")}")
    println("file=${arguments.option("file")}")
    println("allowEmpty=${arguments.flag("allowEmpty")}")
    println("unparsedArgs=${arguments.unparsedArgs.joinToString()}")
}

Parser objects…

fun main(args: Array<String>) {
    val arguments = ExampleArgs(args)

    if (arguments.help) {
        println(arguments.printHelp())
        return
    }

    println("quiet=${arguments.quiet}")
    println("rate=${arguments.rate}")
    println("maxCount=${arguments.maxCount}")
}

class ExampleArgs(args: Array<String>) : TypedArgumentParser(args) {

    val quiet by BooleanArgument(self, "q",
            default = true,
            longOption = listOf("quiet", "silent"),
            description = "Run quietly"
    )

    val rate by NumericArgument(self, "r", 
            default = 1.0f, 
            description = "Rate"
    )

    val maxCount by NumericArgument(self, "m", 
            longOption = listOf("maxCount"), 
            default = 10, 
            description = "Max Count"
    )
}

Typed parser objects support BooleanArgument, StringArgument, and NumericArgument<T> property delegates. They also expose any additional args as a list of strings in the _etc_ property.

License

MIT License

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory