Skip to content

Commit

Permalink
fix: do not send input on :null commands
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedsoupe committed Sep 17, 2023
1 parent bfb8482 commit d85221c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/nexus/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ defmodule Nexus.CLI do

@callback version :: String.t()
@callback banner :: String.t()
@callback handle_input(cmd) :: :ok
when cmd: atom
@callback handle_input(cmd, args) :: :ok
when cmd: atom,
args: list
args: Nexus.Command.Input.t()

@optional_callbacks banner: 0, handle_input: 2
@optional_callbacks banner: 0, handle_input: 2, handle_input: 1

@type t :: map

Expand Down
9 changes: 8 additions & 1 deletion lib/nexus/command_dispatcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ defmodule Nexus.CommandDispatcher do

def dispatch!(%Command{} = spec, raw) do
input = Parser.run!(raw, spec)
spec.module.handle_input(spec.name, input)

case {spec.type, input.value} do
{:null, nil} ->
:ok = spec.module.handle_input(spec.name)

_ ->
:ok = spec.module.handle_input(spec.name, input)
end
end

def dispatch!(module, raw) when is_binary(raw) do
Expand Down

0 comments on commit d85221c

Please sign in to comment.