summaryrefslogtreecommitdiff
path: root/conf/list.go
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2023-05-10 14:15:30 -0500
committersanine-a <sanine.not@pm.me>2023-05-10 14:15:30 -0500
commitc4dbe6328640f8ac43518a642e77dec061bfdd03 (patch)
treed432f0c0522d946e9b42f39c8960a3b37f4af37d /conf/list.go
parentfd994ce631ce7244157f81678574e6bc420d0fcc (diff)
add hacky command parser
Diffstat (limited to 'conf/list.go')
-rw-r--r--conf/list.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/conf/list.go b/conf/list.go
new file mode 100644
index 0000000..bf3fd80
--- /dev/null
+++ b/conf/list.go
@@ -0,0 +1,68 @@
+package main
+
+import(
+ "fmt"
+ "log"
+ "time"
+)
+
+
+var listUsers = Command{
+ Name: "users",
+ Execute: func([]string) {
+ users, err := p.AllUsers()
+ if err != nil {
+ log.Fatal(err)
+ }
+ fmt.Printf("id\tname\n========================================\n")
+ for _, user := range users {
+ fmt.Printf("%v\t%v\n", user.Id, user.Name)
+ }
+ },
+}
+
+
+var listSessions = Command{
+ Name: "sessions",
+ Execute: func([]string) {
+ sessions, err := p.AllSessions()
+ if err != nil {
+ log.Fatal(err)
+ }
+ fmt.Printf("id\tuser\tcreated\tmodified\n========================================\n")
+ for _, session := range sessions {
+ user, err := p.GetById(session.UserId)
+ if err != nil {
+ log.Fatal(err)
+ }
+ fmt.Printf("%v\t%v\n", session.Id, user.Name, session.Created.Format(time.RFC3339), session.Modified.Format(time.RFC3339))
+ }
+ },
+}
+
+
+var listEndpoints = Command{
+ Name: "endpoints",
+ Execute: func([]string) {
+ endpoints, err := p.AllEndpoints()
+ if err != nil { log.Fatal(err) }
+
+ fmt.Printf("name\tpath\taddress\n========================================\n")
+ for _, endpoint := range endpoints {
+ fmt.Printf("%v\t%v\t%v\n", endpoint.Name, endpoint.Path, endpoint.Address)
+ }
+ },
+}
+
+
+func ListInit(parser *Command) {
+ list := &Command{
+ Name: "list",
+ Branch: true,
+ }
+
+ list.AddCommand(&listUsers)
+ list.AddCommand(&listSessions)
+ list.AddCommand(&listEndpoints)
+ parser.AddCommand(list)
+}