| 138 | } |
| 139 | |
| 140 | func BuildDeleteRequests(sheetID int64, count int, indexRaw string, all bool) ([]*sheets.Request, error) { |
| 141 | if all { |
| 142 | requests := make([]*sheets.Request, 0, count) |
| 143 | for index := count - 1; index >= 0; index-- { |
| 144 | requests = append(requests, deleteRequest(sheetID, int64(index))) |
| 145 | } |
| 146 | |
| 147 | return requests, nil |
| 148 | } |
| 149 | |
| 150 | index, err := strconv.Atoi(indexRaw) |
| 151 | if err != nil || index < 0 { |
| 152 | return nil, invalidf("invalid --index") |
| 153 | } |
| 154 | |
| 155 | if index >= count { |
| 156 | return nil, invalidf("--index %d out of range; sheet has %d rules", index, count) |
| 157 | } |
| 158 | |
| 159 | return []*sheets.Request{deleteRequest(sheetID, int64(index))}, nil |
| 160 | } |
| 161 | |
| 162 | func ValidateClearIndex(indexRaw string) error { |
| 163 | indexRaw = strings.TrimSpace(indexRaw) |