Last active
April 2, 2023 10:11
-
-
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
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 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