Slide 1

Slide 1 text

Clikt brian plummer @plummermakes

Slide 2

Slide 2 text

Command Line Interface for Kotlin

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

/giphy ain’t nobody got time for that

Slide 7

Slide 7 text

Clikt does one job really well

Slide 8

Slide 8 text

Options and Arguments

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

val count by option()

Slide 14

Slide 14 text

val count by option().default(“1”)

Slide 15

Slide 15 text

val count: Int by option().int().default(1)

Slide 16

Slide 16 text

option(help = “Number of greetings”)

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

val name by argument()

Slide 19

Slide 19 text

val name by argument(help = “name to say hello to”)

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

val someFlag by option()

Slide 25

Slide 25 text

val someFlag by option().flag()

Slide 26

Slide 26 text

val someFlag by option(“-f”).flag()

Slide 27

Slide 27 text

val someFlag by option (“-f”).flag(default = false)

Slide 28

Slide 28 text

./cliktsample brian Flag f has value: false Hello brian!

Slide 29

Slide 29 text

./cliktsample -f brian Flag f has value: true Hello brian!

Slide 30

Slide 30 text

How do we get that binary? ./cliktsample

Slide 31

Slide 31 text

Gradle’s application plugin

Slide 32

Slide 32 text

./gradlew installDist ./build/install/cliktsample/bin/ clicktsample

Slide 33

Slide 33 text

Packages us up nicely!

Slide 34

Slide 34 text

Lots of features! Let’s look at just a couple more

Slide 35

Slide 35 text

Custom Types

Slide 36

Slide 36 text

Multiple Options

Slide 37

Slide 37 text

Nested Commands

Slide 38

Slide 38 text

Prompt for input val name by option().prompt()

Slide 39

Slide 39 text

Prompt for password prompt(requireConfirmation = true, hideInput = true)

Slide 40

Slide 40 text

And much much more •Choice / Mutually Exclusive / Eager /……Options •Documenting / Formatting •Token normalization / Replacing stdin/stdout •Launch Editor / Bash Autocomplete •Exception Handing

Slide 41

Slide 41 text

And much much more

Slide 42

Slide 42 text

Why not a Kotlin lib like kotlin-argparse or kotlinx.cli? •Lack of subcommand, though that has changed •Not nearly as feature rich •Clikt tries to be consistent and intuitive •Clikt is JVM based

Slide 43

Slide 43 text

Sometimes we have to support scripts that we would rather not

Slide 44

Slide 44 text

There was a ruby script that did string interpolation

Slide 45

Slide 45 text

Legacy Kotlin

Slide 46

Slide 46 text

We can now •Isolate the legacy code •Better control on legacy code invocation •Build new features on our terms •Refactor and pull code into Kotlin

Slide 47

Slide 47 text

StranglerFig Application •Martin Fowler ~ 2004 •Create new system around the old •Gradually move functionality to new •Less risky way to replace

Slide 48

Slide 48 text

Thanks! @plummermakes