Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:24
Show Gist options
  • Select an option

  • Save dacr/a28dcfd3e11a95ecb58be9e95914f8a0 to your computer and use it in GitHub Desktop.

Select an option

Save dacr/a28dcfd3e11a95ecb58be9e95914f8a0 to your computer and use it in GitHub Desktop.
command line options parser / published by https://github.com/dacr/code-examples-manager #f562bfbe-4bdc-4e1c-88e3-f891264c348e/9a399af735ebc61dc522a7666d9c0656dac9b400
// summary : command line options parser
// keywords : scala, script, commandline, parser, helloworld
// publish : gist
// authors : David Crosson
// license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
// id : f562bfbe-4bdc-4e1c-88e3-f891264c348e
// created-on : 2019-11-13T20:13:56Z
// managed-by : https://github.com/dacr/code-examples-manager
// execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc'
// inspired from http://ben.kirw.in/decline/
import $ivy.`com.monovore::decline:1.0.0`
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!")
}
}
)
@main
def main(args: String*):Unit = HelloWorld.main(args.toArray)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment