xuwei-k/optparse-applicative


Scala port of Paolo Capriotti's optparse-applicative library. fork from https://github.com/bmjames/scala-optparse-applicative

License: BSD-3-Clause

Language: Scala

Keywords: applicative, command-line-parser, scala, scala-js, scala-native, scalaz


scala-optparse-applicative

Build Status

A port of the optparse-applicative library to the Scala programming language.

Most functionality has been ported, except completion.

This library depends on Scalaz for functional data structures, type classes and combinators.

How to get it

Version 0.7 of scala-optparse-applicative is available for Scala 2.10, 2.11 and 2.12.

resolvers += "bmjames Bintray Repo" at "https://dl.bintray.com/bmjames/maven"

libraryDependencies += "net.bmjames" %% "scala-optparse-applicative" % "0.7"

License

This library is distributed under a BSD 3-Clause license (see LICENSE).

Simple example

This example follows the one from the [optparse-applicative] 1 docs.

case class Sample(hello: String, quiet: Boolean)

object SampleMain {

  val sample: Parser[Sample] =
    ^(
      strOption(long("hello"), metavar("TARGET"), help("Target for the greeting")),
      switch(long("quiet"), help("Whether to be quiet"))
    )(Sample.apply)

  def greet(s: Sample): Unit = s match {
    case Sample(h, false) => println("Hello, " ++ h)
    case _ =>
  }

  def main(args: Array[String]) {
    val opts = info(sample <*> helper,
      progDesc("Print a greeting for TARGET"),
      header("hello - a test for scala-optparse-applicative"))
    greet(execParser(args, "SampleMain", opts))
  }

}

When run with the --help option, it prints:

hello - a test for scala-optparse-applicative

Usage: SampleMain --hello TARGET [--quiet]
  Print a greeting for TARGET

Available options:
  -h,--help                Show this help text
  --hello TARGET           Target for the greeting
  --quiet                  Whether to be quiet

Advanced examples

Further examples can be found in src/test/examples.

To Do

  • More tests

Project Statistics

Sourcerank 5
Repository Size 147 KB
Stars 4
Forks 0
Watchers 2
Open issues 0
Dependencies 0
Contributors 9
Tags 7
Created
Last updated
Last pushed

Top Contributors See all

Ben James Colt Frederickson kenji yoshida Rob Norris SamRoberts Maun Suang Boey Adelbert Chang Dale Wijnand Kris Nuttycombe

Packages Referencing this Repo

com.github.xuwei-k:optparse-applicative_2.13.0-M4-pre-20d3c21
optparse-applicative is a Scala library for parsing options on the command line, providing a powe...
Latest release 0.8.0 - Published - 4 stars
com.github.xuwei-k:optparse-applicative_2.13.0-M3
optparse-applicative is a Scala library for parsing options on the command line, providing a powe...
Latest release 0.8.0 - Published - 4 stars
com.github.xuwei-k:optparse-applicative_sjs0.6_2.11
optparse-applicative is a Scala library for parsing options on the command line, providing a powe...
Latest release 0.8.0 - Published - 4 stars
com.github.xuwei-k:optparse-applicative_sjs0.6_2.12
optparse-applicative is a Scala library for parsing options on the command line, providing a powe...
Latest release 0.8.0 - Published - 4 stars
com.github.xuwei-k:optparse-applicative_2.11
optparse-applicative is a Scala library for parsing options on the command line, providing a powe...
Latest release 0.8.0 - Published - 4 stars
com.github.xuwei-k:optparse-applicative_sjs0.6_2.13.0-M3
optparse-applicative is a Scala library for parsing options on the command line, providing a powe...
Latest release 0.8.0 - Published - 4 stars
com.github.xuwei-k:optparse-applicative_2.12
optparse-applicative is a Scala library for parsing options on the command line, providing a powe...
Latest release 0.8.0 - Published - 4 stars
com.github.xuwei-k:optparse-applicative_native0.3_2.11
optparse-applicative is a Scala library for parsing options on the command line, providing a powe...
Latest release 0.8.0 - Published - 4 stars

Recent Tags See all

release/0.7 April 15, 2017
release/0.6 December 21, 2016
release/0.5 November 05, 2016
release/0.4 July 27, 2016
release/0.3 October 13, 2015
release/0.2 November 24, 2014
release/0.1 November 07, 2014

Something wrong with this page? Make a suggestion

Last synced: 2018-04-02 00:28:51 UTC

Login to resync this repository