• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
scala0.cmdline
 

scala0.cmdline

on

  • 654 views

Boston Area Scala Enthusiasts second meeting held on Dec 2, 2009.

Boston Area Scala Enthusiasts second meeting held on Dec 2, 2009.
Talk delivered by Jeremy Cloud.

Statistics

Views

Total Views
654
Views on SlideShare
653
Embed Views
1

Actions

Likes
0
Downloads
4
Comments
0

1 Embed 1

http://www.slideshare.net 1

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    scala0.cmdline scala0.cmdline Presentation Transcript

    • jeremy.cloud { • ~2 years professional development with Scala • freelance software developer / web designer -- hire me! • jeremy.cloud@me.com } Friday, December 4, 2009
    • Friday, December 4, 2009
    • scala0.cmdline: • distinct command-line modes • support complex dependencies between options • validation using typed failures so you can customize error messages • generates nicely formatted usage message • short and/or long names • dependency free Friday, December 4, 2009
    • distinct command-line modes foo -v foo -? foo -c [-f num] filenames... foo [-d dir] [-l limit] filename command-line parser will tell you which variation is being used Friday, December 4, 2009
    • dependencies between options if a then b: foo [-a blah -b bleh] b only if a: foo [-a blah [-b bleh]] one of a, b, c: foo (-a blah | -b bleh | -c) arbitrarily nested: foo [-a (-b | -c -d)] Friday, December 4, 2009
    • uses internal DSL object Options extends CommandLineParser { val version = Flag("v", "version", "Print version and quit") val help = Flag("?", "help", "Print help and quit") val a = Flag("a", None, "A") val b = Flag("b", None, "B") val c = Flag("c", None, "C") val d = Flag("d", None, "D") val filename = NakedArgument("filename", "The name of the file") val versionMode = %(version) val helpMode = %(help) val defaultMode = %((a ~ (b | c ~ d)).?, filename) val spec = %%(versionMode, helpMode, defaultMode) } Friday, December 4, 2009
    • mode and error matching def main(args: Array[String]) { Options(args) match { case Left(error) => Console.err.println(error) Options.printHelp("foo") case Right((Options.versionMode, _)) => Console.out.println("Version 1.0") case Right((Options.helpMode, _)) => Options.printHelp("foo") case Right((Options.defaultMode, cmdLine)) => val isA = cmdLine(Options.a) val filename = cmdLine(Options.filename).head // do something... } } Friday, December 4, 2009
    • generates nice help messages USAGE: foo -v foo -? foo [-a (-b | -c -d)] filename OPTIONS: -?, --help Print help and quit -a, --accelerator enable accelerator -b, --blaster use blaster -c, --cool make it cool -d, --dump dumb it down -v, --version Print version and quit Friday, December 4, 2009
    • http://scala0.net thank you Friday, December 4, 2009