From bc5503bc623f3b863e8e7917b7958949f607ee75 Mon Sep 17 00:00:00 2001 From: "Tj (bougyman) Vanderpoel" Date: Sun, 16 Aug 2026 09:45:52 -0400 Subject: [PATCH] feat(profile): add clear subcommand to deactivate active profile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds `lc profile clear` — a zero-argument command that sets active = 0 for whichever profile is currently active, without deleting it. Safe to call with no active profile (no-op). Co-Authored-By: Claude Sonnet 4.6 --- app/lib/linear_cli/cli.ex | 7 +++++++ app/lib/linear_cli/cli/commands.ex | 7 +++++++ app/lib/linear_cli/profiles.ex | 9 +++++++++ app/test/linear_cli/profiles_test.exs | 24 ++++++++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/app/lib/linear_cli/cli.ex b/app/lib/linear_cli/cli.ex index 7c637a2..d5be26b 100644 --- a/app/lib/linear_cli/cli.ex +++ b/app/lib/linear_cli/cli.ex @@ -192,6 +192,9 @@ defmodule LinearCli.CLI do defp dispatch([:profile, :delete], result, halt), do: run(&Commands.profile_delete/1, result, halt) + defp dispatch([:profile, :clear], result, halt), + do: run(&Commands.profile_clear/1, result, halt) + defp dispatch([:issue, :list], result, halt), do: run(&Commands.issue_list/1, result, halt) defp dispatch([:issue, :create], result, halt), do: run(&Commands.issue_create/1, result, halt) @@ -488,6 +491,10 @@ defmodule LinearCli.CLI do name: "delete", about: "Delete a saved profile", args: [name: [value_name: "NAME", help: "Profile name", required: true]] + ], + clear: [ + name: "clear", + about: "Deactivate the active profile without deleting it" ] ] ], diff --git a/app/lib/linear_cli/cli/commands.ex b/app/lib/linear_cli/cli/commands.ex index 97d752f..ce4ae82 100644 --- a/app/lib/linear_cli/cli/commands.ex +++ b/app/lib/linear_cli/cli/commands.ex @@ -201,6 +201,13 @@ defmodule LinearCli.CLI.Commands do :ok end + @doc "New in this port - Ruby has no equivalent. Deactivates the active profile without deleting it." + def profile_clear(_result) do + Profiles.clear() + Prompt.ok("Cleared active profile") + :ok + end + @doc "New in this port - Ruby has no equivalent. Deletes a saved profile." def profile_delete(%{args: %{name: name}}) do case Profiles.delete(name) do diff --git a/app/lib/linear_cli/profiles.ex b/app/lib/linear_cli/profiles.ex index 75a93f1..eb0a70a 100644 --- a/app/lib/linear_cli/profiles.ex +++ b/app/lib/linear_cli/profiles.ex @@ -93,6 +93,15 @@ defmodule LinearCli.Profiles do end) end + @doc "Clears the active profile - deactivates it without deleting. Always returns `:ok`." + @spec clear() :: :ok + def clear do + with_db(fn conn -> + :ok = exec(conn, "UPDATE profiles SET active = 0", []) + :ok + end) + end + @doc "Deletes the named profile. `{:error, :not_found}` if no such profile exists." @spec delete(String.t()) :: :ok | {:error, :not_found} def delete(name) do diff --git a/app/test/linear_cli/profiles_test.exs b/app/test/linear_cli/profiles_test.exs index 0136890..3b661b8 100644 --- a/app/test/linear_cli/profiles_test.exs +++ b/app/test/linear_cli/profiles_test.exs @@ -89,6 +89,30 @@ defmodule LinearCli.ProfilesTest do end end + describe "clear/0" do + test "deactivates the active profile without deleting it" do + {:ok, _} = Profiles.create("manhattan", team: "CRY", project: "Manhattan") + :ok = Profiles.activate("manhattan") + + assert :ok = Profiles.clear() + assert Profiles.active() == nil + assert [%Profile{name: "manhattan", active: false}] = Profiles.list() + end + + test "is a no-op when no profile is active" do + {:ok, _} = Profiles.create("manhattan") + + assert :ok = Profiles.clear() + assert Profiles.active() == nil + assert [%Profile{name: "manhattan"}] = Profiles.list() + end + + test "is a no-op when no profiles exist" do + assert :ok = Profiles.clear() + assert Profiles.active() == nil + end + end + describe "default_team/0 and default_project/0" do test "nil with no active profile" do assert Profiles.default_team() == nil