(ctx context.Context, flags *RootFlags)
| 134 | } |
| 135 | |
| 136 | func (c *SheetsConditionalClearCmd) Run(ctx context.Context, flags *RootFlags) error { |
| 137 | spreadsheetID := normalizeGoogleID(strings.TrimSpace(c.SpreadsheetID)) |
| 138 | sheetName := strings.TrimSpace(c.Sheet) |
| 139 | if spreadsheetID == "" { |
| 140 | return usage("empty spreadsheetId") |
| 141 | } |
| 142 | if sheetName == "" { |
| 143 | return usage("empty --sheet") |
| 144 | } |
| 145 | if !c.All && strings.TrimSpace(c.Index) == "" { |
| 146 | return usage("provide --index or --all") |
| 147 | } |
| 148 | if c.All && strings.TrimSpace(c.Index) != "" { |
| 149 | return usage("use either --index or --all, not both") |
| 150 | } |
| 151 | if err := sheetsconditional.ValidateClearIndex(strings.TrimSpace(c.Index)); err != nil { |
| 152 | return sheetsConditionalPlannerError(err) |
| 153 | } |
| 154 | |
| 155 | if flags != nil && flags.DryRun { |
| 156 | return dryRunAndConfirmDestructive(ctx, flags, "sheets.conditional-format.clear", map[string]any{ |
| 157 | "spreadsheet_id": spreadsheetID, |
| 158 | "sheet": sheetName, |
| 159 | "index": strings.TrimSpace(c.Index), |
| 160 | "all": c.All, |
| 161 | }, "remove conditional format rules from "+sheetName) |
| 162 | } |
| 163 | |
| 164 | account, err := requireAccount(flags) |
| 165 | if err != nil { |
| 166 | return err |
| 167 | } |
| 168 | svc, err := sheetsService(ctx, account) |
| 169 | if err != nil { |
| 170 | return err |
| 171 | } |
| 172 | resp, err := svc.Spreadsheets.Get(spreadsheetID). |
| 173 | Fields("sheets(properties(sheetId,title),conditionalFormats)"). |
| 174 | Context(ctx). |
| 175 | Do() |
| 176 | if err != nil { |
| 177 | return err |
| 178 | } |
| 179 | sheetID, count, err := sheetsconditional.SheetRuleCount(resp, sheetName) |
| 180 | if err != nil { |
| 181 | return sheetsConditionalPlannerError(err) |
| 182 | } |
| 183 | |
| 184 | requests, err := sheetsconditional.BuildDeleteRequests(sheetID, count, strings.TrimSpace(c.Index), c.All) |
| 185 | if err != nil { |
| 186 | return sheetsConditionalPlannerError(err) |
| 187 | } |
| 188 | if len(requests) == 0 { |
| 189 | if outfmt.IsJSON(ctx) { |
| 190 | return outfmt.WriteJSON(ctx, stdoutWriter(ctx), map[string]any{"removed": 0}) |
| 191 | } |
| 192 | ui.FromContext(ctx).Out().Println("No conditional format rules to remove") |
| 193 | return nil |
nothing calls this directly
no test coverage detected