1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2026-01-27 13:35:59 +00:00

Beginnings of a command line REST client

This commit is contained in:
James Hillyerd
2017-02-04 18:07:25 -08:00
parent 56cff6296a
commit 6722811425
4 changed files with 172 additions and 1 deletions

54
cmd/client/list.go Normal file
View File

@@ -0,0 +1,54 @@
package main
import (
"context"
"flag"
"fmt"
"github.com/google/subcommands"
"github.com/jhillyerd/inbucket/rest/client"
)
type listCmd struct {
mailbox string
}
func (*listCmd) Name() string {
return "list"
}
func (*listCmd) Synopsis() string {
return "list contents of mailbox"
}
func (*listCmd) Usage() string {
return `list <mailbox>:
list message IDs in mailbox
`
}
func (l *listCmd) SetFlags(f *flag.FlagSet) {
}
func (l *listCmd) Execute(
_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
mailbox := f.Arg(0)
if mailbox == "" {
return usage("mailbox required")
}
// Setup rest client
c, err := client.New(baseURL())
if err != nil {
return fatal("Couldn't build client", err)
}
// Get list
headers, err := c.ListMailbox(mailbox)
if err != nil {
return fatal("REST call failed", err)
}
for _, h := range headers {
fmt.Println(h.ID)
}
return subcommands.ExitSuccess
}