Clikt

Multiplatform command line interface parsing for Kotlin

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

com.github.ajalt
ArtifactId

ArtifactId

clikt
Last Version

Last Version

2.8.0
Release Date

Release Date

Type

Type

module
Description

Description

Clikt
Multiplatform command line interface parsing for Kotlin
Project URL

Project URL

https://github.com/ajalt/clikt
Source Code Management

Source Code Management

https://github.com/ajalt/clikt

Download clikt

Dependencies

compile (2)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib jar 1.3.72
org.jetbrains.kotlin : kotlin-stdlib-common jar 1.3.72

Project Modules

There are no modules declared in this project.

Clikt (pronounced "clicked") is a multiplatform Kotlin library that makes writing command line interfaces simple and intuitive. It's the "Command Line Interface for Kotlin".

It is designed to make the process of writing command line tools effortless while supporting a wide variety of use cases and allowing advanced customization when needed.

Clikt has:

  • arbitrary nesting of commands
  • composable, type safe parameter values
  • support for a wide variety of command line interface styles
  • multiplatform packages for JVM, NodeJS, and native Linux, Windows and MacOS

What does it look like? Here's a complete example of a simple Clikt program:

class Hello : CliktCommand() {
    val count: Int by option(help="Number of greetings").int().default(1)
    val name: String by option(help="The person to greet").prompt("Your name")

    override fun run() {
        repeat(count) {
            echo("Hello $name!")
        }
    }
}

fun main(args: Array<String>) = Hello().main(args)

And here's what it looks like when run:

 $ ./hello --count=3
 Your name: John
 Hello John!
 Hello John!
 Hello John!

The help page is generated for you:

$ ./hello --help
Usage: hello [OPTIONS]

Options:
  --count INT  Number of greetings
  --name TEXT  The person to greet
  -h, --help   Show this message and exit

Errors are also taken care of:

$ ./hello --whoops
Usage: hello [OPTIONS]

Error: no such option: "--whoops".

Documentation

The full documentation can be found on the website.

There are also a number of sample applications. You can run them with the included runsample script.

Installation

Clikt is distributed through Maven Central.

dependencies {
   implementation("com.github.ajalt.clikt:clikt:3.0.1")
}
In version 3.0, the maven coordinates changed. Make sure you're using the new coordinates if you're updating from an older version.

Multiplatform

Clikt supports the following targets: jvm, mingwX64, linuxX64, macosX64, and js (for both NodeJS and Browsers). See the docs for more information about functionality supported on each target. You'll need to use Gradle 6 or newer.

Snapshots

Snapshot builds are also available

You'll need to add the Sonatype snapshots repository:

repositories {
    maven {
        url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
    }
}

License

Copyright 2018-2020 AJ Alt

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
2.8.0
2.7.1
2.7.0
2.6.0
2.5.0
2.5.0-beta1
2.4.0
2.3.0
2.2.0
2.1.0
2.0.0
1.7.0
1.6.0
1.5.0
1.4.0
1.3.0