Skip to content

Commit

Permalink
fix: honor --yes or -y option when adding a satsolver
Browse files Browse the repository at this point in the history
chore: dialyzer specs for read_one
  • Loading branch information
zachdaniel committed Oct 7, 2024
1 parent 573cc08 commit 926158e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/ash.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2023,7 +2023,7 @@ defmodule Ash do
"""
@doc spark_opts: [{1, @read_one_opts_schema}]
@spec read_one(resource_or_query :: Ash.Query.t() | Ash.Resource.t(), opts :: Keyword.t()) ::
Ash.Resource.record() | nil
Ash.Resource.record() | nil
def read_one!(query, opts \\ []) do
Ash.Helpers.expect_resource_or_query!(query)
Ash.Helpers.expect_options!(opts)
Expand Down Expand Up @@ -2052,7 +2052,7 @@ defmodule Ash do
"""
@doc spark_opts: [{1, @read_one_opts_schema}]
@spec read_one(resource_or_query :: Ash.Query.t() | Ash.Resource.t(), opts :: Keyword.t()) ::
{:ok, Ash.Resource.record() | nil} | {:error, Ash.Error.t()}
{:ok, Ash.Resource.record() | nil} | {:error, Ash.Error.t()}
def read_one(query, opts \\ []) do
Ash.Helpers.expect_options!(opts)
Ash.Helpers.expect_resource_or_query!(query)
Expand Down
30 changes: 18 additions & 12 deletions lib/ash/policy/authorizer/authorizer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -528,24 +528,30 @@ defmodule Ash.Policy.Authorizer do
)
end

def install(igniter, module, type, _path, _argv) do
def install(igniter, module, type, _path, argv) do
yes = "--yes" in argv or "-y" in argv

igniter =
with nil <- Igniter.Project.Deps.get_dependency_declaration(igniter, :picosat_elixir),
nil <- Igniter.Project.Deps.get_dependency_declaration(igniter, :simple_sat) do
solver =
Owl.IO.select(
[
{:picosat_elixir, "~> 0.2"},
{:simple_sat, "~> 0.1"}
],
label:
"Ash.Policy.Authorizer requires a sat solver. Which would you like to use? If on windows, use `simple_sat`, otherwise, use `picosat_elixir`.",
render_as: &to_string(elem(&1, 0))
)
if yes do
{:picosat_elixir, "~> 0.2"}
else
Owl.IO.select(
[
{:picosat_elixir, "~> 0.2"},
{:simple_sat, "~> 0.1"}
],
label:
"Ash.Policy.Authorizer requires a sat solver. Which would you like to use? If on windows, use `simple_sat`, otherwise, use `picosat_elixir`.",
render_as: &to_string(elem(&1, 0))
)
end

igniter
|> Igniter.Project.Deps.add_dep(solver)
|> Igniter.apply_and_fetch_dependencies()
|> Igniter.Project.Deps.add_dep(solver, yes?: yes)
|> Igniter.apply_and_fetch_dependencies(yes: yes)
else
_ ->
igniter
Expand Down

0 comments on commit 926158e

Please sign in to comment.