     }
 }
 
-func usage() {
-    println("usage: spam [install|uninstall|compile]")
-    println("")
-    println("Specify a package with \"import Module // username/module\".")
+// MARK: entry point
+
+let cli = CommandLine()
+let installOption = BoolOption(shortFlag: "i", longFlag: "install", helpMessage:
+          "Download all imported modules. For spam to detect the module's URL, it must be\n" +
+    "      specified in the following manner:\n" +
+    "          import ModuleName // username/ModuleName\n" +
+    "      This will automatically clone the module from github.com/username/ModuleName.")
+let compileOption = BoolOption(shortFlag: "c", longFlag: "compile",
+    helpMessage: "Compile downloaded modules and local sources.")
+let outputOption = StringOption(shortFlag: "o", longFlag: "output", required: false,
+    helpMessage: "Write output to <file>.")
+let uninstallOption = BoolOption(shortFlag: "u", longFlag: "uninstall",
+    helpMessage: "Completely remove the .spam directory.")
+let helpOption = BoolOption(shortFlag: "h", longFlag: "help",
+    helpMessage: "Display this help message and exit.")
+cli.addOptions(installOption, compileOption, outputOption, uninstallOption, helpOption)
+
+let (success, error) = cli.parse()
+if (!success) {
+    println(error!)
+    cli.printUsage()
+    exit(EX_USAGE)
 }
 
-// MARK: entry point
-
-if contains(Process.arguments, "install") || contains(Process.arguments, "i") {
+if installOption.value {
     install()
-} else if contains(Process.arguments, "uninstall") || contains(Process.arguments, "u") {
+} else if uninstallOption.value {
     uninstall()
-} else if contains(Process.arguments, "compile") || contains(Process.arguments, "c") {
-    compile()
+} else if compileOption.value {
+    compile(outputFile: outputOption.value)
 } else {
-    usage()
+    cli.printUsage()
+    exit(EX_USAGE)
 }

import Foundation

let spamDirectory = ".spam"
let swiftc = "xcrun -sdk macosx swiftc"

    call("rm -rf \(spamDirectory)")
}

func compile(#outputFile: String?) {
    if let sourceFiles = filesOfType("swift", atPath: ".") {
        var modules = [Module]()
        for file in split(sourceFiles, isSeparator: { $0 == " " }) {
