argparse

package argparse

Type members

Classlikes

object ArgParser
Companion
class
class ArgParser(val prog: String, val description: String, val version: String, val reporter: Reporter, val env: Map[String, String]) extends SettingsParser

A simple command line argument parser.

A simple command line argument parser.

Usage:

  1. Define parameters with param, requiredParam, repeatedParam and command. Each of these methods gives back a handle to a future argument value.

  2. Call parse() with actual arguments.

  3. If parsing succeeds, the arguments will be available in the handles defined in step 1.

If parsing fails, error descriptions are printed and the program exits with 2. (This behaviour may be changed by subclassing and redefining the check() method).

Example

val parser = argparse.ArgumentParser("appname", "0.1.0")

val p1 = parser.param[String]("--this-is-a-named-param", default = "default value")
val p2 = parser.param[Int]("positional-param", default = 2)

parser.parse(Seq("--this-is-a-named-param=other", 5)) println(p1())

println(p2())
Value Params
description

a short description of this command. Used in help messages.

prog

the name of this command (only used in the default help message)

version

the verion of this app. Used in --version request.

Companion
object
object Ini extends Path => Either[String, String => Option[ConfigValue]]
object MacroUtil
class Macros(using qctx: Quotes)
object Parser

Low-level parsing functionality. See ArgParser for a user-friendly API.

Low-level parsing functionality. See ArgParser for a user-friendly API.

object PredefReader
@implicitNotFound("Don\'t know how to read a ${A} from a command line argument. Try implementing your own argparse.Reader[$A].")
trait Reader[A]

A typeclass that defines how to convert a string from a single command line argument to a given type.

A typeclass that defines how to convert a string from a single command line argument to a given type.

Companion
object
object Reader extends LowPrioReaders
Companion
class
Companion
class
Companion
object
case class arg(aliases: Seq[String], doc: String, env: String) extends StaticAnnotation
case class main(name: String, doc: String, version: String) extends StaticAnnotation
object term

Properties of the current terminal.

Properties of the current terminal.

object userdirs

Common directories for user applications, as specified by the XDG Base Directory Specification, with some adaptations made for macOS.

Common directories for user applications, as specified by the XDG Base Directory Specification, with some adaptations made for macOS.

See also

dirs for conventional directories for an application of a given name, including system services.

Deprecated classlikes

@deprecated("use userdirs for user-specific directories, and the FHS standard for system dirs", "0.10.3")
case class dirs(name: String, system: Boolean)

Common directories for an application of a given name.

Common directories for an application of a given name.

The directories here are implemented as a mix of the XDG Base Directory Specification, macOS adaptations and a fallback to classic unix directories for system applications.

Applications are encouraged to use these directories instead of creating their own hierarchies. They are particularly well-suited for use as parameter defaults, for example:

val parser = argparse.ArgParser()
val cache = parser.param[os.Path](
 "--cache-dir",
 default = argparse.dirs("myapp").cache
Value Params
name

the name of the application

system

use system-wide paths instead of user-specific ones

Companion
object
Deprecated
@deprecated("use userdirs for user-specific directories, and the FHS standard for system dirs", "0.10.3")
object dirs
Companion
class
Deprecated

Types

type Arg[A] = () => A

An argument accessor is a function that returns an argument, assuming that parsing was successful.

An argument accessor is a function that returns an argument, assuming that parsing was successful.

Deprecated types

@deprecated("use ArgParser() instead", "0.3.0")
Deprecated
@deprecated("use userdirs instead", "0.10.3")
type xdg = userdirs
Deprecated

Value members

Concrete methods

inline def parseOrExit[A](container: A, args: Iterable[String]): Unit
inline def parseOrExit(args: Iterable[String]): Unit

Concrete fields

val argsv: Array[String]

Get the system arguments eagerly, this allows using them in a constructor, outside of main().

Get the system arguments eagerly, this allows using them in a constructor, outside of main().

This may be somewhat of a hack.

Deprecated fields

@deprecated("use userdirs instead", "0.10.3")
Deprecated