go-mastodon/cmd/mstdn/cmd_search.go

48 lines
1.1 KiB
Go
Raw Permalink Normal View History

2017-04-15 19:55:32 +02:00
package main
import (
"context"
2017-04-15 19:55:32 +02:00
"errors"
"fmt"
"github.com/mattn/go-mastodon"
2022-11-27 05:24:42 +01:00
"github.com/urfave/cli/v2"
2017-04-15 19:55:32 +02:00
)
func cmdSearch(c *cli.Context) error {
if !c.Args().Present() {
return errors.New("arguments required")
}
client := c.App.Metadata["client"].(*mastodon.Client)
2017-04-20 17:50:39 +02:00
config := c.App.Metadata["config"].(*mastodon.Config)
results, err := client.Search(context.Background(), argstr(c), false)
2017-04-15 19:55:32 +02:00
if err != nil {
return err
}
2017-04-20 17:50:39 +02:00
s := newScreen(config)
if len(results.Accounts) > 0 {
fmt.Fprintln(c.App.Writer, "===ACCOUNT===")
for _, result := range results.Accounts {
fmt.Fprintf(c.App.Writer, "%v,%v\n", result.ID, s.acct(result.Acct))
}
fmt.Fprintln(c.App.Writer)
2017-04-15 19:55:32 +02:00
}
2017-04-20 17:50:39 +02:00
if len(results.Statuses) > 0 {
fmt.Fprintln(c.App.Writer, "===STATUS===")
for _, result := range results.Statuses {
s.displayStatus(c.App.Writer, result)
}
fmt.Fprintln(c.App.Writer)
2017-04-15 19:55:32 +02:00
}
2017-04-20 17:50:39 +02:00
if len(results.Hashtags) > 0 {
fmt.Fprintln(c.App.Writer, "===HASHTAG===")
for _, result := range results.Hashtags {
fmt.Fprintf(c.App.Writer, "#%v\n", result)
}
fmt.Fprintln(c.App.Writer)
2017-04-15 19:55:32 +02:00
}
return nil
}