]> Vexing Labs - dead-tooter.git/commitdiff
wip, misc
authorAdam Shamblin <adam@vexingworkshop.com>
Mon, 16 Jan 2023 18:21:59 +0000 (11:21 -0700)
committerAdam Shamblin <adam@vexingworkshop.com>
Mon, 16 Jan 2023 18:21:59 +0000 (11:21 -0700)
cmd/list.go
pkg/mastodon/account.go
pkg/mastodon/display.go [deleted file]
pkg/mastodon/display/display.go [new file with mode: 0644]

index 82f3dc312b265f0ee764e23d4c09e2a36a4ba718..a7cab4dff1bb02382005b91397c73418a16ade3e 100644 (file)
@@ -51,7 +51,7 @@ var listAccountsCmd = &cobra.Command{
                        log.Fatal(err.Error())
                }
 
-               accounts.Display()
+               print(accounts)
        },
 }
 
index 0a630a966731a014f0b5b26dc46e5202d139d39c..e01b018b4d9d3aeabc13cf64bc89fdd131f4cd75 100644 (file)
@@ -67,11 +67,8 @@ type Emoji struct {
        Category        string `json:"category"`
 }
 
-// AccountCollection is a group of Accounts
-type AccountCollection []Account
-
 // Display a single Account
-func (a *Account) Display() string {
+func (a *Account) String() string {
        return strings.Join([]string{a.ID, a.Acct}, "\t")
 }
 
@@ -93,15 +90,30 @@ func (a *Account) DisplayLong() (err error) {
        return err
 }
 
+// AccountCollection is a group of Accounts
+type AccountCollection []Account
+
 // Display a collection of Accounts
 func (ac AccountCollection) Display() {
        w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
        for _, value := range ac {
-               fmt.Fprintln(w, value.Display())
+               fmt.Fprintln(w, value.String())
        }
        w.Flush()
 }
 
+func (ac AccountCollection) Len() int {
+       return len(ac)
+}
+
+func (ac AccountCollection) Less(i, j int) bool {
+       return ac[i].ID < ac[j].ID
+}
+
+func (ac AccountCollection) Swap(i, j int) {
+       ac[i], ac[j] = ac[j], ac[i]
+}
+
 // Authorize opens the default browser to initiate the authorization flow
 // for the current user.
 func (a *Account) Authorize(host string, app Application) (code string, err error) {
diff --git a/pkg/mastodon/display.go b/pkg/mastodon/display.go
deleted file mode 100644 (file)
index 9bd233f..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-package mastodon
-
-import (
-       "fmt"
-       "os"
-       "text/tabwriter"
-)
-
-// DisplayItem interface provides a means to display a single item.
-type DisplayItem interface {
-       Display() string
-}
-
-// 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()
-}
diff --git a/pkg/mastodon/display/display.go b/pkg/mastodon/display/display.go
new file mode 100644 (file)
index 0000000..b5c7688
--- /dev/null
@@ -0,0 +1,26 @@
+package display
+
+import (
+       "fmt"
+       "os"
+       "text/tabwriter"
+)
+
+// DisplayItem interface provides a means to display a single item.
+type Item interface {
+       Display() string
+}
+
+// DisplayItemCollection provides a means to display a collection of items.
+type ItemCollection []Item
+
+func AsTable(c ItemCollection) {
+       w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
+       for _, item := range c {
+               fmt.Fprintln(w, item.Display())
+       }
+       w.Flush()
+}
+
+func AsJSON(c ItemCollection) {
+}