diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index e378376..456ce3a 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -7,11 +7,12 @@ on: jobs: gen: runs-on: ubuntu-latest + needs: build steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - name: Run docgen run: go run cmd/docgen/docgen.go + - name: Run Lua docgen + run: ./hilbish cmd/docgen/docgen.lua - name: Commit new docs uses: stefanzweifel/git-auto-commit-action@v4 with: diff --git a/.gitignore b/.gitignore index e2207a5..b2be7c4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ hilbish !docs/api/hilbish docgen +!cmd/docgen .vim petals/ diff --git a/cmd/docgen/docgen.lua b/cmd/docgen/docgen.lua new file mode 100644 index 0000000..82719a4 --- /dev/null +++ b/cmd/docgen/docgen.lua @@ -0,0 +1,67 @@ +local fs = require 'fs' +local emmyPattern = '^%-%-%- (.+)' +local pieces = {} + +local files = fs.readdir 'nature' +for _, fname in ipairs(files) do + local isScript = fname:match'%.lua$' + if not isScript then goto continue end + + local f = io.open(string.format('nature/%s', fname)) + local header = f:read '*l' + if not header:match(emmyPattern) then goto continue end + + local iface = header:match(emmyPattern) + pieces[iface] = {} + + local docPiece = {} + + for line in f:lines() do + if line == header then goto continue2 end + if not line:match(emmyPattern) then + if line:match '^function' then + local pattern = (string.format('^function %s.', iface) .. '(%w+)') + local funcName = line:match(pattern) + pieces[iface][funcName] = docPiece + end + docPiece = {} + goto continue2 + end + + table.insert(docPiece, line) + ::continue2:: + end + ::continue:: +end + +for iface, dps in pairs(pieces) do + local mod = iface:match '(%w+)%.' + local path = string.format('docs/api/%s/%s.md', mod, iface) + local f = io.open(path, 'a+') + + for func, docs in pairs(dps) do + local params = table.filter(docs, function(t) + return t:match '^%-%-%- @param' + end) + f:write(string.format('## %s(', func)) + for i, str in ipairs(params) do + if i ~= 1 then + f:write ', ' + end + f:write(str:match '^%-%-%- @param ([%w]+) ') + end + f:write(')\n') + + for _, str in ipairs(docs) do + if not str:match '^%-%-%- @' then + f:write(str:match '^%-%-%- (.+)' .. '\n') + end + end + f:write('\n') + end + f:flush() +end + + + + diff --git a/docs/api/hilbish/hilbish.runner.md b/docs/api/hilbish/hilbish.runner.md index 68ffdc6..ec8a652 100644 --- a/docs/api/hilbish/hilbish.runner.md +++ b/docs/api/hilbish/hilbish.runner.md @@ -29,3 +29,20 @@ or `load`, but is appropriated for the runner interface. Runs a command in Hilbish's shell script interpreter. This is the equivalent of using `source`. +## setCurrent(name) +Sets the current interactive/command line runner mode. + +## add(name, runner) +Adds a runner to the table of available runners. If runner is a table, +it must have the run function in it. + +## get(name) +Get a runner by name. + +## set(name, runner) +Sets a runner by name. The runner table must have the run function in it. + +## exec(cmd, runnerName) +Executes cmd with a runner. If runnerName isn't passed, it uses +the user's current runner. +