Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/lib/linear_cli/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"
]
]
],
Expand Down
7 changes: 7 additions & 0 deletions app/lib/linear_cli/cli/commands.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions app/lib/linear_cli/profiles.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions app/test/linear_cli/profiles_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down