Advertisement
Guest User

Untitled

a guest
Jan 21st, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.77 KB | None | 0 0
  1. package trial
  2.  
  3. // These are some basic imports for Args4j
  4. import org.kohsuke.args4j.CmdLineException
  5. import org.kohsuke.args4j.CmdLineParser
  6. import org.kohsuke.args4j.{ Option => Args4jOption, Argument } // => renames Option class for clarity
  7.  
  8.  
  9. object helper {
  10.  
  11.   class Options {
  12.     /*
  13.      *  This class is simply a container that holds our options
  14.      */
  15.     @Argument(required = false, metaVar = "INPUT1", usage = "The first ADAM file to compare", index = 0)
  16.     val input1Path: String = null
  17.    
  18.     @Args4jOption(name = "--help", aliases = Array("-h"), usage = "show this message")
  19.     var help = false
  20.  
  21.     @Args4jOption(name = "--count", aliases = Array("-c"), depends=Array("INPUT1"), usage = "some val", metaVar = "BLAH")
  22.     var count: Int = 0
  23.  
  24.     @Args4jOption(name = "--taco", aliases = Array("-t"), usage = "Required Test Taco", metaVar = "TACO")
  25.     var taco = false
  26.   }
  27.  
  28.   def main(args: Array[String]) {
  29.     val options = new Options // Defines an object from our Options class (could be named anything)
  30.     val parser = new CmdLineParser(options) // Define a parser object from the options objects
  31.  
  32.     println("Test Print")
  33.  
  34.     try {
  35.       parser.parseArgument(args: _*) // This line culls the arguments.
  36.  
  37.       if (options.count != 0) println("You've chosen a new # of Tacos: " + options.count)
  38.       if (options.taco) println("You've opted for TACOS! Taco=" + options.taco)
  39.  
  40.       if (options.help) {
  41.         parser.printUsage(System.err)
  42.         //println("You Wanted help!")
  43.         sys.exit(0)
  44.       }
  45.     } catch {
  46.       case e: CmdLineException => {
  47.         println("Option Entered Incorrectly by User: ")
  48.         System.err.println(e.getMessage)
  49.         parser.printUsage(System.err)
  50.         sys.exit(1)
  51.       }
  52.     }
  53.   }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement