ProductPromotion
Logo

Scala

made by https://0x3d.site

GitHub - scallop/scallop: a simple Scala CLI parsing library
a simple Scala CLI parsing library. Contribute to scallop/scallop development by creating an account on GitHub.
Visit Site

GitHub - scallop/scallop: a simple Scala CLI parsing library

GitHub - scallop/scallop: a simple Scala CLI parsing library

Scallop

Build Status

A simple command-line arguments parsing library for Scala. Cross-built for Scala 3.0, 2.13, 2.12, 2.11, 2.10, supports Scala Native and Scala JS.

Scallop supports:

  • flag, single-value and multiple value options
  • POSIX-style short option names (-a) with grouping (-abc)
  • GNU-style long option names (--opt, --opt=value)
  • unnamed integer options, like GNU tail (-42)
  • Property arguments (-Dkey=value, -D key1=value key2=value)
  • Non-string types of options and properties values (with extendable converters)
  • Powerful matching on trailing args
  • Subcommands

For more info and information on usage, you can look into the project wiki or consult the API docs.

Also, I wrote a blog post and another one about Scallop.

Installation

Add following to your build.sbt:

libraryDependencies += "org.rogach" %% "scallop" % "5.1.0"

For use with Scala Native and Scala.js, use %%%:

libraryDependencies += "org.rogach" %%% "scallop" % "5.1.0"

If you were using 4.x version or older, please see migration notes.

Quick example

import org.rogach.scallop._

class Conf(arguments: Seq[String]) extends ScallopConf(arguments) {
  val apples = opt[Int](required = true)
  val bananas = opt[Int]()
  val name = trailArg[String]()
  verify()
}

object Main {
  def main(args: Array[String]) {
    val conf = new Conf(args)
    println("apples are: " + conf.apples())
  }
}

This snippet above defined simple configuration that will parse argument lines like these:

--apples 4 --bananas 10 strangeTree
-a 4 appleTree

For more examples, you can look at Scallop's wiki and test suite.

Fancy things

Scallop supports quite powerful matching on trailing arguments. For example:

object Conf extends ScallopConf(
       List("-Ekey1=value1", "key2=value2", "key3=value3",
            "first", "1","2","3","second","4","5","6")) {
  val properties = props[String]('E')
  val firstListName = trailArg[String]()
  val firstList = trailArg[List[Int]]()
  val secondListName = trailArg[String]()
  val secondList = trailArg[List[Double]]()
  verify()
}
Conf.properties("key1") shouldBe "value1"
Conf.firstListName() shouldBe "first"
Conf.secondListName() shouldBe "second"
Conf.firstList() shouldBe List(1,2,3)
Conf.secondList() shouldBe List[Double](4,5,6)

In this case, Scallop's backtracking parser is clever enough to distinguish the boundaries of the arguments lists.

Also, Scallop supports parsing of subcommands. Not only subcommands, but nested subcommands!

object Conf extends ScallopConf(Seq("sub1", "sub2", "sub3", "sub4", "win!")) {
  object sub1 extends Subcommand("sub1") {
    object sub2 extends Subcommand("sub2") {
      object sub3 extends Subcommand("sub3") {
        object sub4 extends Subcommand("sub4") {
          val opts = trailArg[List[String]]()
        }
        addSubcommand(sub4)
      }
      addSubcommand(sub3)
    }
    addSubcommand(sub2)
  }
  addSubcommand(sub1)
  verify()
}
Conf.subcommands shouldBe List(Conf.sub1, Conf.sub1.sub2, Conf.sub1.sub2.sub3, Conf.sub1.sub2.sub3.sub4)
Conf.sub1.sub2.sub3.sub4.opts() shouldBe List("win!")

Thanks

... and the whole Scala community for help and explanations.

Notes

Scallop is distributed under MIT license.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory