scalax.io

class CommandLineParser

[source: scalax/io/CommandLineParser.scala]

class CommandLineParser
extends AnyRef
A utility for parsing GNU-style command-line arguments.

Example usage:

 object Options extends CommandLineParser {
     val exclude = new StringOption('x', "exclude", "Exclude the given file") with AllowAll
     val version = new Flag("version", "Show version info") with AllowNone
     override def helpHeader = """
         |  SomeTool v0.1
         |  (c) 1908 SomeCorp
         |
         |""".stripMargin
 }

 Options.parseOrHelp(argv) { cmd =>
     if(cmd(Options.version)) {
         ...
     }
 }
 
Method Summary
def helpHeader : java.lang.String
Override this to define a header for the help message.
def parse (argv : scala.Array[java.lang.String]) : Bistate[Result, java.lang.String]
Parse the given command line.
def parseOrHelp [A](argv : scala.Array[java.lang.String])(body : (Result) => A) : Bistate[A, java.lang.String]
Parses the command line and shows a help message if parsing fails.
def permitNonOptions : Boolean
Override this to refuse non-option arguments.
def showError (msg : java.lang.String) : Unit
Displays a formatted help message and an error message to stderr.
def showHelp (out : java.io.PrintStream) : Unit
Displays a formatted help message.
Methods inherited from AnyRef
getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Class Summary
trait AllowAll extends OptionSpec
Mix this into an option definition to mark it compatible with every option (including itself).
trait AllowAllBut extends OptionSpec
Mix this in to mark only the specified options as incompatible.
trait AllowAllButSelf extends OptionSpec
Mix this into an option definition to mark it compatible with every option except itself.
trait AllowNone extends OptionSpec
Mix this into an option definition to mark it incompatible with every option.
sealed trait Argument extends AnyRef
Interface for the actual received arguments.
abstract class Flag (val shortName : scala.Option[Char], val longName : java.lang.String, val description : java.lang.String) extends OptionSpec with Argument
Instantiate one of these for each flag-type option.
abstract class IntOption (val shortName : scala.Option[Char], val longName : java.lang.String, val description : java.lang.String) extends OptionType[Int]
An option variant that insists that the parameter is an integer.
case class NonOption (val value : java.lang.String) extends Argument with scala.Product
A received non-option argument.
sealed abstract class OptionSpec extends AnyRef
Superclass of the specifications of permitted options.
abstract class OptionType [A] extends OptionSpec
Superclass of OptionSpecs which accept a parameter.
case class OptionValue [A](val option : OptionType[A], val value : A) extends Argument with scala.Product
An OptionSpec paired with the actual value received.
class Result (val arguments : scala.List[Argument]) extends AnyRef
Parsed representation of the command line.
abstract class StringOption (val shortName : scala.Option[Char], val longName : java.lang.String, val description : java.lang.String) extends OptionType[java.lang.String]
Instantiate one of these for each option taking a parameter.
Method Details
def permitNonOptions : Boolean
Override this to refuse non-option arguments.

def parse(argv : scala.Array[java.lang.String]) : Bistate[Result, java.lang.String]
Parse the given command line.

def helpHeader : java.lang.String
Override this to define a header for the help message.

def parseOrHelp[A](argv : scala.Array[java.lang.String])(body : (Result) => A) : Bistate[A, java.lang.String]
Parses the command line and shows a help message if parsing fails.

def showHelp(out : java.io.PrintStream) : Unit
Displays a formatted help message.

def showError(msg : java.lang.String) : Unit
Displays a formatted help message and an error message to stderr.


Copyright (c) 2005-8 The Scalax Project. All Rights Reserved.