Skip to content

Commit 5304de1

Browse files
committed
🎨 Provide function main()
1 parent b88f742 commit 5304de1

File tree

7 files changed

+47
-33
lines changed

7 files changed

+47
-33
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ luarocks install prompt-style
130130

131131
### Other luas
132132

133+
- [lupa](https://github.com/scoder/lupa): provide an extra `python` module in lua.
133134
- [wezterm](https://github.com/wez/wezterm):
134135
- `wezterm --config-file /the/path/weztermp`
135136
- doesn't support shebang

bin/lupa

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python
2+
"""
3+
https://github.com/scoder/lupa/issues/278
4+
https://gitlab.archlinux.org/archlinux/packaging/packages/python-lupa/-/issues/2
5+
"""
6+
from lupa.lua54 import LuaRuntime
7+
8+
if __name__ == "__main__":
9+
lua = LuaRuntime()
10+
lua.require('prompt.utils')
11+
# use $PYTHONSTARTUP
12+
lua.eval('require "prompt.utils".main(arg, {})')

bin/neomuttp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env -S sh -c 'neomutt -elua-source\\ $0'
22
local utils = require "prompt.utils"
33

4-
utils.init()
54
-- use ~/.config/neomutt/neomuttrc
6-
-- utils.source_configs()
7-
local parser = utils.get_parser()
8-
local args = parser:parse(arg)
9-
if args.v then
10-
mutt.command.version()
11-
os.exit(0)
12-
end
13-
utils.process_args(args, parser)
5+
utils.main(arg, {}, function(args)
6+
if args.v then
7+
-- luacheck: ignore 111 113
8+
---@diagnostic disable: undefined-global
9+
mutt.command.version()
10+
os.exit(0)
11+
end
12+
return args
13+
end)
1414
-- ex: filetype=lua

bin/nvimp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ if require "prompt".name == "lua" then
1414
end
1515
end
1616

17-
utils.init()
1817
-- use ~/.config/nvim/init.vim
19-
-- utils.source_configs()
20-
local parser = utils.get_parser()
21-
local args = parser:parse(arg)
22-
if args.v then
23-
vim.cmd.version()
24-
os.exit(0)
25-
end
26-
utils.process_args(args, parser)
18+
utils.main(arg, {}, function(args)
19+
if args.v then
20+
vim.cmd.version()
21+
os.exit(0)
22+
end
23+
return args
24+
end)
2725
-- ex: filetype=lua

bin/pandocp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#!/usr/bin/env -S pandoc -fmarkdown /dev/null --lua-filter
22
local utils = require "prompt.utils"
33

4-
utils.init()
5-
utils.source_configs()
6-
local parser = utils.get_parser()
7-
local args = parser:parse(arg)
8-
utils.process_args(args, parser)
4+
utils.main(arg)
95
-- ex: filetype=lua

lua/prompt/utils.lua

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function M.process_args(args, parser)
131131

132132
if not ok or not m then
133133
parser:error('unknown luaJIT command or ' ..
134-
'jit.* modules not installed')
134+
'jit.* modules not installed')
135135
end
136136

137137
m.start(unpack(_args))
@@ -224,7 +224,7 @@ end
224224
---@param configs string[] | nil
225225
function M.source_configs(configs)
226226
configs = configs or { os.getenv('HOME') .. '/.luaprc.lua',
227-
os.getenv('HOME') .. '/.config/luaprc.lua' }
227+
os.getenv('HOME') .. '/.config/luaprc.lua' }
228228
for _, name in ipairs(configs) do
229229
local f = io.open(name, "r")
230230
if f ~= nil then
@@ -240,5 +240,20 @@ function M.source_configs(configs)
240240
end
241241
end
242242

243+
---**entry for pandocp**
244+
---@param argv string[] command line arguments
245+
---@param configs string[] | nil `nil` means default `~/.config/luaprc.lua`
246+
---@param callback function | nil handle `args`
247+
function M.main(argv, configs, callback)
248+
M.init()
249+
M.source_configs(configs)
250+
local parser = M.get_parser()
251+
local args = parser:parse(argv)
252+
if callback then
253+
args = callback(args)
254+
end
255+
M.process_args(args, parser)
256+
end
257+
243258
---@export
244259
return M

template.rockspec

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ end
3939

4040
build = {
4141
type = 'builtin',
42-
install = {
43-
-- cannot use _VERSION
44-
bin = {
45-
"bin/nvimp",
46-
"bin/pandocp",
47-
"bin/neomuttp"
48-
},
49-
},
5042
}
5143

5244
deploy = {

0 commit comments

Comments
 (0)