Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active June 15, 2024 07:58
Show Gist options
  • Save dacr/f67057c1220521e7887e2364b0734e31 to your computer and use it in GitHub Desktop.
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
// 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