Class

com.github.acrisci.commander

Program

Related Doc: package commander

Permalink

class Program extends Dynamic

The program is a class used to parse command line arguments. Add options to this class with Program::option(). Parse arguments you get from the main() method with Program::parse(). The values of the options will be dynamically set on this object in camelcase form. Example:

import com.github.acrisci.commander.Program

var program = new Program()
  .version("0.0.1")
  .option("-p, --peppers", "Add peppers")
  .option("-P, --pineapple", "Add pineapple")
  .option("-b, --bbq-sauce", "Add bbq sauce")
  .option("-c, --cheese [type]", "Add the specified type of cheese [marble]", default="marble")
  .parse(args)

if (args.isEmpty)
  program.help

println("you ordered a pizza with:")
if (program.peppers)
  println("  - peppers")
if (program.pineapple)
  println("  - pineapple")
if (program.bbqSauce)
  println("  - bbq")
println("  - " + cheese + " cheese")

Linear Supertypes
Dynamic, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Program
  2. Dynamic
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Program(exitOnError: Boolean = true, exitOnCommand: Boolean = true)

    Permalink

    exitOnError

    deprecated - do not use

    exitOnCommand

    deprecated - do not use

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. var args: List[String]

    Permalink

    Unknown arguments not given to an option will be stored here.

  5. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  6. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  7. def command(klass: Class[_], usage: String = "", description: String = ""): Program

    Permalink

    Define a command that will run the given class with usage and description.

    Define a command that will run the given class with usage and description.

    The command will be defined as the hyphenated name of the class (e.g., SomeClass -> some-class). You can choose your own name for the command by providing it as the first word (beginning with a word character) in the usage parameter.

    If the command name is given as the first argument on the command line, it will run a method with the signature main(args: Array[String]) of the given class with the remaining arguments. That class should define another program in the main method to handle the remaining arguments.

    Examples:

      // If ./program install-package is given on the command line, it will run InstallPackage.main() with the remaining args.
      program.command(classOf[InstallPackage], "[package]", "Install the given package")
      // Override the name of the command to `install`
      program.command(classOf[InstallPackage], "install [package]", "Install the given package")
    

    klass

    The class that will handle this command. It should have a method with signature main(args: Array[String]) that will be called with remaining arguments.

    usage

    Usage that will be displayed in the help message. The first word will be the name of the command if it begins with a word character.

    description

    Description of this command to be displayed in the help string.

    returns

    Returns the program for chaining.

  8. def description(d: String): Program

    Permalink

    Set a description for this program

    Set a description for this program

    d

    the description of this program

  9. var description: String

    Permalink

    A useful description to be printed in the help string of this program.

  10. def epilogue(e: String): Program

    Permalink

    Set an epilogue message for this program

    Set an epilogue message for this program

    e

    the epilogue message

  11. var epilogue: String

    Permalink

    Additional information to be printed at the end of the help string in this program.

  12. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  13. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  14. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  15. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  16. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  17. def help(): Nothing

    Permalink

    Print help information and exit

  18. def helpInformation(): String

    Permalink

    Get a help string for this program.

  19. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  20. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  21. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  22. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  23. def option(flags: String, description: String, default: Any = null, required: Boolean = false, fn: (String) ⇒ Any = identity): Program

    Permalink

    Define option with flags, description and optional coercion fn.

    Define option with flags, description and optional coercion fn.

    The flags string should contain both the short and long flags, separated by comma, a pipe or space. The following are all valid all will output this way when --help is used.

    "-p, --pepper"
    "-p|--pepper"
    "-p --pepper"
    

    Examples:

    // simple boolean defaulting to false
    program.option("-p, --pepper", "add pepper")
    // option with optional parameter defaulting to "marble"
    program.option("-c, --cheese [type]", "add cheese", default="marble")
    // option with required parameter
    program.option("-b, --bbq-sauce ", "add bbq sauce")
    // option that is coerced to an integer
    program.option("-n, --num [num]", "number of pizzas", default=1, fn=(_.toInt))
    // option that is required for the program to run
    program.option("-C, --crust ", required=true)
    

    flags

    The flags for this option (see example)

    description

    Description of this option for the help string

    default

    The default value when this option is not given

    required

    Whether this option is required for the program to run

    fn

    Coercion function that takes the string value given on the command line and returns the value that will be given on the program object

  24. def parse(argv: Array[String]): Program

    Permalink

    Parse command line args

    Parse command line args

    argv

    Args given to the main() method.

  25. def selectDynamic[T](name: String)(implicit arg0: ClassTag[T]): T

    Permalink

    Options will be set dynamically on this class in camelcase form.

    Options will be set dynamically on this class in camelcase form. Do not use this method directly.

    name

    the name of the option to get a value for

  26. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  27. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  28. def usage(u: String): Program

    Permalink

    Set usage information for this program

    Set usage information for this program

    u

    the usage information

  29. var usage: String

    Permalink

    Custom usage information to be printed in the help string

  30. def version(v: String): Program

    Permalink

    Set the version of this program.

    Set the version of this program.

    v

    the version of this program

  31. var version: String

    Permalink

    The version of this program.

    The version of this program. This will be printed when -v or --version is given on the command line (TODO).

  32. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  33. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  34. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Dynamic

Inherited from AnyRef

Inherited from Any

Ungrouped