From 1fe688e2874daa0c7654417af6c616239e48c65a Mon Sep 17 00:00:00 2001 From: Layla Manley Date: Sun, 8 Oct 2023 05:19:07 -0400 Subject: [PATCH] iteration --- lib/auth.lua | 17 +++++++++++++++++ packages/auth.lua | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/auth.lua b/lib/auth.lua index 1ad898d..1878aef 100644 --- a/lib/auth.lua +++ b/lib/auth.lua @@ -49,6 +49,23 @@ function check_user_group(username, group) end end +function trueKeysToString(tbl) + local result = "" + local first = true + + for key, value in pairs(tbl) do + if value == true then + if not first then + result = result .. ", " + else + first = false + end + result = result .. key + end + end + + return result +end function list_to_string(list) local str = "" diff --git a/packages/auth.lua b/packages/auth.lua index e9f37d1..1ad4d1d 100644 --- a/packages/auth.lua +++ b/packages/auth.lua @@ -101,7 +101,7 @@ elseif action == "group" then if subaction == "list" then local result = auth.list_user_groups(settings.get("auth.username")) - io.write("Groups: " .. auth.list_to_string(result) .. "\n") + io.write("Groups: " .. auth.trueKeysToString(result) .. "\n") elseif subaction == "add" then local target_user = args[3] local group = args[4]