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

@@ -3,8 +3,8 @@ defmodule BDS.UI.SettingsForm do
Renderer-agnostic preferences forms (issue #29).
Exposes each settings section of the GUI settings editor as a flat list
of typed fields (`:text`, `:bool`, `:enum`, `:info`) that the TUI can
render and edit generically. `save/3` writes through the same backends
of typed fields (`:text`, `:bool`, `:enum`, `:info`, `:action`) that the
TUI can render and edit generically. `save/3` writes through the same backends
as the GUI editor — `BDS.Metadata`, `BDS.Settings`, `BDS.AI` and
`BDS.MCP.AgentConfig` — so both frontends operate on the same
preferences.
@@ -28,7 +28,7 @@ defmodule BDS.UI.SettingsForm do
@type field :: %{
key: String.t(),
label: String.t(),
type: :text | :bool | :enum | :info,
type: :text | :bool | :enum | :info | :action,
value: term(),
options: [String.t()]
}
@@ -217,6 +217,11 @@ defmodule BDS.UI.SettingsForm do
"data_hint",
dgettext("ui", "Maintenance"),
dgettext("ui", "Rebuild and maintenance commands are available under the : prompt.")
),
action(
"install_cli",
dgettext("ui", "Command Line Tool"),
dgettext("ui", "Install CLI Tool")
)
])
end
@@ -351,6 +356,28 @@ defmodule BDS.UI.SettingsForm do
def save(_section, _project_id, _values), do: :ok
# ── Actions ──────────────────────────────────────────────────────────────
@doc """
Runs an `:action` field (issue #25) and returns a localized result
message for the invoking frontend (GUI toast or TUI status line).
"""
@spec run_action(String.t()) :: {:ok, String.t()} | {:error, String.t()}
def run_action("install_cli") do
case BDS.CLI.Install.install() do
{:ok, path} ->
{:ok, dgettext("ui", "CLI tool installed to %{path}", path: path)}
{:error, :no_release} ->
{:error, dgettext("ui", "The CLI tool can only be installed from the packaged application")}
{:error, reason} ->
{:error, dgettext("ui", "Installing the CLI tool failed: %{reason}", reason: inspect(reason))}
end
end
def run_action(_key), do: {:error, dgettext("ui", "Unknown settings action")}
# ── Helpers ──────────────────────────────────────────────────────────────
defp form(section, title, fields), do: %{section: section, title: title, fields: fields}
@@ -367,6 +394,9 @@ defmodule BDS.UI.SettingsForm do
defp info(key, label, value),
do: %{key: key, label: label, type: :info, value: value, options: []}
defp action(key, label, caption),
do: %{key: key, label: label, type: :action, value: caption, options: []}
defp editor_settings do
%{
"default_mode" => Settings.get_global_setting("ui.preferred_editor_mode") || "markdown",