Skip to content

Commit

Permalink
Fix: Fix the argument parsing
Browse files Browse the repository at this point in the history
Properly fixes #7.
  • Loading branch information
hankertrix committed Dec 22, 2024
1 parent 0cbf590 commit 09676c5
Showing 1 changed file with 2 additions and 35 deletions.
37 changes: 2 additions & 35 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ local function parse_number_arguments(args)
local parsed_args = {}

-- Iterate over the arguments given
for arg_name, arg_value in ipairs(args) do
for arg_name, arg_value in pairs(args) do
--

-- Try to convert the argument to a number
Expand Down Expand Up @@ -2772,39 +2772,6 @@ local function run_command_func(command, args, config)
command_func(args, config, command_table)
end

-- The function to handle the arguments from the job object
---@param job Job The job object given by Yazi
---@return Arguments args The arguments from the job object
local function get_args_from_job(job)
--

-- If the job object has no argument field
-- that means the arguments are given
-- as a list of strings (Yazi v0.3.x and below)
if not job.args then
return parse_args(job)

-- Otherwise, the arguments are given as a table (Yazi v0.4.x and above)
else
--

-- Get the string arguments from the job object
local string_args = job.args.args

-- If the string arguments are nil,
-- then return the job arguments
if not string_args then return parse_number_arguments(job.args) end

-- Otherwise, if the string arguments are not a string,
-- return an empty table of arguments
if type(string_args) ~= "string" then return {} end

-- Otherwise, split the string arguments, parse them,
-- and return the result
return parse_args(string_split(string_args, " "))
end
end

-- The setup function to setup the plugin
---@param _ any
---@param opts Configuration|nil The options given to the plugin
Expand All @@ -2825,7 +2792,7 @@ local function entry(_, job)

-- Get the arguments to the plugin
---@type Arguments
local args = get_args_from_job(job)
local args = parse_number_arguments(job.args) or parse_args(job)

-- Get the command passed to the plugin
local command = table.remove(args, 1)
Expand Down

0 comments on commit 09676c5

Please sign in to comment.