Last active
June 15, 2024 07:58
-
-
Save dacr/f67057c1220521e7887e2364b0734e31 to your computer and use it in GitHub Desktop.
com-lihaoyi mainargs basic usage examples / published by https://github.com/dacr/code-examples-manager #01b15efe-23c8-4e73-85b1-66c857979694/436ce932ca4ca86eb64707ac646147759d01e276
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 : com-lihaoyi mainargs basic usage examples | |
// keywords : scala, lihaoyi, mainargs, @testable | |
// 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 : 01b15efe-23c8-4e73-85b1-66c857979694 | |
// created-on : 2024-01-06T16:55:30+01:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file -- --help | |
// --------------------- | |
//> using scala "3.4.2" | |
//> using dep "com.lihaoyi::mainargs:0.7.0" | |
// --------------------- | |
import mainargs.{main, arg, ParserForMethods, Flag} | |
object Main { | |
@main | |
def run( | |
@arg(short = 'f', doc = "String to print repeatedly") | |
foo: String, | |
@arg(name = "my-num", doc = "How many times to print string") | |
myNum: Int = 2, | |
@arg(doc = "Example flag, can be passed without any value to become true") | |
bool: Flag | |
) = { | |
println(foo * myNum + " " + bool.value) | |
} | |
def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args) | |
} | |
Main.main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment