Skip to content

Commit be052f8

Browse files
committed
Remove code duplication
1 parent 003ae7d commit be052f8

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

item.lua

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,14 @@ local options = {
355355
owned = false,
356356
nowebs = false,
357357
verbose = false,
358+
filterquality = false,
358359
totalquality = false,
359360
}
360361

361362
--- @type (fun(item:item):boolean)[]
362363
local conditions = {}
363364

364-
local minQuality, maxQuality
365+
local minQuality, maxQuality = 0, 5
365366

366367
local function flagsFilter(args, negate)
367368
local flags = argparse.stringList(args, "flag list")
@@ -425,12 +426,12 @@ local positionals = argparse.processArgsGetopt({ ... }, {
425426
{ 'q', 'min-quality', hasArg = true,
426427
handler = function(levelst)
427428
local level = argparse.nonnegativeInt(levelst, 'min-quality')
428-
minQuality = level end },
429+
minQuality = level options.filterquality = true end },
429430
-- condition_quality(conditions, level, 5) end },
430431
{ 'Q', 'max-quality', hasArg = true,
431432
handler = function(levelst)
432433
local level = argparse.nonnegativeInt(levelst, 'max-quality')
433-
maxQuality = level end },
434+
maxQuality = level options.filterquality = true end },
434435
-- condition_quality(conditions, 0, level) end },
435436
{ nil, 'stockpiled',
436437
handler = function () condition_stockpiled(conditions) end },
@@ -449,19 +450,11 @@ if options.help or positionals[1] == 'help' then
449450
return
450451
end
451452

452-
if minQuality then
453+
if options.filterquality then
453454
if options.totalquality then
454-
condition_overall_quality(conditions, minQuality, 5)
455+
condition_overall_quality(conditions, minQuality, maxQuality)
455456
else
456-
condition_quality(conditions, minQuality, 5)
457-
end
458-
end
459-
460-
if maxQuality then
461-
if options.totalquality then
462-
condition_overall_quality(conditions, 0, maxQuality)
463-
else
464-
condition_quality(conditions, 0, maxQuality)
457+
condition_quality(conditions, minQuality, maxQuality)
465458
end
466459
end
467460

0 commit comments

Comments
 (0)