A scala command line parser
Scala
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
project
src
.gitignore
LICENSE
README

README

A command-line parser for scala that supports complex command-line-argument grammars.

An Expample:

object MyApplication {
    object Options extends CommandLineParser {
        val version = Flag("v", "version", "Print version number and quit")
        val help = Flag("?", "help", "Print help and quit")
        val dir = StringOption("d", "dir", "dir", "output directory")
        val filename = NakedArgument("filename", "The name of the file")
        val versionMode = %(version)
        val helpMode = %(help)
        val filenameMode = %(dir?, filename)
        val spec = %%(versionMode, helpMode, filenameMode)
    }

    def main(args: Array[String]) {
        Options(args) match {
            case Left(error) =>
                Console.err.println(error)
                Options.printHelp("MyApplication")

            case Right((Options.versionMode, _)) =>
                Console.out.println("Version 1.0")

            case Right((Options.helpMode, _)) =>
                Options.printHelp("MyApplication")
                
            case Right((Options.filenameMode, cmdLine)) =>
                val dir = cmdLine(Options.dir).getOrElse(".")
                val filename = cmdLine(Options.filename).head
                // do something...
        }
    }
}