Commit 913c513
Changed files (3)
lib
elelem
plugins
lib/elelem/plugins/execute.rb
@@ -9,4 +9,9 @@ Elelem::Plugins.register(:execute) do |toolbox|
) do |a|
Elelem.sh("bash", args: ["-c", a["command"]]) { |x| $stdout.print(x) }
end
+
+ toolbox.after("execute") do |args, result|
+ status = result[:exit_status] == 0 ? "ok" : "FAIL"
+ $stdout.puts " #{status} #{args["command"]}"
+ end
end
lib/elelem/plugins/verify.rb
@@ -27,18 +27,19 @@ module Elelem
end
Plugins.register(:verify) do |toolbox|
- toolbox.after("write") do |_args, result|
- next if result[:error]
-
- Verifiers.for(result[:path]).each do |cmd|
+ toolbox.add("verify",
+ description: "Verify file syntax and run tests",
+ params: { path: { type: "string" } },
+ required: ["path"]
+ ) do |a|
+ path = a["path"]
+ Verifiers.for(path).inject({verified: []}) do |memo, cmd|
$stdout.puts "\n -> verify: #{cmd}"
- v = Elelem.sh("bash", args: ["-c", cmd]) { |x| $stdout.print(x) }
- status = v[:exit_status] == 0 ? "ok" : "FAIL"
- $stdout.puts " #{status} #{cmd}"
- if v[:exit_status] != 0
- $stdout.puts v[:content].lines.first(5).map { |l| " #{l}" }.join
- break
- end
+ v = toolbox.run("execute", { "command" => cmd })
+ return v.merge(path: path, command: cmd) if v[:exit_status] != 0
+
+ memo[:verified] << cmd
+ memo
end
end
end
lib/elelem/plugins/write.rb
@@ -15,8 +15,9 @@ Elelem::Plugins.register(:write) do |toolbox|
toolbox.after("write") do |_, result|
if result[:error]
$stdout.puts " ! #{result[:error]}"
- elsif !system("bat", "--paging=never", result[:path])
- $stdout.puts " -> #{result[:path]}"
+ else
+ system("bat", "--paging=never", result[:path]) || $stdout.puts(" -> #{result[:path]}")
+ toolbox.run("verify", { "path" => result[:path] })
end
end
end