Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active April 2, 2023 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacr/a28dcfd3e11a95ecb58be9e95914f8a0 to your computer and use it in GitHub Desktop.
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/246a4d4296a886838804e9e429096ceb94eee6bc
// summary : command line options parser
// keywords : scala, script, commandline, parser, helloworld
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// 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