From d85221c9bc8ac7f0b39b4a7deeaed283e53232bc Mon Sep 17 00:00:00 2001 From: Zoey de Souza Pessanha Date: Sun, 17 Sep 2023 15:25:50 -0300 Subject: [PATCH] fix: do not send input on :null commands --- lib/nexus/cli.ex | 6 ++++-- lib/nexus/command_dispatcher.ex | 9 ++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/nexus/cli.ex b/lib/nexus/cli.ex index 7266b79..6ac7d43 100644 --- a/lib/nexus/cli.ex +++ b/lib/nexus/cli.ex @@ -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 diff --git a/lib/nexus/command_dispatcher.ex b/lib/nexus/command_dispatcher.ex index 461bcf1..be740d1 100644 --- a/lib/nexus/command_dispatcher.ex +++ b/lib/nexus/command_dispatcher.ex @@ -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