https://github.com/lhns/scala-commandline
Scala command line parser
https://github.com/lhns/scala-commandline
cli commandline parser scala
Last synced: 4 months ago
JSON representation
Scala command line parser
- Host: GitHub
- URL: https://github.com/lhns/scala-commandline
- Owner: lhns
- License: apache-2.0
- Created: 2020-04-22T14:11:17.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2026-01-06T00:32:02.000Z (6 months ago)
- Last Synced: 2026-01-14T03:51:27.077Z (5 months ago)
- Topics: cli, commandline, parser, scala
- Language: Scala
- Homepage:
- Size: 162 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# scala-commandline
[](https://github.com/lhns/scala-commandline/actions/workflows/build.yml)
[](https://search.maven.org/artifact/de.lhns/scala-commandline_2.13)
[](https://www.apache.org/licenses/LICENSE-2.0)
[](https://scala-steward.org)
A small state-monad-based command line parser library written in scala.
### build.sbt
```sbt
libraryDependencies += "de.lhns" %% "scala-commandline" % "0.4.0"
```
## Example
```scala
case class Options(help: Boolean,
version: Boolean,
logLevel: Option[String],
decode: Boolean,
validate: Boolean,
params: Seq[String])
def main(args: Array[String]): Unit = {
val options: Options = CommandLine(args) {
for {
default <- CommandLine.defaultOpts()
/* shorthand for:
empty <- CommandLine.isEmpty
help <- CommandLine.opt("-h", "--help").flag
version <- CommandLine.opt("--version").flag
*/
logLevel <- CommandLine.opt("--loglevel").arg.map(_.lastOption)
decode <- CommandLine.opt("-d", "--decode").flag
validate <- CommandLine.opt("--validate").flag
_ <- CommandLine.errorOnUnrecognizedOpts()
params <- CommandLine.args
} yield Options(
help = default.empty || default.help,
version = default.version,
logLevel = logLevel,
decode = decode,
validate = validate,
params = params
)
}
}
```
## License
This project uses the Apache 2.0 License. See the file called LICENSE.