feat(go): add --dry-run to fuj sync
All checks were successful
Deploy to K8s / deploy (push) Successful in 18s
All checks were successful
Deploy to K8s / deploy (push) Successful in 18s
Mirror fuj infer's read-only mode: SyncOpts.DryRun skips WriteHeader, AppendValues, and SortByDateColumn, printing one "Dry run: would …" line per planned operation instead. ID-dedup still runs so the output reflects exactly what the next real sync would write. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,7 @@ type SyncOpts struct {
|
||||
Days int // look-back window when From/To are zero
|
||||
From, To time.Time // explicit window (overrides Days)
|
||||
Sort bool // sort the sheet by Date after appending
|
||||
DryRun bool // print planned writes without modifying the sheet
|
||||
}
|
||||
|
||||
// SyncToSheets fetches Fio transactions and appends new ones to the payments sheet.
|
||||
@@ -52,8 +53,12 @@ func SyncToSheets(
|
||||
if len(rows) > 0 {
|
||||
header := rows[0]
|
||||
if !headerMatches(header) {
|
||||
if err := sh.WriteHeader(ctx, spreadsheetID, columnLabels); err != nil {
|
||||
return 0, fmt.Errorf("sync: write header: %w", err)
|
||||
if opts.DryRun {
|
||||
fmt.Println("Dry run: would write header row")
|
||||
} else {
|
||||
if err := sh.WriteHeader(ctx, spreadsheetID, columnLabels); err != nil {
|
||||
return 0, fmt.Errorf("sync: write header: %w", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, row := range rows[1:] {
|
||||
@@ -113,6 +118,17 @@ func SyncToSheets(
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if opts.DryRun {
|
||||
for _, row := range newRows {
|
||||
fmt.Printf("Dry run: would append date=%v amount=%v sender=%v vs=%v message=%v\n",
|
||||
row[0], row[1], row[6], row[7], row[8])
|
||||
}
|
||||
if opts.Sort {
|
||||
fmt.Println("Dry run: would sort by date")
|
||||
}
|
||||
return len(newRows), nil
|
||||
}
|
||||
|
||||
if err := sh.AppendValues(ctx, spreadsheetID, "A2", newRows); err != nil {
|
||||
return 0, fmt.Errorf("sync: append: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user