Skip to content

Commit 768b3d6

Browse files
committed
add a 'toggle' command line option for any boolean value
1 parent 3e96c60 commit 768b3d6

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

plugins/lua/spectate.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,11 @@ local function set_setting(args)
210210
-- here just in case, is already checked in the loop above
211211
qerror('missing value for ' .. path)
212212
elseif entry_type == 'boolean' then
213-
value = argparse.boolean(value, path)
213+
if value == 'toggle' then
214+
value = not cfg[key]
215+
else
216+
value = argparse.boolean(value, path)
217+
end
214218
elseif entry_type == 'number' then
215219
if path == 'follow-seconds' then
216220
value = argparse.positiveInt(value, path)
@@ -241,7 +245,12 @@ function parse_commandline(args)
241245
if not command or command == 'status' then
242246
print_status()
243247
elseif command == 'toggle' then
244-
do_toggle()
248+
if #args == 0 then
249+
do_toggle()
250+
else
251+
args[#args+1] = 'toggle'
252+
set_setting(args)
253+
end
245254
elseif command == 'set' then
246255
set_setting(args)
247256
elseif command == 'overlay' then

0 commit comments

Comments
 (0)