馃崚 YAML toolkit for Neovim users
1#!/usr/bin/env lua
2
3local select_bin = function()
4 local bins = { "docker", "podman" }
5 for _, bin in ipairs(bins) do
6 if os.execute("which " .. bin) ~= nil then
7 return bin
8 end
9 end
10
11 print("No container engine found, bins are: " .. table.concat(bins, ", "))
12 os.exit(1)
13end
14
15local exec_and_exit = function(cmd)
16 print("Command: " .. cmd)
17
18 local bin = select_bin()
19 print("Binary: " .. bin)
20
21 local container = "nixery.dev/shell/curl/findutils/fzf/gcc/git/gnutar/gzip/neovim/tree-sitter"
22 local pwd = io.popen("pwd"):read("*l")
23
24 local args = {
25 bin,
26 "run",
27 "--rm",
28 "-v",
29 pwd .. ":/yaml.nvim",
30 "--workdir",
31 "/yaml.nvim",
32 "-it",
33 container,
34 cmd,
35 }
36 local arg = table.concat(args, " ")
37 print("$ " .. arg)
38
39 local status, _ = os.execute(arg)
40 os.exit(status)
41end
42
43local main = function()
44 local opts = {}
45 local cmds = {
46 nvim = function()
47 return "nvim -u tests/init.lua tests/sample.yaml"
48 end,
49 test = function()
50 for line in io.lines(".tangled/workflows/tests.yaml") do
51 if string.find(line, "PlenaryBustedDirectory") then
52 return string.gsub(line, "^%s*(.-)%s*$", "%1")
53 end
54 end
55 end,
56 }
57 for name, cmd in pairs(cmds) do
58 table.insert(opts, name)
59 if name == arg[1] then
60 local arg = cmd()
61 exec_and_exit(arg)
62 end
63 end
64
65 print("No command found, options are: " .. table.concat(opts, ", "))
66end
67
68main()