Skip to content

Commit

Permalink
remove repeated if quiet then
Browse files Browse the repository at this point in the history
reorganize main function parameters for backwards compat
  • Loading branch information
AndrielChaoti committed Nov 10, 2023
1 parent 56d1755 commit b950abe
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions unforbid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

local argparse = require('argparse')

local function unforbid_all(include_unreachable, include_tattered, quiet)
if not quiet then print('Unforbidding all items...') end
local function unforbid_all(include_unreachable, quiet, include_worn)
local p
if quiet then p=function(s) return end; else p=function(s) return print(s) end; end

p('Unforbidding all items...')

local citizens = dfhack.units.getCitizens(true)
local count = 0
Expand All @@ -19,25 +22,25 @@ local function unforbid_all(include_unreachable, include_tattered, quiet)
end

if not reachable then
if not quiet then print((' unreachable: %s (skipping)'):format(item)) end
p((' unreachable: %s (skipping)'):format(item))
goto skipitem
end
end

if ((not options.include_worn) and item.wear >= 2) then
if not quiet then print((' worn: %s (skipping)'):format(item)) end
goto skipitem
end
if ((not include_worn) and item.wear >= 2) then
p((' worn: %s (skipping)'):format(item))
goto skipitem
end

if not quiet then print((' unforbid: %s'):format(item)) end
p((' unforbid: %s'):format(item))
item.flags.forbid = false
count = count + 1

::skipitem::
end
end

if not quiet then print(('%d items unforbidden'):format(count)) end
p(('%d items unforbidden'):format(count)) end
end

-- let the common --help parameter work, even though it's undocumented
Expand All @@ -61,5 +64,5 @@ if positionals[1] == nil or positionals[1] == 'help' or options.help then
end

if positionals[1] == 'all' then
unforbid_all(options.include_unreachable, options.include_worn, options.quiet)
unforbid_all(options.include_unreachable, options.quiet, options.include_worn)
end

0 comments on commit b950abe

Please sign in to comment.