Skip to content

Commit 802c45a

Browse files
leogdionclaude
andcommitted
refactor: simplify JSON output by removing computed properties and jsonOutput flag
Remove unnecessary complexity from JSON output implementation: - Remove custom encode(to:) method from DetailedSyncResult - Remove computed properties (totalCreated, totalUpdated, totalFailed, totalRecords) - Remove jsonOutput boolean configuration (keep only jsonOutputFile) - Always show human-readable summary to console - Calculate totals manually in both SyncCommand and GitHub Actions workflow This addresses PR review feedback to simplify the implementation by: 1. Relying on stored properties only for JSON serialization 2. Using a single jsonOutputFile config instead of dual jsonOutput + jsonOutputFile 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 8e1231c commit 802c45a

File tree

6 files changed

+19
-61
lines changed

6 files changed

+19
-61
lines changed

.github/actions/cloudkit-sync/action.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ runs:
249249
CLOUDKIT_ENVIRONMENT: ${{ inputs.environment }}
250250
CLOUDKIT_CONTAINER_ID: ${{ inputs.container-id }}
251251
VIRTUALBUDDY_API_KEY: ${{ inputs.virtualbuddy-api-key }}
252-
BUSHEL_SYNC_JSON_OUTPUT: true
253252
BUSHEL_SYNC_JSON_OUTPUT_FILE: sync-result.json
254253
run: |
255254
echo "Starting CloudKit sync with change tracking..."
@@ -275,9 +274,10 @@ runs:
275274
SWIFT_UPDATED=$(jq '.swiftVersions.updated' sync-result.json)
276275
SWIFT_FAILED=$(jq '.swiftVersions.failed' sync-result.json)
277276
278-
TOTAL_CREATED=$(jq '.totalCreated' sync-result.json)
279-
TOTAL_UPDATED=$(jq '.totalUpdated' sync-result.json)
280-
TOTAL_FAILED=$(jq '.totalFailed' sync-result.json)
277+
# Calculate totals manually
278+
TOTAL_CREATED=$((RESTORE_CREATED + XCODE_CREATED + SWIFT_CREATED))
279+
TOTAL_UPDATED=$((RESTORE_UPDATED + XCODE_UPDATED + SWIFT_UPDATED))
280+
TOTAL_FAILED=$((RESTORE_FAILED + XCODE_FAILED + SWIFT_FAILED))
281281
282282
# Generate summary showing changes (not just totals)
283283
cat > sync-summary.md <<EOF

Sources/BushelCloudCLI/Commands/SyncCommand.swift

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,15 @@ internal enum SyncCommand {
6969
do {
7070
let result = try await syncEngine.sync(options: options)
7171

72-
// Output based on format
73-
if config.sync?.jsonOutput == true {
72+
// Write JSON to file if path specified
73+
if let outputFile = config.sync?.jsonOutputFile {
7474
let json = try result.toJSON(pretty: true)
75-
76-
// Write to file if path specified, otherwise print to stdout
77-
if let outputFile = config.sync?.jsonOutputFile {
78-
try json.write(toFile: outputFile, atomically: true, encoding: .utf8)
79-
BushelCloudKit.ConsoleOutput.info("✅ JSON output written to: \(outputFile)")
80-
} else {
81-
print(json)
82-
}
83-
} else {
84-
printSuccess(result)
75+
try json.write(toFile: outputFile, atomically: true, encoding: .utf8)
76+
BushelCloudKit.ConsoleOutput.info("✅ JSON output written to: \(outputFile)")
8577
}
78+
79+
// Always show human-readable summary
80+
printSuccess(result)
8681
} catch {
8782
printError(error)
8883
Foundation.exit(1)
@@ -139,12 +134,16 @@ internal enum SyncCommand {
139134
printTypeResult("XcodeVersions", result.xcodeVersions)
140135
printTypeResult("SwiftVersions", result.swiftVersions)
141136

137+
let totalCreated = result.restoreImages.created + result.xcodeVersions.created + result.swiftVersions.created
138+
let totalUpdated = result.restoreImages.updated + result.xcodeVersions.updated + result.swiftVersions.updated
139+
let totalFailed = result.restoreImages.failed + result.xcodeVersions.failed + result.swiftVersions.failed
140+
142141
print(String(repeating: "-", count: 60))
143142
print("TOTAL:")
144-
print(" ✨ Created: \(result.totalCreated)")
145-
print(" 🔄 Updated: \(result.totalUpdated)")
146-
if result.totalFailed > 0 {
147-
print(" ❌ Failed: \(result.totalFailed)")
143+
print(" ✨ Created: \(totalCreated)")
144+
print(" 🔄 Updated: \(totalUpdated)")
145+
if totalFailed > 0 {
146+
print(" ❌ Failed: \(totalFailed)")
148147
}
149148
print(String(repeating: "=", count: 60))
150149
print("\n💡 Next: Use 'bushel-cloud export' to view the synced data")

Sources/BushelCloudKit/CloudKit/SyncEngine.swift

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,6 @@ public struct SyncEngine: Sendable {
7979
public let xcodeVersions: TypeSyncResult
8080
public let swiftVersions: TypeSyncResult
8181

82-
public var totalCreated: Int {
83-
restoreImages.created + xcodeVersions.created + swiftVersions.created
84-
}
85-
86-
public var totalUpdated: Int {
87-
restoreImages.updated + xcodeVersions.updated + swiftVersions.updated
88-
}
89-
90-
public var totalFailed: Int {
91-
restoreImages.failed + xcodeVersions.failed + swiftVersions.failed
92-
}
93-
94-
public var totalRecords: Int {
95-
totalCreated + totalUpdated + totalFailed
96-
}
97-
9882
public init(
9983
restoreImages: TypeSyncResult, xcodeVersions: TypeSyncResult, swiftVersions: TypeSyncResult
10084
) {
@@ -103,26 +87,6 @@ public struct SyncEngine: Sendable {
10387
self.swiftVersions = swiftVersions
10488
}
10589

106-
/// Custom encoding to include computed properties
107-
public func encode(to encoder: Encoder) throws {
108-
var container = encoder.container(keyedBy: CodingKeys.self)
109-
try container.encode(restoreImages, forKey: .restoreImages)
110-
try container.encode(xcodeVersions, forKey: .xcodeVersions)
111-
try container.encode(swiftVersions, forKey: .swiftVersions)
112-
try container.encode(totalCreated, forKey: .totalCreated)
113-
try container.encode(totalUpdated, forKey: .totalUpdated)
114-
try container.encode(totalFailed, forKey: .totalFailed)
115-
}
116-
117-
private enum CodingKeys: String, CodingKey {
118-
case restoreImages
119-
case xcodeVersions
120-
case swiftVersions
121-
case totalCreated
122-
case totalUpdated
123-
case totalFailed
124-
}
125-
12690
/// Convert to JSON string
12791
public func toJSON(pretty: Bool = false) throws -> String {
12892
let encoder = JSONEncoder()

Sources/BushelCloudKit/Configuration/CommandConfigurations.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public struct SyncConfiguration: Sendable {
4343
public var force: Bool
4444
public var minInterval: Int?
4545
public var source: String?
46-
public var jsonOutput: Bool
4746
public var jsonOutputFile: String?
4847

4948
public init(
@@ -57,7 +56,6 @@ public struct SyncConfiguration: Sendable {
5756
force: Bool = false,
5857
minInterval: Int? = nil,
5958
source: String? = nil,
60-
jsonOutput: Bool = false,
6159
jsonOutputFile: String? = nil
6260
) {
6361
self.dryRun = dryRun
@@ -70,7 +68,6 @@ public struct SyncConfiguration: Sendable {
7068
self.force = force
7169
self.minInterval = minInterval
7270
self.source = source
73-
self.jsonOutput = jsonOutput
7471
self.jsonOutputFile = jsonOutputFile
7572
}
7673
}

Sources/BushelCloudKit/Configuration/ConfigurationKeys.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ internal enum ConfigurationKeys {
107107
internal static let force = ConfigKey<Bool>(bushelPrefixed: "sync.force")
108108
internal static let minInterval = OptionalConfigKey<Int>(bushelPrefixed: "sync.min_interval")
109109
internal static let source = OptionalConfigKey<String>(bushelPrefixed: "sync.source")
110-
internal static let jsonOutput = ConfigKey<Bool>(bushelPrefixed: "sync.json_output")
111110
internal static let jsonOutputFile = OptionalConfigKey<String>(bushelPrefixed: "sync.json_output_file")
112111
}
113112

Sources/BushelCloudKit/Configuration/ConfigurationLoader+Loading.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ extension ConfigurationLoader {
9595
force: read(ConfigurationKeys.Sync.force),
9696
minInterval: read(ConfigurationKeys.Sync.minInterval),
9797
source: read(ConfigurationKeys.Sync.source),
98-
jsonOutput: read(ConfigurationKeys.Sync.jsonOutput),
9998
jsonOutputFile: read(ConfigurationKeys.Sync.jsonOutputFile)
10099
)
101100

0 commit comments

Comments
 (0)