Skip to content

Commit

Permalink
Merge pull request #60 from olafurpg/repeated
Browse files Browse the repository at this point in the history
Fix  handling of repeated arguments
  • Loading branch information
olafurpg authored Sep 3, 2018
2 parents 0fab6dd + 2c471a8 commit df7eec3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ lazy val `metaconfig-json` = project
allSettings,
libraryDependencies ++= List(
"com.lihaoyi" %%% "ujson" % "0.6.5",
"org.scalameta" %% "testkit" % "3.7.3" % Test
"org.scalameta" %% "testkit" % "4.0.0-M11" % Test
)
)
.dependsOn(`metaconfig-coreJVM`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ class CliParserSuite extends BaseCliParserSuite {
Options(in = "in", out = "out")
)

check(
"repeated",
List("--classpath", "a", "--classpath", "b"),
Options().copy(classpath = List("a", "b"))
)

check(
"kebab",
"--base-url" :: "base-url" :: Nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ object CliParser {
curr: Conf.Obj,
xs: List[String],
s: State): Configured[Conf.Obj] = {
def add(key: String, value: Conf) = Conf.Obj((key, value) :: curr.values)
def add(key: String, value: Conf): Conf.Obj = {
val values = curr.values.filterNot {
case (k, _) => k == key
}
Conf.Obj((key, value) :: values)
}

(xs, s) match {
case (Nil, NoFlag) => ok(curr)
case (Nil, Flag(flag, _)) => ok(add(flag, Conf.fromBoolean(true)))
Expand Down

0 comments on commit df7eec3

Please sign in to comment.