'How to build and package CommandApp from decline library

(Note: I'm totally new to Scala and still wrapping my head around sbt tooling)

I have a small command line app using decline and I am confused about how to build it so as to execute that from console.

I referred the quick-start tutorial for decline - https://ben.kirw.in/decline/ that has below example.

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!")
    }
  }
)

And it shows the resulting app can be executed from console like below.


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

Says hello!

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

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

Could someone please guide me how to build the source code to have this executable app? I have read through sbt tasks but could not find anything that works.

Appreciate any pointers on this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source