decline is a composable command-line parsing library, inspired by optparse-applicative and built on cats.

Why decline?

  • Full-featured: decline supports the standard set of Unix command-line idioms, including flags, options, positional arguments, and subcommands. Support for mutually-exclusive options and custom validations make it easy to mold your CLI to the shape of your application.
  • Helpful: decline automatically generates comprehensive and precise error messages and usage texts.
  • Functional: decline provides an immutable and functional API, usable whether or not your program is written in a functional style.

Quick Start

First, pull the library into your build. For sbt:

// NB: 1.2.0 is the last release to support Scala 2.11
libraryDependencies += "com.monovore" %% "decline" % "2.4.2-SNAPSHOT"

Then, write a program:

import cats.implicits._
import com.monovore.decline._

object HelloWorld extends CommandApp(
  name = "hello-world",
  header = "Says hello!",
  main = {
    val userOpt =
      Opts.option[String]("target", help = "Person to greet.").withDefault("world")

    val quietOpt = Opts.flag("quiet", help = "Whether to be quiet.").orFalse

    (userOpt, quietOpt).mapN { (user, quiet) =>
      if (quiet) println("...")
      else println(s"Hello $user!")

Then, run it:

$ hello-world --help
Usage: hello-world [--target <string>] [--quiet]

Says hello!

Options and flags:
        Display this help text.
    --target <string>
        Person to greet.
        Whether to be quiet.

$ hello-world --target friend
Hello, friend!

(For a more in-depth introduction, see the user’s guide!)