on 448bfaf help sign in
31 lines 6.3 kB history raw
1defmodule Charlex.Command do
2 @callback usage() :: [String.t()]
4 @callback description() :: String.t()
6 @callback parse_args(args :: String.t()) :: any()
8 @callback run(context :: Map.t(), args :: [String.t()] | any()) :: String.t() | any()
10 @optional_callbacks usage: 0, description: 0, parse_args: 1
12 defmacro __using__(_opts) do
13 quote do
14 @behaviour unquote(__MODULE__)
16 @impl true
17 def usage, do: "This command is without usage, will add it soon"
19 @impl true
20 def description, do: "This command is without description, will add it soon"
22 @impl true
23 def run(_context, _args), do: :ok
25 @impl true
26 def parse_args(args), do: args |> String.split() |> Kernel.tl()
28 defoverridable parse_args: 1, description: 0, run: 2, usage: 0
29 end
30 end
31end