cmd/accounts.go
changeset 237 ac5ce4c0e79b
parent 226 5df927fa87ca
child 239 605a00e9d1ab
equal deleted inserted replaced
236:55accc8c0fe1 237:ac5ce4c0e79b
    68 
    68 
    69 	accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.list, "list", false, "List pending follow requests")
    69 	accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.list, "list", false, "List pending follow requests")
    70 	accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.acceptFR, "accept", false, "Accept the follow request from the account ID")
    70 	accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.acceptFR, "accept", false, "Accept the follow request from the account ID")
    71 	accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.rejectFR, "reject", false, "Reject the follow request from the account ID")
    71 	accountFollowRequestsSubcommand.Flags().BoolVar(&accountsOpts.rejectFR, "reject", false, "Reject the follow request from the account ID")
    72 
    72 
    73 	accountBlockSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unblock the account")
    73 	accountBlockSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unblock the account (deprecated)")
    74 
    74 
    75 	accountMuteSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unmute the account")
    75 	accountMuteSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unmute the account (deprecated)")
    76 	accountMuteSubcommand.Flags().BoolVarP(&accountsOpts.muteNotifications, "notifications", "", true, "Mute the notifications")
    76 	accountMuteSubcommand.Flags().BoolVarP(&accountsOpts.muteNotifications, "notifications", "", true, "Mute the notifications")
    77 	accountFollowSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unfollow the account")
    77 	accountFollowSubcommand.Flags().BoolVarP(&accountsOpts.unset, "unset", "", false, "Unfollow the account (deprecated)")
    78 	accountFollowSubcommand.Flags().BoolVarP(&accountsOpts.reblogs, "show-reblogs", "", true, "Follow account's boosts")
    78 	accountFollowSubcommand.Flags().BoolVarP(&accountsOpts.reblogs, "show-reblogs", "", true, "Follow account's boosts")
    79 	accountFollowSubcommand.Flags().StringVarP(&accountsOpts.remoteUID, "remote", "r", "", "Follow remote account (user@domain)")
    79 	accountFollowSubcommand.Flags().StringVarP(&accountsOpts.remoteUID, "remote", "r", "", "Follow remote account (user@domain)")
    80 
    80 
    81 	accountRelationshipsSubcommand.Flags().StringVar(&accountsOpts.accountIDs, "account-ids", "", "Comma-separated list of account IDs")
    81 	accountRelationshipsSubcommand.Flags().StringVar(&accountsOpts.accountIDs, "account-ids", "", "Comma-separated list of account IDs")
    82 
    82 
    95 	accountUpdateSubcommand.Flags().StringVar(&accountsOpts.defaultPrivacy, "default-privacy", "", "Default toot privacy (public, unlisted, private)")
    95 	accountUpdateSubcommand.Flags().StringVar(&accountsOpts.defaultPrivacy, "default-privacy", "", "Default toot privacy (public, unlisted, private)")
    96 	accountUpdateSubcommand.Flags().BoolVar(&accountsOpts.defaultSensitive, "default-sensitive", false, "Mark medias as sensitive by default")
    96 	accountUpdateSubcommand.Flags().BoolVar(&accountsOpts.defaultSensitive, "default-sensitive", false, "Mark medias as sensitive by default")
    97 	accountUpdateSubcommand.Flags().BoolVar(&accountsOpts.locked, "locked", false, "Following account requires approval")
    97 	accountUpdateSubcommand.Flags().BoolVar(&accountsOpts.locked, "locked", false, "Following account requires approval")
    98 	accountUpdateSubcommand.Flags().BoolVar(&accountsOpts.bot, "bot", false, "Set as service (automated) account")
    98 	accountUpdateSubcommand.Flags().BoolVar(&accountsOpts.bot, "bot", false, "Set as service (automated) account")
    99 
    99 
       
   100 	// Deprecated flags
       
   101 	accountBlockSubcommand.Flags().MarkDeprecated("unset", "please use unblock instead")
       
   102 	accountMuteSubcommand.Flags().MarkDeprecated("unset", "please use unmute instead")
       
   103 	accountFollowSubcommand.Flags().MarkDeprecated("unset", "please use unfollow instead")
       
   104 
   100 	// Those variables will be used to check if the options were
   105 	// Those variables will be used to check if the options were
   101 	// explicitly set or not
   106 	// explicitly set or not
   102 	accountUpdateFlags = accountUpdateSubcommand.Flags()
   107 	accountUpdateFlags = accountUpdateSubcommand.Flags()
   103 	accountMuteFlags = accountMuteSubcommand.Flags()
   108 	accountMuteFlags = accountMuteSubcommand.Flags()
   104 	accountFollowFlags = accountFollowSubcommand.Flags()
   109 	accountFollowFlags = accountFollowSubcommand.Flags()
   175 	},
   180 	},
   176 	accountSearchSubcommand,
   181 	accountSearchSubcommand,
   177 	accountStatusesSubcommand,
   182 	accountStatusesSubcommand,
   178 	accountFollowRequestsSubcommand,
   183 	accountFollowRequestsSubcommand,
   179 	accountFollowSubcommand,
   184 	accountFollowSubcommand,
       
   185 	accountUnfollowSubcommand,
   180 	accountBlockSubcommand,
   186 	accountBlockSubcommand,
       
   187 	accountUnblockSubcommand,
   181 	accountMuteSubcommand,
   188 	accountMuteSubcommand,
       
   189 	accountUnmuteSubcommand,
   182 	accountPinSubcommand,
   190 	accountPinSubcommand,
   183 	accountUnpinSubcommand,
   191 	accountUnpinSubcommand,
   184 	accountRelationshipsSubcommand,
   192 	accountRelationshipsSubcommand,
   185 	accountReportsSubcommand,
   193 	accountReportsSubcommand,
   186 	accountUpdateSubcommand,
   194 	accountUpdateSubcommand,
   225 		return accountSubcommandsRunE(cmd.Name(), args)
   233 		return accountSubcommandsRunE(cmd.Name(), args)
   226 	},
   234 	},
   227 }
   235 }
   228 var accountFollowSubcommand = &cobra.Command{
   236 var accountFollowSubcommand = &cobra.Command{
   229 	Use:   "follow",
   237 	Use:   "follow",
   230 	Short: "Follow or unfollow the account",
   238 	Short: "Follow an account",
   231 	Example: `# Argument type can be set explicitly:
   239 	Example: `# Argument type can be set explicitly:
   232   madonctl account follow --account-id 1234
   240   madonctl account follow --account-id 1234
   233   madonctl account follow --remote Gargron@mastodon.social
   241   madonctl account follow --remote Gargron@mastodon.social
   234 
   242 
   235 # Or argument type can be guessed:
   243 # Or argument type can be guessed:
   240 	RunE: func(cmd *cobra.Command, args []string) error {
   248 	RunE: func(cmd *cobra.Command, args []string) error {
   241 		return accountSubcommandsRunE(cmd.Name(), args)
   249 		return accountSubcommandsRunE(cmd.Name(), args)
   242 	},
   250 	},
   243 }
   251 }
   244 
   252 
       
   253 var accountUnfollowSubcommand = &cobra.Command{
       
   254 	Use:   "unfollow",
       
   255 	Short: "Stop following an account",
       
   256 	Example: `  madonctl account unfollow --account-id 1234
       
   257 
       
   258 Same usage as madonctl follow.
       
   259 `,
       
   260 	RunE: func(cmd *cobra.Command, args []string) error {
       
   261 		return accountSubcommandsRunE(cmd.Name(), args)
       
   262 	},
       
   263 }
       
   264 
   245 var accountBlockSubcommand = &cobra.Command{
   265 var accountBlockSubcommand = &cobra.Command{
   246 	Use:   "block",
   266 	Use:   "block",
   247 	Short: "Block or unblock the account",
   267 	Short: "Block the account",
       
   268 	RunE: func(cmd *cobra.Command, args []string) error {
       
   269 		return accountSubcommandsRunE(cmd.Name(), args)
       
   270 	},
       
   271 }
       
   272 
       
   273 var accountUnblockSubcommand = &cobra.Command{
       
   274 	Use:   "unblock",
       
   275 	Short: "Unblock the account",
   248 	RunE: func(cmd *cobra.Command, args []string) error {
   276 	RunE: func(cmd *cobra.Command, args []string) error {
   249 		return accountSubcommandsRunE(cmd.Name(), args)
   277 		return accountSubcommandsRunE(cmd.Name(), args)
   250 	},
   278 	},
   251 }
   279 }
   252 
   280 
   253 var accountMuteSubcommand = &cobra.Command{
   281 var accountMuteSubcommand = &cobra.Command{
   254 	Use:   "mute",
   282 	Use:   "mute",
   255 	Short: "Mute or unmute the account",
   283 	Short: "Mute the account",
       
   284 	RunE: func(cmd *cobra.Command, args []string) error {
       
   285 		return accountSubcommandsRunE(cmd.Name(), args)
       
   286 	},
       
   287 }
       
   288 
       
   289 var accountUnmuteSubcommand = &cobra.Command{
       
   290 	Use:   "unmute",
       
   291 	Short: "Unmute the account",
   256 	RunE: func(cmd *cobra.Command, args []string) error {
   292 	RunE: func(cmd *cobra.Command, args []string) error {
   257 		return accountSubcommandsRunE(cmd.Name(), args)
   293 		return accountSubcommandsRunE(cmd.Name(), args)
   258 	},
   294 	},
   259 }
   295 }
   260 
   296 
   406 	case "favourites", "blocks", "mutes", "pinned":
   442 	case "favourites", "blocks", "mutes", "pinned":
   407 		// Those subcommands can not use an account ID
   443 		// Those subcommands can not use an account ID
   408 		if opt.accountID > 0 {
   444 		if opt.accountID > 0 {
   409 			return errors.New("useless account ID")
   445 			return errors.New("useless account ID")
   410 		}
   446 		}
   411 	case "follow":
   447 	case "follow", "unfollow":
   412 		// We need an account ID or a remote UID
   448 		// We need an account ID or a remote UID
   413 		if opt.accountID < 1 && opt.remoteUID == "" {
   449 		if opt.accountID < 1 && opt.remoteUID == "" {
   414 			return errors.New("missing account ID or URI")
   450 			return errors.New("missing account ID or URI")
   415 		}
   451 		}
   416 		if opt.accountID > 0 && opt.remoteUID != "" {
   452 		if opt.accountID > 0 && opt.remoteUID != "" {
   417 			return errors.New("cannot use both account ID and URI")
   453 			return errors.New("cannot use both account ID and URI")
   418 		}
   454 		}
   419 		if opt.unset && opt.accountID < 1 {
   455 		if (opt.unset || subcmd == "unfollow") && opt.accountID < 1 {
   420 			return errors.New("unfollowing requires an account ID")
   456 			return errors.New("unfollowing requires an account ID")
   421 		}
   457 		}
   422 	case "follow-requests":
   458 	case "follow-requests":
   423 		if opt.list {
   459 		if opt.list {
   424 			if opt.acceptFR || opt.rejectFR {
   460 			if opt.acceptFR || opt.rejectFR {
   529 		statusList, err = gClient.GetAccountStatuses(opt.accountID, opt.onlyPinned, opt.onlyMedia, opt.excludeReplies, limOpts)
   565 		statusList, err = gClient.GetAccountStatuses(opt.accountID, opt.onlyPinned, opt.onlyMedia, opt.excludeReplies, limOpts)
   530 		if opt.keep > 0 && len(statusList) > int(opt.keep) {
   566 		if opt.keep > 0 && len(statusList) > int(opt.keep) {
   531 			statusList = statusList[:opt.keep]
   567 			statusList = statusList[:opt.keep]
   532 		}
   568 		}
   533 		obj = statusList
   569 		obj = statusList
   534 	case "follow":
   570 	case "follow", "unfollow":
   535 		var relationship *madon.Relationship
   571 		var relationship *madon.Relationship
   536 		if opt.unset {
   572 		if opt.unset || subcmd == "unfollow" {
   537 			relationship, err = gClient.UnfollowAccount(opt.accountID)
   573 			relationship, err = gClient.UnfollowAccount(opt.accountID)
   538 			obj = relationship
   574 			obj = relationship
   539 			break
   575 			break
   540 		}
   576 		}
   541 		if opt.accountID <= 0 {
   577 		if opt.accountID <= 0 {
   581 			}
   617 			}
   582 			obj = followRequests
   618 			obj = followRequests
   583 		} else {
   619 		} else {
   584 			err = gClient.FollowRequestAuthorize(opt.accountID, !opt.rejectFR)
   620 			err = gClient.FollowRequestAuthorize(opt.accountID, !opt.rejectFR)
   585 		}
   621 		}
   586 	case "block":
   622 	case "block", "unblock":
   587 		var relationship *madon.Relationship
   623 		var relationship *madon.Relationship
   588 		if opt.unset {
   624 		if opt.unset || subcmd == "unblock" {
   589 			relationship, err = gClient.UnblockAccount(opt.accountID)
   625 			relationship, err = gClient.UnblockAccount(opt.accountID)
   590 		} else {
   626 		} else {
   591 			relationship, err = gClient.BlockAccount(opt.accountID)
   627 			relationship, err = gClient.BlockAccount(opt.accountID)
   592 		}
   628 		}
   593 		obj = relationship
   629 		obj = relationship
   594 	case "mute":
   630 	case "mute", "unmute":
   595 		var relationship *madon.Relationship
   631 		var relationship *madon.Relationship
   596 		if opt.unset {
   632 		if opt.unset || subcmd == "unmute" {
   597 			relationship, err = gClient.UnmuteAccount(opt.accountID)
   633 			relationship, err = gClient.UnmuteAccount(opt.accountID)
   598 		} else {
   634 		} else {
   599 			var muteNotif *bool
   635 			var muteNotif *bool
   600 			if accountMuteFlags.Lookup("notifications").Changed {
   636 			if accountMuteFlags.Lookup("notifications").Changed {
   601 				muteNotif = &opt.muteNotifications
   637 				muteNotif = &opt.muteNotifications