Scopt not recognizing options?

525 views
Skip to first unread message

Amr Abouelleil

unread,
Sep 2, 2016, 12:48:22 PM9/2/16
to scala-user
Hi There,

I'm new to both Scala and Java so please forgive me if this question is very noobish. I'm getting familiar with the scopt library and for some reason, I am getting the following error:

Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: --inputFile

Process finished with exit code 1

I ran the code below (through Intellij) with the following arguments (--inputFile foobar.txt --headerRow 1 --llastRow 10 --delimiter "\t"). When I run it with --help or with no arguments/options it behaves as expected. 

My scala code is as follows. Any help appreciated!


package org.broadinstitute.parsomatic
import java.io.File

/**
  * Created by amr on 9/1/2016.
  */

object Parsomatic extends App {
  def parser = {
    new scopt.OptionParser[Config]("Parsomatic") {
      head("Parsomatic", "1.0")
      opt[File]('i', "inputFile").valueName("<file>").required().action((x, c) => c.copy(inputFile = x))
        .text("Path to input file to parse. Required.")
      opt[Int]('h', "headerRow").valueName("<int>").action((x, c) => c.copy(headerRow = x))
        .text("Header row in file. Default = 1.")
      opt[Int]('l', "lastRow").valueName("<int>").optional().action((x, c) => c.copy(lastRow = x))
        .text("Last row of data to parse. If unspecified, will end parse all lines after headerRow.")
      opt[String]('s', "startKey").valueName("<string>").optional().action((x, c) => c.copy(startKey = x))
        .text("A key string to indicate header row. Must begin with first character of line.")
      opt[String]('e', "endKey").valueName("<string>").optional().action((x, c) => c.copy(endKey = x))
        .text("A string to indicate last row of data. Must begin with first character of line.")
      opt[String]('d', "delimiter").valueName("<char>").required().action((x, c) => c.copy(delimiter = x))
        .text("Delimiter used to separate values in file. Use '\\t' for tabs. Required.")
      help("help").text("Prints this help text.")
      note("\nA tool for parsing data files into MD objects.\n")
    }
  }
  private def failureExit(msg: String) {
    println("\nFATAL ERROR: " + msg)
    System.exit(1)
  }

  parser.parse(args, Config(inputFile = new File("NA.tmp"), lastRow = 0, headerRow = 1, startKey = "foo", endKey = "bar", delimiter = "\t")) match {
    // Command line arguments are valid - go execute them
    case Some(config) => println(config.inputFile.toString)
    case None => failureExit("Please provide valid input.")
  }
}

Eike

unread,
Sep 2, 2016, 5:28:12 PM9/2/16
to Amr Abouelleil, scala-user

Hello,

to me it seems as if you specify these options to the java/scala
executable instead of to your program.

Can you check your run configuration in IntelliJ and see where you
declared these arguments? It should be “Program arguments” and not “VM
options”.

kind regards
Eike
--
gpg: AD7AC35E
finger print: 137F BB0B 1639 D25F DC5D E59C B412 C5F5 AD7A C35E

Lanny Ripple

unread,
Sep 3, 2016, 3:14:13 PM9/3/16
to scala-user, a...@broadinstitute.org, ei...@eknet.org
Following up on Eike's post I'm pretty sure you want 'Run' > 'Edit Configurations...' > '+' > 'Application'.
Reply all
Reply to author
Forward
0 new messages