Skip to content

Commit

Permalink
Add guards to prevent commandline accidents from propagating
Browse files Browse the repository at this point in the history
  • Loading branch information
fhunleth committed May 9, 2023
1 parent 7432023 commit 3e8fc1c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions lib/ring_logger/autoclient.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule RingLogger.Autoclient do
Attach to the logger and print messages as they come in.
"""
@spec attach(RingLogger.client_options()) :: :ok | {:error, term()}
def attach(opts \\ []) do
def attach(opts \\ []) when is_list(opts) do
run(&Client.attach/1, opts)
end

Expand Down Expand Up @@ -54,31 +54,31 @@ defmodule RingLogger.Autoclient do
Print the log messages since the previous time this was called.
"""
@spec next(RingLogger.client_options()) :: :ok | {:error, term()}
def next(opts \\ []) do
def next(opts \\ []) when is_list(opts) do
run(&Client.next(&1, opts), opts)
end

@doc """
Print the log message count since the previous time this was called.
"""
@spec count_next(RingLogger.client_options()) :: non_neg_integer()
def count_next(opts \\ []) do
def count_next(opts \\ []) when is_list(opts) do
run(&Client.count_next/1, opts)
end

@doc """
Print the most recent log messages.
"""
@spec tail(non_neg_integer(), RingLogger.client_options()) :: :ok
def tail(n, opts) do
def tail(n, opts) when is_integer(n) and is_list(opts) do
run(&Client.tail(&1, n, opts), opts)
end

@doc """
Run a regular expression on each entry in the log and print out the matchers.
"""
@spec grep(String.t() | Regex.t(), RingLogger.client_options()) :: :ok | {:error, term()}
def grep(regex_or_string, opts \\ []) do
def grep(regex_or_string, opts \\ []) when is_list(opts) do
run(&Client.grep(&1, regex_or_string, opts), opts)
end

Expand All @@ -87,7 +87,7 @@ defmodule RingLogger.Autoclient do
that the next call to `tail/1` starts back at the oldest entry.
"""
@spec reset(RingLogger.client_options()) :: :ok | {:error, term()}
def reset(opts \\ []) do
def reset(opts \\ []) when is_list(opts) do
run(&Client.reset/1, opts)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ring_logger/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ defmodule RingLogger.Client do
will take precedence.
"""
@spec configure(GenServer.server(), RingLogger.client_options()) :: :ok
def configure(client_pid, config) do
def configure(client_pid, config) when is_list(config) do
GenServer.call(client_pid, {:configure, config})
end

Expand Down

0 comments on commit 3e8fc1c

Please sign in to comment.