From 0d7a802091a40a7304a0c3d1113c0cafd6556365 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Fri, 25 Jul 2014 13:06:21 +0100 Subject: Added function to list recent polls --- blavote.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'blavote.go') diff --git a/blavote.go b/blavote.go index 03d2f28..315b74a 100644 --- a/blavote.go +++ b/blavote.go @@ -24,6 +24,7 @@ func main() { Username string `short:"u" long:"username" description:"Username of user adding poll"` Remove int `short:"r" long:"remove" description:"ID of a poll to delete"` Info int `short:"i" long:"info" description:"Get info and vote stats for a given poll ID"` + List bool `short:"l" long:"list" description:"List recent polls"` Args struct { Rest []string @@ -87,6 +88,11 @@ func main() { } } else if (opts.Info > 0) { err = pollInfo(db, opts.Info) + } else if (opts.List) { + err = listPolls(db) + if (err != nil) { + fmt.Println(err) + } } else { if (len(opts.Args.Rest) > 1) { err = vote(db, opts.Username, opts.Args.Rest) @@ -201,3 +207,21 @@ func pollInfo(db *sqlite3.Conn, id int) error { return err } + +func listPolls(db *sqlite3.Conn) error { + + polls, err := getRecentPolls(db) + + for _, poll := range polls { + if (poll.id != 0) { + fmt.Print(poll.id) + fmt.Print(": " + poll.title + " ") + } else { + fmt.Println() + return nil + } + } + + + return err +} \ No newline at end of file -- cgit v1.2.3