cmd/accounts.go
changeset 167 1341bacd01c9
parent 160 452865b363fb
child 168 ce4000ac7294
equal deleted inserted replaced
166:79c0f8db66ff 167:1341bacd01c9
    18 
    18 
    19 var accountsOpts struct {
    19 var accountsOpts struct {
    20 	accountID                 int64
    20 	accountID                 int64
    21 	accountUID                string
    21 	accountUID                string
    22 	unset                     bool   // TODO remove eventually?
    22 	unset                     bool   // TODO remove eventually?
    23 	limit                     uint   // Limit the results
    23 	limit, keep               uint   // Limit the results
    24 	sinceID, maxID            int64  // Query boundaries
    24 	sinceID, maxID            int64  // Query boundaries
    25 	all                       bool   // Try to fetch all results
    25 	all                       bool   // Try to fetch all results
    26 	onlyMedia, excludeReplies bool   // For acccount statuses
    26 	onlyMedia, excludeReplies bool   // For acccount statuses
    27 	remoteUID                 string // For account follow
    27 	remoteUID                 string // For account follow
    28 	acceptFR, rejectFR        bool   // For account follow_requests
    28 	acceptFR, rejectFR        bool   // For account follow_requests
    43 	accountsCmd.AddCommand(accountSubcommands...)
    43 	accountsCmd.AddCommand(accountSubcommands...)
    44 
    44 
    45 	// Global flags
    45 	// Global flags
    46 	accountsCmd.PersistentFlags().Int64VarP(&accountsOpts.accountID, "account-id", "a", 0, "Account ID number")
    46 	accountsCmd.PersistentFlags().Int64VarP(&accountsOpts.accountID, "account-id", "a", 0, "Account ID number")
    47 	accountsCmd.PersistentFlags().StringVarP(&accountsOpts.accountUID, "user-id", "u", "", "Account user ID")
    47 	accountsCmd.PersistentFlags().StringVarP(&accountsOpts.accountUID, "user-id", "u", "", "Account user ID")
    48 	accountsCmd.PersistentFlags().UintVarP(&accountsOpts.limit, "limit", "l", 0, "Limit number of results")
    48 	accountsCmd.PersistentFlags().UintVarP(&accountsOpts.limit, "limit", "l", 0, "Limit number of API results")
       
    49 	accountsCmd.PersistentFlags().UintVarP(&accountsOpts.keep, "keep", "k", 0, "Limit number of results")
    49 	accountsCmd.PersistentFlags().Int64Var(&accountsOpts.sinceID, "since-id", 0, "Request IDs greater than a value")
    50 	accountsCmd.PersistentFlags().Int64Var(&accountsOpts.sinceID, "since-id", 0, "Request IDs greater than a value")
    50 	accountsCmd.PersistentFlags().Int64Var(&accountsOpts.maxID, "max-id", 0, "Request IDs less (or equal) than a value")
    51 	accountsCmd.PersistentFlags().Int64Var(&accountsOpts.maxID, "max-id", 0, "Request IDs less (or equal) than a value")
    51 	accountsCmd.PersistentFlags().BoolVar(&accountsOpts.all, "all", false, "Fetch all results")
    52 	accountsCmd.PersistentFlags().BoolVar(&accountsOpts.all, "all", false, "Fetch all results")
    52 
    53 
    53 	// Subcommand flags
    54 	// Subcommand flags
   372 		accountList, err = gClient.SearchAccounts(strings.Join(args, " "), limOpts)
   373 		accountList, err = gClient.SearchAccounts(strings.Join(args, " "), limOpts)
   373 		obj = accountList
   374 		obj = accountList
   374 	case "followers":
   375 	case "followers":
   375 		var accountList []madon.Account
   376 		var accountList []madon.Account
   376 		accountList, err = gClient.GetAccountFollowers(opt.accountID, limOpts)
   377 		accountList, err = gClient.GetAccountFollowers(opt.accountID, limOpts)
   377 		if opt.limit > 0 && len(accountList) > int(opt.limit) {
   378 		if opt.keep > 0 && len(accountList) > int(opt.keep) {
   378 			accountList = accountList[:opt.limit]
   379 			accountList = accountList[:opt.keep]
   379 		}
   380 		}
   380 		obj = accountList
   381 		obj = accountList
   381 	case "following":
   382 	case "following":
   382 		var accountList []madon.Account
   383 		var accountList []madon.Account
   383 		accountList, err = gClient.GetAccountFollowing(opt.accountID, limOpts)
   384 		accountList, err = gClient.GetAccountFollowing(opt.accountID, limOpts)
   384 		if opt.limit > 0 && len(accountList) > int(opt.limit) {
   385 		if opt.keep > 0 && len(accountList) > int(opt.keep) {
   385 			accountList = accountList[:opt.limit]
   386 			accountList = accountList[:opt.keep]
   386 		}
   387 		}
   387 		obj = accountList
   388 		obj = accountList
   388 	case "statuses":
   389 	case "statuses":
   389 		var statusList []madon.Status
   390 		var statusList []madon.Status
   390 		statusList, err = gClient.GetAccountStatuses(opt.accountID, opt.onlyMedia, opt.excludeReplies, limOpts)
   391 		statusList, err = gClient.GetAccountStatuses(opt.accountID, opt.onlyMedia, opt.excludeReplies, limOpts)
   391 		if opt.limit > 0 && len(statusList) > int(opt.limit) {
   392 		if opt.keep > 0 && len(statusList) > int(opt.keep) {
   392 			statusList = statusList[:opt.limit]
   393 			statusList = statusList[:opt.keep]
   393 		}
   394 		}
   394 		obj = statusList
   395 		obj = statusList
   395 	case "follow":
   396 	case "follow":
   396 		var relationship *madon.Relationship
   397 		var relationship *madon.Relationship
   397 		if opt.unset {
   398 		if opt.unset {
   423 					followRequests = []madon.Account{*fRequest}
   424 					followRequests = []madon.Account{*fRequest}
   424 				} else {
   425 				} else {
   425 					followRequests = []madon.Account{}
   426 					followRequests = []madon.Account{}
   426 				}
   427 				}
   427 			} else {
   428 			} else {
   428 				if opt.limit > 0 && len(followRequests) > int(opt.limit) {
   429 				if opt.keep > 0 && len(followRequests) > int(opt.keep) {
   429 					followRequests = followRequests[:opt.limit]
   430 					followRequests = followRequests[:opt.keep]
   430 				}
   431 				}
   431 			}
   432 			}
   432 			obj = followRequests
   433 			obj = followRequests
   433 		} else {
   434 		} else {
   434 			err = gClient.FollowRequestAuthorize(opt.accountID, !opt.rejectFR)
   435 			err = gClient.FollowRequestAuthorize(opt.accountID, !opt.rejectFR)
   450 		}
   451 		}
   451 		obj = relationship
   452 		obj = relationship
   452 	case "favourites":
   453 	case "favourites":
   453 		var statusList []madon.Status
   454 		var statusList []madon.Status
   454 		statusList, err = gClient.GetFavourites(limOpts)
   455 		statusList, err = gClient.GetFavourites(limOpts)
   455 		if opt.limit > 0 && len(statusList) > int(opt.limit) {
   456 		if opt.keep > 0 && len(statusList) > int(opt.keep) {
   456 			statusList = statusList[:opt.limit]
   457 			statusList = statusList[:opt.keep]
   457 		}
   458 		}
   458 		obj = statusList
   459 		obj = statusList
   459 	case "blocks":
   460 	case "blocks":
   460 		var accountList []madon.Account
   461 		var accountList []madon.Account
   461 		accountList, err = gClient.GetBlockedAccounts(limOpts)
   462 		accountList, err = gClient.GetBlockedAccounts(limOpts)
   462 		if opt.limit > 0 && len(accountList) > int(opt.limit) {
   463 		if opt.keep > 0 && len(accountList) > int(opt.keep) {
   463 			accountList = accountList[:opt.limit]
   464 			accountList = accountList[:opt.keep]
   464 		}
   465 		}
   465 		obj = accountList
   466 		obj = accountList
   466 	case "mutes":
   467 	case "mutes":
   467 		var accountList []madon.Account
   468 		var accountList []madon.Account
   468 		accountList, err = gClient.GetMutedAccounts(limOpts)
   469 		accountList, err = gClient.GetMutedAccounts(limOpts)
   469 		if opt.limit > 0 && len(accountList) > int(opt.limit) {
   470 		if opt.keep > 0 && len(accountList) > int(opt.keep) {
   470 			accountList = accountList[:opt.limit]
   471 			accountList = accountList[:opt.keep]
   471 		}
   472 		}
   472 		obj = accountList
   473 		obj = accountList
   473 	case "relationships":
   474 	case "relationships":
   474 		var ids []int64
   475 		var ids []int64
   475 		ids, err = splitIDs(opt.accountIDs)
   476 		ids, err = splitIDs(opt.accountIDs)
   487 		obj = relationships
   488 		obj = relationships
   488 	case "reports":
   489 	case "reports":
   489 		if opt.list {
   490 		if opt.list {
   490 			var reports []madon.Report
   491 			var reports []madon.Report
   491 			reports, err = gClient.GetReports(limOpts)
   492 			reports, err = gClient.GetReports(limOpts)
   492 			if opt.limit > 0 && len(reports) > int(opt.limit) {
   493 			if opt.keep > 0 && len(reports) > int(opt.keep) {
   493 				reports = reports[:opt.limit]
   494 				reports = reports[:opt.keep]
   494 			}
   495 			}
   495 			obj = reports
   496 			obj = reports
   496 			break
   497 			break
   497 		}
   498 		}
   498 		// Send a report
   499 		// Send a report