https://github.com/meysampg/scala-autoconf
Just Another Command Line Arguments Parser for Scala
https://github.com/meysampg/scala-autoconf
cli-parser commandlineparser scala
Last synced: about 1 year ago
JSON representation
Just Another Command Line Arguments Parser for Scala
- Host: GitHub
- URL: https://github.com/meysampg/scala-autoconf
- Owner: meysampg
- License: mit
- Created: 2023-01-05T10:24:44.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-06T12:35:25.000Z (over 3 years ago)
- Last Synced: 2025-03-15T04:25:24.513Z (over 1 year ago)
- Topics: cli-parser, commandlineparser, scala
- Language: Scala
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Scala CLI AutoConf
==================
```scala
package com.github.meysampg.sample
import com.github.meysampg.autoconf.Parser
import com.github.meysampg.autoconf.{Argument, Config}
@Config
class SampleConfig
(
@Argument("name", "name to show")
val name: String,
@Argument("iteration", "count of iteration")
val iteration: Int,
@Argument("only-even-numbers", "print name only for even numbers")
val onlyEvenNumbers: Option[Boolean], // make optional argument with Option type
@Argument("pre-line-char", "characters to print before each line")
val preLine: String = ">>> ", // make optional with default value
@Argument("post-line-seq", "show characters after the line")
val postLine: Seq[String],
)
object Main {
def print(pr: String, i: Int, name: String, po: Seq[String]): Unit =
println(s"${pr}$i ${name} ${po.mkString(" ")}")
def main(args: Array[String]): Unit = {
val config: SampleConfig = Parser(args).as[SampleConfig]
if (config.onlyEvenNumbers.isDefined)
Range(0, config.iteration).withFilter(_ % 2 == 0)
.foreach(i => print(config.preLine, i, config.name, config.postLine))
else
Range(0, config.iteration)
.foreach(i => print(config.preLine, i, config.name, config.postLine))
}
}
```
```shell
$ java target/autoconf.jar com.github.meysampg.sample.Main --name Meysam --iteration 5 --only-even-numbers --pre-line-char !!!
!!!0 Meysam
!!!2 Meysam
!!!4 Meysam
```