Last active
February 3, 2026 20:24
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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