Skip to content

Commit

Permalink
Report an error if using foreground flag outside of --notty mode
Browse files Browse the repository at this point in the history
  • Loading branch information
bitspittle committed Oct 7, 2024
1 parent ec72b42 commit 473305f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion kobweb/src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import com.github.ajalt.clikt.core.Abort
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.CoreCliktCommand
import com.github.ajalt.clikt.core.ParameterHolder
import com.github.ajalt.clikt.core.UsageError
import com.github.ajalt.clikt.core.context
import com.github.ajalt.clikt.core.main
import com.github.ajalt.clikt.core.subcommands
import com.github.ajalt.clikt.output.Localization
import com.github.ajalt.clikt.output.ParameterFormatter
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.optional
import com.github.ajalt.clikt.parameters.groups.mutuallyExclusiveOptions
Expand Down Expand Up @@ -241,7 +245,7 @@ fun main(args: Array<String>) {
val foreground by option(
"-f",
"--foreground",
help = "Keep kobweb running in the foreground. This value is ignored unless in --notty mode."
help = "Keep kobweb running in the foreground. This value can only be specified in --notty mode."
).flag(default = false)
val layout by layout()
val path by path()
Expand All @@ -251,6 +255,13 @@ fun main(args: Array<String>) {

override fun shouldCheckForUpgrade() = ttyMode.shouldUseAnsi()
override fun doRun() {
if (foreground && ttyMode != TeleTypeMode.DISABLED) {
throw object : UsageError(null) {
override fun formatMessage(localization: Localization, formatter: ParameterFormatter): String {
return "The foreground flag is only valid when running in ${formatter.formatOption("--notty")} mode."
}
}
}
handleRun(
env,
path,
Expand Down

0 comments on commit 473305f

Please sign in to comment.