Add option --keep to keep the N last items
This complements the --limit option which is used for the API call
itself. The keep flag is used after the filters to output only a
maximum number of filtered items.
--- a/cmd/accounts.go Sat Jul 15 21:58:24 2017 +0200
+++ b/cmd/accounts.go Sat Jul 15 22:25:46 2017 +0200
@@ -20,7 +20,7 @@
accountID int64
accountUID string
unset bool // TODO remove eventually?
- limit uint // Limit the results
+ limit, keep uint // Limit the results
sinceID, maxID int64 // Query boundaries
all bool // Try to fetch all results
onlyMedia, excludeReplies bool // For acccount statuses
@@ -45,7 +45,8 @@
// Global flags
accountsCmd.PersistentFlags().Int64VarP(&accountsOpts.accountID, "account-id", "a", 0, "Account ID number")
accountsCmd.PersistentFlags().StringVarP(&accountsOpts.accountUID, "user-id", "u", "", "Account user ID")
- accountsCmd.PersistentFlags().UintVarP(&accountsOpts.limit, "limit", "l", 0, "Limit number of results")
+ accountsCmd.PersistentFlags().UintVarP(&accountsOpts.limit, "limit", "l", 0, "Limit number of API results")
+ accountsCmd.PersistentFlags().UintVarP(&accountsOpts.keep, "keep", "k", 0, "Limit number of results")
accountsCmd.PersistentFlags().Int64Var(&accountsOpts.sinceID, "since-id", 0, "Request IDs greater than a value")
accountsCmd.PersistentFlags().Int64Var(&accountsOpts.maxID, "max-id", 0, "Request IDs less (or equal) than a value")
accountsCmd.PersistentFlags().BoolVar(&accountsOpts.all, "all", false, "Fetch all results")
@@ -374,22 +375,22 @@
case "followers":
var accountList []madon.Account
accountList, err = gClient.GetAccountFollowers(opt.accountID, limOpts)
- if opt.limit > 0 && len(accountList) > int(opt.limit) {
- accountList = accountList[:opt.limit]
+ if opt.keep > 0 && len(accountList) > int(opt.keep) {
+ accountList = accountList[:opt.keep]
}
obj = accountList
case "following":
var accountList []madon.Account
accountList, err = gClient.GetAccountFollowing(opt.accountID, limOpts)
- if opt.limit > 0 && len(accountList) > int(opt.limit) {
- accountList = accountList[:opt.limit]
+ if opt.keep > 0 && len(accountList) > int(opt.keep) {
+ accountList = accountList[:opt.keep]
}
obj = accountList
case "statuses":
var statusList []madon.Status
statusList, err = gClient.GetAccountStatuses(opt.accountID, opt.onlyMedia, opt.excludeReplies, limOpts)
- if opt.limit > 0 && len(statusList) > int(opt.limit) {
- statusList = statusList[:opt.limit]
+ if opt.keep > 0 && len(statusList) > int(opt.keep) {
+ statusList = statusList[:opt.keep]
}
obj = statusList
case "follow":
@@ -425,8 +426,8 @@
followRequests = []madon.Account{}
}
} else {
- if opt.limit > 0 && len(followRequests) > int(opt.limit) {
- followRequests = followRequests[:opt.limit]
+ if opt.keep > 0 && len(followRequests) > int(opt.keep) {
+ followRequests = followRequests[:opt.keep]
}
}
obj = followRequests
@@ -452,22 +453,22 @@
case "favourites":
var statusList []madon.Status
statusList, err = gClient.GetFavourites(limOpts)
- if opt.limit > 0 && len(statusList) > int(opt.limit) {
- statusList = statusList[:opt.limit]
+ if opt.keep > 0 && len(statusList) > int(opt.keep) {
+ statusList = statusList[:opt.keep]
}
obj = statusList
case "blocks":
var accountList []madon.Account
accountList, err = gClient.GetBlockedAccounts(limOpts)
- if opt.limit > 0 && len(accountList) > int(opt.limit) {
- accountList = accountList[:opt.limit]
+ if opt.keep > 0 && len(accountList) > int(opt.keep) {
+ accountList = accountList[:opt.keep]
}
obj = accountList
case "mutes":
var accountList []madon.Account
accountList, err = gClient.GetMutedAccounts(limOpts)
- if opt.limit > 0 && len(accountList) > int(opt.limit) {
- accountList = accountList[:opt.limit]
+ if opt.keep > 0 && len(accountList) > int(opt.keep) {
+ accountList = accountList[:opt.keep]
}
obj = accountList
case "relationships":
@@ -489,8 +490,8 @@
if opt.list {
var reports []madon.Report
reports, err = gClient.GetReports(limOpts)
- if opt.limit > 0 && len(reports) > int(opt.limit) {
- reports = reports[:opt.limit]
+ if opt.keep > 0 && len(reports) > int(opt.keep) {
+ reports = reports[:opt.keep]
}
obj = reports
break
--- a/cmd/notifications.go Sat Jul 15 21:58:24 2017 +0200
+++ b/cmd/notifications.go Sat Jul 15 22:25:46 2017 +0200
@@ -104,8 +104,8 @@
notifications = newNotifications
}
- if accountsOpts.limit > 0 && len(notifications) > int(accountsOpts.limit) {
- notifications = notifications[:accountsOpts.limit]
+ if accountsOpts.keep > 0 && len(notifications) > int(accountsOpts.keep) {
+ notifications = notifications[:accountsOpts.keep]
}
obj = notifications
} else if opt.notifID > 0 {
--- a/cmd/status.go Sat Jul 15 21:58:24 2017 +0200
+++ b/cmd/status.go Sat Jul 15 22:25:46 2017 +0200
@@ -32,7 +32,7 @@
addMentions bool
// Used for several subcommands to limit the number of results
- limit uint
+ limit, keep uint
//sinceID, maxID int64
all bool
}
@@ -45,7 +45,8 @@
// Global flags
statusCmd.PersistentFlags().Int64VarP(&statusOpts.statusID, "status-id", "s", 0, "Status ID number")
- statusCmd.PersistentFlags().UintVarP(&statusOpts.limit, "limit", "l", 0, "Limit number of results")
+ statusCmd.PersistentFlags().UintVarP(&statusOpts.limit, "limit", "l", 0, "Limit number of API results")
+ statusCmd.PersistentFlags().UintVarP(&statusOpts.keep, "keep", "k", 0, "Limit number of results")
//statusCmd.PersistentFlags().Int64Var(&statusOpts.sinceID, "since-id", 0, "Request IDs greater than a value")
//statusCmd.PersistentFlags().Int64Var(&statusOpts.maxID, "max-id", 0, "Request IDs less (or equal) than a value")
statusCmd.PersistentFlags().BoolVar(&statusOpts.all, "all", false, "Fetch all results (for reblogged-by/favourited-by)")
@@ -232,15 +233,15 @@
case "reblogged-by":
var accountList []madon.Account
accountList, err = gClient.GetStatusRebloggedBy(opt.statusID, limOpts)
- if opt.limit > 0 && len(accountList) > int(opt.limit) {
- accountList = accountList[:opt.limit]
+ if opt.keep > 0 && len(accountList) > int(opt.keep) {
+ accountList = accountList[:opt.keep]
}
obj = accountList
case "favourited-by":
var accountList []madon.Account
accountList, err = gClient.GetStatusFavouritedBy(opt.statusID, limOpts)
- if opt.limit > 0 && len(accountList) > int(opt.limit) {
- accountList = accountList[:opt.limit]
+ if opt.keep > 0 && len(accountList) > int(opt.keep) {
+ accountList = accountList[:opt.keep]
}
obj = accountList
case "delete":
--- a/cmd/timelines.go Sat Jul 15 21:58:24 2017 +0200
+++ b/cmd/timelines.go Sat Jul 15 22:25:46 2017 +0200
@@ -15,7 +15,7 @@
var timelineOpts struct {
local bool
- limit uint
+ limit, keep uint
sinceID, maxID int64
}
@@ -39,7 +39,8 @@
RootCmd.AddCommand(timelineCmd)
timelineCmd.Flags().BoolVar(&timelineOpts.local, "local", false, "Posts from the local instance")
- timelineCmd.Flags().UintVarP(&timelineOpts.limit, "limit", "l", 0, "Limit number of results")
+ timelineCmd.Flags().UintVarP(&timelineOpts.limit, "limit", "l", 0, "Limit number of API results")
+ timelineCmd.Flags().UintVarP(&timelineOpts.keep, "keep", "k", 0, "Limit number of results")
timelineCmd.PersistentFlags().Int64Var(&timelineOpts.sinceID, "since-id", 0, "Request IDs greater than a value")
timelineCmd.PersistentFlags().Int64Var(&timelineOpts.maxID, "max-id", 0, "Request IDs less (or equal) than a value")
}
@@ -78,8 +79,8 @@
os.Exit(1)
}
- if opt.limit > 0 && len(sl) > int(opt.limit) {
- sl = sl[:opt.limit]
+ if opt.keep > 0 && len(sl) > int(opt.keep) {
+ sl = sl[:opt.keep]
}
p, err := getPrinter()