scala_cli_parser


License

License

Categories

Categories

Scala Languages CLI User Interface
GroupId

GroupId

io.github.fmv1992
ArtifactId

ArtifactId

scala_cli_parser_2.12
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

scala_cli_parser
scala_cli_parser
Project URL

Project URL

https://github.com/fmv1992/fmv1992_scala_utilities
Project Organization

Project Organization

io.github.fmv1992
Source Code Management

Source Code Management

https://github.com/fmv1992/scala_cli_parser

Download scala_cli_parser_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.fmv1992/scala_cli_parser_2.12/ -->
<dependency>
    <groupId>io.github.fmv1992</groupId>
    <artifactId>scala_cli_parser_2.12</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.fmv1992/scala_cli_parser_2.12/
implementation 'io.github.fmv1992:scala_cli_parser_2.12:0.2.0'
// https://jarcasting.com/artifacts/io.github.fmv1992/scala_cli_parser_2.12/
implementation ("io.github.fmv1992:scala_cli_parser_2.12:0.2.0")
'io.github.fmv1992:scala_cli_parser_2.12:jar:0.2.0'
<dependency org="io.github.fmv1992" name="scala_cli_parser_2.12" rev="0.2.0">
  <artifact name="scala_cli_parser_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.fmv1992', module='scala_cli_parser_2.12', version='0.2.0')
)
libraryDependencies += "io.github.fmv1992" % "scala_cli_parser_2.12" % "0.2.0"
[io.github.fmv1992/scala_cli_parser_2.12 "0.2.0"]

Dependencies

compile (5)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.8
com.sandinh : scala-rewrites_2.12 jar 1.0.0
org.scalameta : scalameta_2.12 jar 4.3.24
io.github.fmv1992 : util_2.12 jar 1.11.4
org.scala-lang.modules : scala-collection-compat_2.12 jar 2.2.0

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.12 jar 3.1.0

Project Modules

There are no modules declared in this project.

scala_cli_parser

  • dev:

    • Build status

    • codecov

  • Available for Scala 2.11 (both JVM and Scala Native), 2.12 and 2.13.


A library for parsing command line arguments.

It’s main feature is that CLI parsing is defined on a config file. For example consider a very simple sum program:

import fmv1992.fmv1992_scala_utilities.util.S

object TestSum extends CLIConfigTestableMain {

  val version = "0.0.0"

  val programName = "TestSum"

  val CLIConfigContents =
    S.putfile("./src/test/resources/test_cli_example_02_gnu.txt")

  def testableMain(args: Seq[Argument]): List[String] = {

    val res = args.foldLeft(0)((l, x) => {
      x match {
        case y: Argument if y.longName == "sum" => x.value.map(_.toInt).sum + l
        case _                                  => println(x); throw new Exception()
      }
    })

    List(res.toString)
  }
}

It can be configured with the following config file:

name: version
    n: 0
    type: int
    help: Help text.

name: help
    n: 0
    type: int
    help: Help text.

name: sum
    n: 2
    type: int
    help: Sum arguments.

# vim: set filetype=config fileformat=unix wrap:

And its usages are as follows:

  1. TestSum --version
    
    TestSum 0.0.0
    
  2. TestSum --help
    
    TestSum --debug --help --sum --version
        --debug: Turn on debugging.
        --help: Help text.
        --sum: Sum arguments.
        --version: Show the program version.
    
  3. TestSum --sum 1992 1
    
    1993
    

Versions

Version
0.2.0
0.1.4