replpp.shaded.scopt

Members list

Type members

Classlikes

abstract class DefaultOEffectSetup extends OEffectSetup

Attributes

Supertypes
trait OEffectSetup
class Object
trait Matchable
class Any
abstract class DefaultOParserSetup extends OParserSetup

Attributes

Supertypes
trait OParserSetup
class Object
trait Matchable
class Any
sealed trait OEffect

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object OEffect

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
OEffect.type
trait OEffectSetup

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class OParser[A, C](head: OptionDef[A, C], rest: List[OptionDef[_, C]])

A monadic commandline options parser.

A monadic commandline options parser.

import scopt.OParser
val builder = OParser.builder[Config]
val parser1 = {
 import builder._
 OParser.sequence(
   programName("scopt"),
   head("scopt", "4.x"),
   opt[Int]('f', "foo")
     .action((x, c) => c.copy(foo = x))
     .text("foo is an integer property"),
   opt[File]('o', "out")
     .required()
     .valueName("<file>")
     .action((x, c) => c.copy(out = x))
     .text("out is a required file property"),
   opt[(String, Int)]("max")
     .action({ case ((k, v), c) => c.copy(libName = k, maxCount = v) })
     .validate(x =>
       if (x._2 > 0) success
       else failure("Value <max> must be >0"))
     .keyValueName("<libname>", "<max>")
     .text("maximum count for <libname>"),
   opt[Seq[File]]('j', "jars")
     .valueName("<jar1>,<jar2>...")
     .action((x, c) => c.copy(jars = x))
     .text("jars to include"),
   opt[Map[String, String]]("kwargs")
     .valueName("k1=v1,k2=v2...")
     .action((x, c) => c.copy(kwargs = x))
     .text("other arguments"),
   opt[Unit]("verbose")
     .action((_, c) => c.copy(verbose = true))
     .text("verbose is a flag"),
   opt[Unit]("debug")
     .hidden()
     .action((_, c) => c.copy(debug = true))
     .text("this option is hidden in the usage text"),
   help("help").text("prints this usage text"),
   arg[File]("<file>...")
     .unbounded()
     .optional()
     .action((x, c) => c.copy(files = c.files :+ x))
     .text("optional unbounded args"),
   note("some notes." + sys.props("line.separator")),
   cmd("update")
     .action((_, c) => c.copy(mode = "update"))
     .text("update is a command.")
     .children(
       opt[Unit]("not-keepalive")
         .abbr("nk")
         .action((_, c) => c.copy(keepalive = false))
         .text("disable keepalive"),
       opt[Boolean]("xyz")
         .action((x, c) => c.copy(xyz = x))
         .text("xyz is a boolean property"),
       opt[Unit]("debug-update")
         .hidden()
         .action((_, c) => c.copy(debug = true))
         .text("this option is hidden in the usage text"),
       checkConfig(
         c =>
           if (c.keepalive && c.xyz) failure("xyz cannot keep alive")
           else success)
     )
 )
}

// OParser.parse returns Option[Config]
OParser.parse(parser1, args, Config()) match {
 case Some(config) =>
   // do something
 case _ =>
   // arguments are bad, error message will have been displayed
}

// alternatively, use OParser.runParser returns (Option[Config], List[OEffect])
OParser.runParser(parser1, args, Config()) match {
 case (result, effects) =>
   OParser.runEffects(effects, new DefaultOEffectSetup {
     // override def displayToOut(msg: String): Unit = Console.out.println(msg)
     // override def displayToErr(msg: String): Unit = Console.err.println(msg)
     // override def reportError(msg: String): Unit = displayToErr("Error: " + msg)
     // override def reportWarning(msg: String): Unit = displayToErr("Warning: " + msg)

     // ignore terminate
     override def terminate(exitState: Either[String, Unit]): Unit = ()
   })

   result match {
     Some(config) =>
       // do something
     case _ =>
       // arguments are bad, error message will have been displayed
   }
}

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object OParser

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
OParser.type
abstract class OParserBuilder[C]

Attributes

Supertypes
class Object
trait Matchable
class Any
trait OParserSetup

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class OptionDef[A, C](_id: Int, _kind: OptionDefKind, _name: String, _shortOpt: Option[String], _keyName: Option[String], _valueName: Option[String], _desc: String, _action: (A, C) => C, _validations: Seq[A => Either[String, Unit]], _configValidations: Seq[C => Either[String, Unit]], _parentId: Option[Int], _minOccurs: Int, _maxOccurs: Int, _isHidden: Boolean, _fallback: Option[() => A], _defCallback: OptionDefCallback[C])(implicit evidence$1: Read[A])

Attributes

Supertypes
class Object
trait Matchable
class Any
abstract class OptionDefCallback[C]

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class OptionParser[C]

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
abstract class OptionParser[C](programName: String) extends OptionDefCallback[C]

scopt.immutable.OptionParser is instantiated within your object, set up by an (ordered) sequence of invocations of the various builder methods such as opt method or arg method.

scopt.immutable.OptionParser is instantiated within your object, set up by an (ordered) sequence of invocations of the various builder methods such as opt method or arg method.

val parser = new scopt.OptionParser[Config]("scopt") {
 head("scopt", "4.x")

 opt[Int]('f', "foo").action( (x, c) =>
   c.copy(foo = x) ).text("foo is an integer property")

 opt[File]('o', "out").required().valueName("<file>").
   action( (x, c) => c.copy(out = x) ).
   text("out is a required file property")

 opt[(String, Int)]("max").action({
     case ((k, v), c) => c.copy(libName = k, maxCount = v) }).
   validate( x =>
     if (x._2 > 0) success
     else failure("Value <max> must be >0") ).
   keyValueName("<libname>", "<max>").
   text("maximum count for <libname>")

 opt[Seq[File]]('j', "jars").valueName("<jar1>,<jar2>...").action( (x,c) =>
   c.copy(jars = x) ).text("jars to include")

 opt[Map[String,String]]("kwargs").valueName("k1=v1,k2=v2...").action( (x, c) =>
   c.copy(kwargs = x) ).text("other arguments")

 opt[Unit]("verbose").action( (_, c) =>
   c.copy(verbose = true) ).text("verbose is a flag")

 opt[Unit]("debug").hidden().action( (_, c) =>
   c.copy(debug = true) ).text("this option is hidden in the usage text")

 help("help").text("prints this usage text")

 arg[File]("<file>...").unbounded().optional().action( (x, c) =>
   c.copy(files = c.files :+ x) ).text("optional unbounded args")

 note("some notes.".newline)

 cmd("update").action( (_, c) => c.copy(mode = "update") ).
   text("update is a command.").
   children(
     opt[Unit]("not-keepalive").abbr("nk").action( (_, c) =>
       c.copy(keepalive = false) ).text("disable keepalive"),
     opt[Boolean]("xyz").action( (x, c) =>
       c.copy(xyz = x) ).text("xyz is a boolean property"),
     opt[Unit]("debug-update").hidden().action( (_, c) =>
       c.copy(debug = true) ).text("this option is hidden in the usage text"),
     checkConfig( c =>
       if (c.keepalive && c.xyz) failure("xyz cannot keep alive")
       else success )
   )
}

// parser.parse returns Option[C]
parser.parse(args, Config()) match {
 case Some(config) =>
   // do stuff

 case None =>
   // arguments are bad, error message will have been displayed
}

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
trait Read[A]

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Self type
Read[A]
object Read extends PlatformReadInstances

Attributes

Companion
trait
Supertypes
trait PlatformReadInstances
class Object
trait Matchable
class Any
Self type
Read.type

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object OneColumn.type
object TwoColumns.type
object RenderingMode

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
object Validation

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Validation.type