feat: issue #25 implemented - cli

This commit is contained in:
2026-07-17 14:26:14 +02:00
parent e4fa61ae07
commit 0f3f1efa08
24 changed files with 2899 additions and 873 deletions

View File

@@ -13,15 +13,18 @@ defmodule BDS.Server do
@doc """
Resolves the boot mode from the `BDS_MODE` environment variable:
`"server"` (headless + SSH daemon), `"tui"` (headless + SSH daemon +
a TUI attached to the launching terminal), anything else is desktop.
a TUI attached to the launching terminal), `"cli"` (headless one-shot
command run — no SSH daemon, no HTTP listener, no watcher; issue #25),
anything else is desktop.
"""
@spec mode(String.t() | nil) :: :desktop | :server | :tui
@spec mode(String.t() | nil) :: :desktop | :server | :tui | :cli
def mode(value \\ System.get_env("BDS_MODE"))
def mode(value) when is_binary(value) do
case String.downcase(value) do
"server" -> :server
"tui" -> :tui
"cli" -> :cli
_other -> :desktop
end
end
@@ -41,9 +44,9 @@ defmodule BDS.Server do
signal and a local launch always has a graphical session. Windows always
boots the GUI.
"""
@spec effective_mode(:desktop | :server | :tui, {atom(), atom()}, %{
@spec effective_mode(:desktop | :server | :tui | :cli, {atom(), atom()}, %{
optional(String.t()) => String.t()
}) :: :desktop | :server | :tui
}) :: :desktop | :server | :tui | :cli
def effective_mode(mode \\ mode(), os_type \\ :os.type(), env \\ System.get_env())
def effective_mode(:desktop, {:unix, :darwin}, env) do
@@ -79,11 +82,14 @@ defmodule BDS.Server do
Called from `config/runtime.exs`: runtime config is the only hook that
runs before dependency applications start, in both `mix run` and releases.
"""
@spec prepare_boot_env(:desktop | :server | :tui, (-> :ok)) :: :desktop | :server | :tui
@spec prepare_boot_env(:desktop | :server | :tui | :cli, (-> :ok)) ::
:desktop | :server | :tui | :cli
def prepare_boot_env(mode \\ effective_mode(), redirect_logs \\ &redirect_logging_to_file/0) do
if mode != :desktop, do: System.put_env("NO_WX", "1")
if mode == :tui do
# CLI mode owns stdout for command output the same way the local TUI owns
# the terminal: console logging goes to the rotating file instead.
if mode in [:tui, :cli] do
Application.put_env(:bumblebee, :progress_bar_enabled, false)
redirect_logs.()
end
@@ -138,7 +144,7 @@ defmodule BDS.Server do
and clients arrive through the key-authenticated SSH tunnel, which the
per-boot webview token would otherwise lock out.
"""
@spec desktop_auth_required?(:desktop | :server | :tui) :: boolean()
@spec desktop_auth_required?(:desktop | :server | :tui | :cli) :: boolean()
def desktop_auth_required?(mode \\ effective_mode())
def desktop_auth_required?(:desktop), do: true
def desktop_auth_required?(_mode), do: false