Skip to content

Commit

Permalink
Change "headless" option to "mode"
Browse files Browse the repository at this point in the history
After thinking about it, it's not *really* headless, not necessarily.

I would have called it "interactive" and made it a boolean, but that
would imply kobweb commands are non-interactive by default, which
isn't right.
  • Loading branch information
bitspittle committed Dec 4, 2021
1 parent 8bf70e4 commit 45ee420
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions cli/kobweb/src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@ import kotlinx.cli.ExperimentalCli
import kotlinx.cli.Subcommand
import kotlinx.cli.default

private fun ArgParser.headlessOption() = option(
ArgType.Boolean,
fullName = "headless",
description = "If true, allow user interaction / use colors and animations. Else, restrict to simple console logging",
).default(false)
private enum class Mode {
/** Expect a user at an ANSI-enabled terminal interacting with the command */
INTERACTIVE,

/** Expect the command to run in a constrained environment, e.g. a server, without user interaction */
DUMB
}

private fun ArgParser.mode() = option(
ArgType.Choice<Mode>(),
fullName = "mode",
shortName = "m",
description = "If interactive, runs in an ANSI-enabled terminal expecting user input. If dumb, command only outputs, using simple console logging",
).default(Mode.INTERACTIVE)

@ExperimentalCli
fun main(args: Array<String>) {
Expand Down Expand Up @@ -53,19 +62,19 @@ fun main(args: Array<String>) {
}

class Export : Subcommand("export", "Generate a static version of a Kobweb app / site") {
val isHeadless by headlessOption()
val mode by mode()

override fun execute() {
handleExport(!isHeadless)
handleExport(mode == Mode.INTERACTIVE)
}
}

class Run : Subcommand("run", "Run a Kobweb server") {
val env by option(ArgType.Choice<ServerEnvironment>(), "env").default(ServerEnvironment.DEV)
val isHeadless by headlessOption()
val mode by mode()

override fun execute() {
handleRun(env, !isHeadless)
handleRun(env, mode == Mode.INTERACTIVE)
}
}

Expand Down

0 comments on commit 45ee420

Please sign in to comment.