From 7410cef1fd960a90e56d893c4a774f3b24eff666 Mon Sep 17 00:00:00 2001
From: Kevin Lyda <kevin@lyda.ie>
Date: Sun, 18 May 2025 12:00:07 +0100
Subject: [PATCH] Add SHOW PRIVILEGES

---
 ask/ask.go      | 8 ++++++++
 repl/command.go | 1 +
 repl/show.go    | 6 +++++-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/ask/ask.go b/ask/ask.go
index bdde8a3..e58a68c 100644
--- a/ask/ask.go
+++ b/ask/ask.go
@@ -52,3 +52,11 @@ func Choose(prompt string, choices []string) (int, error) {
 	}
 	return choice, nil
 }
+
+// YesNo converts an int64 to "yes" (`!= 0`) or "no" (`== 0`).
+func YesNo(num int64) string {
+	if num != 0 {
+		return "yes"
+	}
+	return "no"
+}
diff --git a/repl/command.go b/repl/command.go
index 4f49833..79ec62e 100644
--- a/repl/command.go
+++ b/repl/command.go
@@ -1485,6 +1485,7 @@ have been set.`,
 				Description: `Shows the  privileges necessary to  use privileged commands.  Also shows
 any  rights identifiers  that would  also give  a user  privileges. (The
 latter are ACLs which are set on the BULLUSER.DAT file.)`,
+				Action: ActionShowPrivileges,
 			},
 			"USER": {
 				Description: `Shows the last time that a user logged in, or if /FOLDER  is  specified,
diff --git a/repl/show.go b/repl/show.go
index a2d628d..80481f8 100644
--- a/repl/show.go
+++ b/repl/show.go
@@ -7,6 +7,7 @@ import (
 
 	"github.com/carlmjohnson/versioninfo"
 
+	"git.lyda.ie/kevin/bulletin/ask"
 	"git.lyda.ie/kevin/bulletin/dclish"
 	"git.lyda.ie/kevin/bulletin/folders"
 	"git.lyda.ie/kevin/bulletin/storage"
@@ -117,7 +118,10 @@ func ActionShowNew(_ *dclish.Command) error {
 
 // ActionShowPrivileges handles the `SHOW PRIVILEGES` command.
 func ActionShowPrivileges(_ *dclish.Command) error {
-	fmt.Println("TODO: implement ActionShowPrivileges.")
+	fmt.Printf("Account privileges for %s:\n", this.User.Login)
+	fmt.Printf("  Admin     : %s\n", ask.YesNo(this.User.Admin))
+	fmt.Printf("  Moderator : %s\n", ask.YesNo(this.User.Moderator))
+	fmt.Printf("  Alert     : %s\n", ask.YesNo(this.User.Alert))
 	return nil
 }
 
-- 
GitLab