From c4dbe6328640f8ac43518a642e77dec061bfdd03 Mon Sep 17 00:00:00 2001 From: sanine-a Date: Wed, 10 May 2023 14:15:30 -0500 Subject: add hacky command parser --- conf/list.go | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 conf/list.go (limited to 'conf/list.go') 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) +} -- cgit v1.2.1