Skip to content

Commit 739330f

Browse files
phanenibhagwan
authored andcommitted
refactor(cmd): parse_args_to_opts
useful if want to parse cli flags manually, I want to detect if pass fzf_bin=sk from cli
1 parent b070bf5 commit 739330f

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

lua/fzf-lua/cmd.lua

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,9 @@ local serpent = require "fzf-lua.lib.serpent"
66

77
local M = {}
88

9-
---@param cmd string
10-
---@param ...string
11-
function M.run_command(cmd, ...)
9+
function M.parse_args_to_opts(...)
1210
local args = { ... }
13-
cmd = cmd or "builtin"
14-
15-
if not builtin[cmd] then
16-
utils.error("invalid command '%s'", cmd)
17-
return
18-
end
19-
2011
local opts = {}
21-
2212
for _, arg in ipairs(args) do
2313
local key = arg:match("^[^=]+")
2414
local val = arg:match("=") and arg:match("=(.*)$")
@@ -33,7 +23,18 @@ function M.run_command(cmd, ...)
3323
end
3424
end
3525
end
26+
return opts
27+
end
3628

29+
---@param cmd string
30+
---@param ...string
31+
function M.run_command(cmd, ...)
32+
cmd = cmd or "builtin"
33+
if not builtin[cmd] then
34+
utils.error("invalid command '%s'", cmd)
35+
return
36+
end
37+
local opts = M.parse_args_to_opts(...)
3738
builtin[cmd](opts)
3839
end
3940

0 commit comments

Comments
 (0)