-package tooter
-
-import (
- "log"
-
- "git.vexingworkshop.com/signal9/dead-tooter/pkg/mastodon"
- "github.com/spf13/cobra"
-)
-
-var accountID string
-var account mastodon.Account
-
-func init() {
- accountCmd.PersistentFlags().StringVarP(&accountID, "id", "", "", "ID of the Mastodon account")
-
- accountCmd.AddCommand(getAccountCmd)
- accountCmd.AddCommand(getFollowersCmd)
- accountCmd.AddCommand(getFollowingCmd)
- accountCmd.AddCommand(getListsCmd)
- accountCmd.AddCommand(getStatusesCmd)
-
- rootCmd.AddCommand(accountCmd)
-}
-
-var accountCmd = &cobra.Command{
- Use: "account",
- Short: "Account commands",
- Long: "Commands related to the logged in Mastodon account.",
-}
-
-var getAccountCmd = &cobra.Command{
- Use: "get",
- Short: "Get account info",
- Long: `Return information the account specified by --id. If no id is supplied,
-return information on the current logged in user.`,
-
- PreRun: func(cmd *cobra.Command, args []string) {
- err := account.VerifyCredentials(&mAPI)
- if err != nil {
- log.Fatal("Failed to verify credentials.")
- }
- },
-
- Run: func(cmd *cobra.Command, args []string) {
- if accountID == "" {
- accountID = account.ID
- }
-
- acct, err := mastodon.GetAccount(accountID, &mAPI)
- if err != nil {
- log.Fatal("Failed to get account.")
- }
-
- acct.DisplayLong()
- },
-}
-
-var getFollowersCmd = &cobra.Command{
- Use: "followers",
- Short: "Get account followers",
- Long: "Get a list of followers for the current account.",
-
- PreRun: func(cmd *cobra.Command, args []string) {
- err := account.VerifyCredentials(&mAPI)
- if err != nil {
- log.Fatal("Failed to verify credentials.")
- }
- },
-
- Run: func(cmd *cobra.Command, args []string) {
- if accountID == "" {
- accountID = account.ID
- }
-
- followers, err := mastodon.GetFollowers(accountID, &mAPI)
- if err != nil {
- log.Fatal(err.Error())
- }
-
- followers.Display()
- },
-}
-
-var getFollowingCmd = &cobra.Command{
- Use: "following",
- Short: "Get accounts followed",
- Long: "Get a list of followed accounts for the current account.",
-
- PreRun: func(cmd *cobra.Command, args []string) {
- err := account.VerifyCredentials(&mAPI)
- if err != nil {
- log.Fatal("Failed to verify credentials.")
- }
- },
-
- Run: func(cmd *cobra.Command, args []string) {
- if accountID == "" {
- accountID = account.ID
- }
-
- following, err := mastodon.GetFollowing(accountID, &mAPI)
- if err != nil {
- log.Fatal("Failed to get following list.")
- }
-
- following.Display()
- },
-}
-
-var getListsCmd = &cobra.Command{
- Use: "lists",
- Short: "Get account's lists",
- Long: "Fetch all lists the account owns",
-
- PreRun: func(cmd *cobra.Command, args []string) {
- err := account.VerifyCredentials(&mAPI)
- if err != nil {
- log.Fatal("Failed to verify credentials.")
- }
- },
-
- Run: func(cmd *cobra.Command, args []string) {
- lists, err := account.GetLists(&mAPI)
- if err != nil {
- log.Fatal("Failed to get following list.")
- }
-
- lists.Display()
- },
-}
-
-var getStatusesCmd = &cobra.Command{
- Use: "statuses",
- Short: "Get account's statuses",
- Long: "Fetch statuses posted by account.",
-
- PreRun: func(cmd *cobra.Command, args []string) {
- err := account.VerifyCredentials(&mAPI)
- if err != nil {
- log.Fatal("Failed to verify credentials.")
- }
- },
-
- Run: func(cmd *cobra.Command, args []string) {
- if accountID == "" {
- accountID = account.ID
- }
- statuses, err := mastodon.GetStatuses(accountID, &mAPI)
- if err != nil {
- log.Fatal("Failed to retrieve statuses.")
- }
-
- statuses.Display()
- },
-}