Skip to content

Commit 45cce6f

Browse files
bougymanclaude
andauthored
feat(profile): add profile clear command (#120)
## Summary - Adds `lc profile clear` — a zero-argument command that deactivates the currently active profile without deleting it - Useful for "parking" a profile when no team/project default is wanted, without losing the saved bundle - Safe to call with no active profile (no-op); always returns `:ok` ## Changes - `LinearCli.Profiles.clear/0`: single `UPDATE profiles SET active = 0` statement, no transaction needed - `LinearCli.CLI`: Optimus subcommand spec for `clear` (no args) + dispatch clause `[:profile, :clear]` - `LinearCli.CLI.Commands.profile_clear/1`: calls `Profiles.clear()` and prints confirmation - 3 new unit tests covering: deactivates active profile, no-op with no active profile, no-op with no profiles ## Test plan - [x] `mix test` passes (3 new `clear/0` tests all pass; only pre-existing git env failures remain) - [x] `mix compile --warnings-as-errors` clean - [x] `lc profile clear` clears the active profile - [x] `lc profile clear` with no active profile prints confirmation without error Closes https://linear.app/cryptokairos/issue/CRY-46/featprofile-deactivate-a-profile-without-deleting-it 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c61d842 commit 45cce6f

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎app/lib/linear_cli/cli.ex‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ defmodule LinearCli.CLI do
192192
defp dispatch([:profile, :delete], result, halt),
193193
do: run(&Commands.profile_delete/1, result, halt)
194194

195+
defp dispatch([:profile, :clear], result, halt),
196+
do: run(&Commands.profile_clear/1, result, halt)
197+
195198
defp dispatch([:issue, :list], result, halt), do: run(&Commands.issue_list/1, result, halt)
196199
defp dispatch([:issue, :create], result, halt), do: run(&Commands.issue_create/1, result, halt)
197200

@@ -488,6 +491,10 @@ defmodule LinearCli.CLI do
488491
name: "delete",
489492
about: "Delete a saved profile",
490493
args: [name: [value_name: "NAME", help: "Profile name", required: true]]
494+
],
495+
clear: [
496+
name: "clear",
497+
about: "Deactivate the active profile without deleting it"
491498
]
492499
]
493500
],

‎app/lib/linear_cli/cli/commands.ex‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ defmodule LinearCli.CLI.Commands do
201201
:ok
202202
end
203203

204+
@doc "New in this port - Ruby has no equivalent. Deactivates the active profile without deleting it."
205+
def profile_clear(_result) do
206+
Profiles.clear()
207+
Prompt.ok("Cleared active profile")
208+
:ok
209+
end
210+
204211
@doc "New in this port - Ruby has no equivalent. Deletes a saved profile."
205212
def profile_delete(%{args: %{name: name}}) do
206213
case Profiles.delete(name) do

‎app/lib/linear_cli/profiles.ex‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ defmodule LinearCli.Profiles do
9393
end)
9494
end
9595

96+
@doc "Clears the active profile - deactivates it without deleting. Always returns `:ok`."
97+
@spec clear() :: :ok
98+
def clear do
99+
with_db(fn conn ->
100+
:ok = exec(conn, "UPDATE profiles SET active = 0", [])
101+
:ok
102+
end)
103+
end
104+
96105
@doc "Deletes the named profile. `{:error, :not_found}` if no such profile exists."
97106
@spec delete(String.t()) :: :ok | {:error, :not_found}
98107
def delete(name) do

‎app/test/linear_cli/profiles_test.exs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,30 @@ defmodule LinearCli.ProfilesTest do
8989
end
9090
end
9191

92+
describe "clear/0" do
93+
test "deactivates the active profile without deleting it" do
94+
{:ok, _} = Profiles.create("manhattan", team: "CRY", project: "Manhattan")
95+
:ok = Profiles.activate("manhattan")
96+
97+
assert :ok = Profiles.clear()
98+
assert Profiles.active() == nil
99+
assert [%Profile{name: "manhattan", active: false}] = Profiles.list()
100+
end
101+
102+
test "is a no-op when no profile is active" do
103+
{:ok, _} = Profiles.create("manhattan")
104+
105+
assert :ok = Profiles.clear()
106+
assert Profiles.active() == nil
107+
assert [%Profile{name: "manhattan"}] = Profiles.list()
108+
end
109+
110+
test "is a no-op when no profiles exist" do
111+
assert :ok = Profiles.clear()
112+
assert Profiles.active() == nil
113+
end
114+
end
115+
92116
describe "default_team/0 and default_project/0" do
93117
test "nil with no active profile" do
94118
assert Profiles.default_team() == nil

0 commit comments

Comments
 (0)