import (
"fmt"
+ "os"
"git.vexingworkshop.com/signal9/dead-tooter/pkg/mastodon"
"github.com/spf13/cobra"
PreRun: func(cmd *cobra.Command, args []string) {
err := account.VerifyCredentials(host, token)
if err != nil {
- fmt.Printf("Error verifying credentials: %s", err.Error())
+ fmt.Println("Failed to verify credentials.")
+ os.Exit(1)
}
},
acct, err := mastodon.GetAccount(id, host, token)
if err != nil {
- panic(err.Error())
+ fmt.Println("Failed to get account.")
+ os.Exit(1)
}
- fmt.Printf("%+v", acct)
+ acct.DisplayLong()
},
}
PreRun: func(cmd *cobra.Command, args []string) {
err := account.VerifyCredentials(host, token)
if err != nil {
- panic(err.Error())
+ fmt.Println("Failed to verify credentials.")
+ os.Exit(1)
}
},
PreRun: func(cmd *cobra.Command, args []string) {
err := account.VerifyCredentials(host, token)
if err != nil {
- panic(err.Error())
+ fmt.Println("Failed to verify credentials.")
+ os.Exit(1)
}
},
Run: func(cmd *cobra.Command, args []string) {
following, err := account.GetFollowing(host, token)
if err != nil {
- panic(err.Error())
+ fmt.Println("Failed to get following list.")
+ os.Exit(1)
}
following.Display()
PreRun: func(cmd *cobra.Command, args []string) {
err := account.VerifyCredentials(host, token)
if err != nil {
- panic(err.Error())
+ fmt.Println("Failed to verify credentials.")
+ os.Exit(1)
}
},
Run: func(cmd *cobra.Command, args []string) {
lists, err := account.GetLists(host, token)
if err != nil {
- panic(err.Error())
+ fmt.Println("Failed to get following list.")
+ os.Exit(1)
}
lists.Display()
"os/exec"
"strings"
"text/tabwriter"
+ "text/template"
"git.vexingworkshop.com/signal9/dead-tooter/pkg/mastodon/api"
)
return strings.Join([]string{a.ID, a.Acct}, "\t")
}
+const accountTemplate = `Display Name: {{.DisplayName}}
+Account ID: {{.ID}} User Name: {{.UserName}}
+Followers: {{.FollowersCount}} Following: {{.FollowingCount}}
+Last Status: {{.LastStatusAt}}
+`
+
+// DisplayLong is a multiline display for a single Account.
+func (a *Account) DisplayLong() (err error) {
+ tmpl, err := template.New("account-long").Parse(accountTemplate)
+ if err != nil {
+ return
+ }
+
+ tmpl.Execute(os.Stdout, a)
+
+ return err
+}
+
// Display a collection of Accounts
func (aa AccountCollection) Display() {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
package mastodon
+import (
+ "fmt"
+ "os"
+ "text/tabwriter"
+)
+
+// DisplayItem interface provides a means to display a single item.
type DisplayItem interface {
- Display() (string, error)
+ Display() string
}
-type DisplayList interface {
- Display(items []interface{}) error
+// DisplayItemCollection provides a means to display a collection of items.
+type DisplayItemCollection []DisplayItem
+
+func (c DisplayItemCollection) Display() {
+ w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
+ for _, item := range c {
+ fmt.Fprintln(w, item.Display())
+ }
+ w.Flush()
}