package textapp


class CommandLineArgumentProcessor(args: Array[String]) {
  def getParam(longName: String, shortName: String): Option[String] = {
    val longFormat = "--%s".format(longName)
    val shortFormat = "-%s".format(shortName)

    val paramsWithValues = argPairs.flatMap { case (first, second) =>
      if (first == longFormat || first == shortFormat) {
        if (!isParam(second)) Some(second)
        else None
      }
      else None
    }.toList

    val paramsWithoutValues = args.flatMap { arg =>
      if (arg == longFormat || arg == shortFormat) Some("")
      else None
    }.toList
    (paramsWithValues ::: paramsWithoutValues).headOption
  }

  private def argPairs = args.zip(args.drop(1))
  private def isParam(s: String) = s.startsWith("-")
}
package textapp


class CommandLineArgumentProcessor(args: Array[String]) {
  def getParam(longName: String, shortName: String): Option[String] = {
    val longFormat = "--%s".format(longName)
    val shortFormat = "-%s".format(shortName)

    val paramsWithValues = argPairs.flatMap { case (first, second) =>
      if (first == longFormat || first == shortFormat) {
        if (!isParam(second)) Some(second)
        else None
      }
      else None
    }.toList

    val paramsWithoutValues = args.flatMap { arg =>
      if (arg == longFormat || arg == shortFormat) Some("")
      else None
    }.toList
    (paramsWithValues ::: paramsWithoutValues).firstOption
  }

  private def argPairs = args.zip(args.drop(1))
  private def isParam(s: String) = s.startsWith("-")
}
--- 
+++ 
@@ -18,7 +18,7 @@
       if (arg == longFormat || arg == shortFormat) Some("")
       else None
     }.toList
-    (paramsWithValues ::: paramsWithoutValues).firstOption
+    (paramsWithValues ::: paramsWithoutValues).headOption
   }
 
   private def argPairs = args.zip(args.drop(1))
Replace deprecated firstOption with headOption

Signed-off-by: Sami Rosendahl <b33c757bb777642ab0d59c699f8d5782929a814f@reaktor.fi>
Signed-off-by: Antti Mattila <422fa99ecc9af171a83eb3d69d51885324be22a3@reaktor.fi>
Acked-by: Aki Saarinen <2c8035bb80cf98a391872dcbe797b269d759f6d9@reaktor.fi>
