| 1 |
|
defmodule Tools.Sys.Spec.Schema do |
| 2 |
|
def get(name, _state) do |
| 3 |
|
%{name: name, description: "Read specification file", parameters: params()} |
| 4 |
|
end |
| 5 |
|
|
| 6 |
|
defp params do |
| 7 |
|
%{type: "object", properties: properties(), required: ["name"]} |
| 8 |
|
end |
| 9 |
|
|
| 10 |
|
defp properties do |
| 11 |
|
%{name: %{type: "string", description: "Spec name to read"}} |
| 12 |
|
end |
| 13 |
|
end |
| 14 |
|
|
| 15 |
|
defmodule Tools.Sys.Spec do |
| 16 |
|
import Log, only: [log: 5, agent: 5] |
| 17 |
|
import Cfg, only: [config: 1] |
| 18 |
|
|
| 19 |
|
@icon "🧪" |
| 20 |
|
|
| 21 |
10 |
defdelegate spec(name, state), to: Tools.Sys.Spec.Schema, as: :get |
| 22 |
|
|
| 23 |
:-( |
def icon, do: @icon |
| 24 |
|
|
| 25 |
|
def exec(_, %{"name" => name}, %{config: config, name: agent} = state) do |
| 26 |
3 |
spec = config("#{name}_spec") |
| 27 |
3 |
audit(spec, name, agent, config, state) |
| 28 |
|
end |
| 29 |
|
|
| 30 |
3 |
defp audit(spec, name, agent, config, state) do |
| 31 |
3 |
key = "#{name}_spec" |
| 32 |
3 |
log(@icon, key, ":", "\n#{spec.content}\n", :white) |
| 33 |
3 |
agent(@icon, key, ":", "\n#{spec.content}\n", %{name: agent}) |
| 34 |
3 |
{spec.content, %{state | config: config ++ [spec]}} |
| 35 |
|
end |
| 36 |
|
end |