Skip to content

Commit 8ffbf3b

Browse files
committed
Settings: move fromCliArgs into class
Otherwise, we could inadvertently completely override all settings instead of modifying them.
1 parent 3fd6737 commit 8ffbf3b

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

cli/src/main/scala/mdoc/internal/cli/Settings.scala

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,18 @@ case class Settings(
247247
cwd = dir
248248
)
249249
}
250+
251+
def withCliArgs(args: List[String]): Configured[Settings] = {
252+
Conf.parseCliArgs[Settings](args).andThen { conf =>
253+
val propsFile = conf.get[String]("propertyFileName").getOrElse("mdoc.properties")
254+
val base = conf.get[String]("cwd").map { x =>
255+
implicit val defaultCwd: AbsolutePath = this.cwd
256+
withWorkingDirectory(AbsolutePath(x))
257+
}.getOrElse(this).withPropertiesFromFile(propsFile)
258+
conf.as[Settings](Settings.decoder(base)).map(_.addSite(base.site))
259+
}
260+
}
261+
250262
}
251263

252264
object Settings { // extends MetaconfigScalametaImplicits with Decoders with SettingsGeneric {
@@ -306,20 +318,8 @@ object Settings { // extends MetaconfigScalametaImplicits with Decoders with Set
306318
generic.deriveDecoder[Settings](base)
307319
}
308320

309-
def fromCliArgs(args: List[String], workingDirectory: => AbsolutePath): Configured[Settings] = {
310-
Conf
311-
.parseCliArgs[Settings](args)
312-
.andThen { conf =>
313-
implicit val defaultCwd: AbsolutePath = workingDirectory
314-
val base = Settings(
315-
conf.get[String]("cwd").map(AbsolutePath(_)).getOrElse(defaultCwd),
316-
conf.get[String]("propertyFileName").getOrElse("mdoc.properties")
317-
)
318-
conf
319-
.as[Settings](decoder(base))
320-
.map(_.addSite(base.site))
321-
}
322-
}
321+
def fromCliArgs(args: List[String], workingDirectory: AbsolutePath): Configured[Settings] =
322+
Settings(workingDirectory).withCliArgs(args)
323323

324324
def fromCliArgs(args: List[String], workingDirectory: Path): Configured[Settings] =
325325
fromCliArgs(args, AbsolutePath(workingDirectory))

mdoc/src/main/scala/mdoc/MainSettings.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ final class MainSettings private (
2323
def withArgs(args: List[String]): MainSettings = {
2424
if (args.isEmpty) this
2525
else {
26-
Settings.fromCliArgs(args, settings.cwd.toNIO) match {
26+
settings.withCliArgs(args) match {
2727
case Configured.Ok(newSettings) =>
28-
copy(settings = newSettings)
28+
if (newSettings eq settings) this else copy(settings = newSettings)
2929
case Configured.NotOk(error) =>
3030
throw new IllegalArgumentException(error.toString())
3131
}

0 commit comments

Comments
 (0)