Skip to content

Commit 0c77a33

Browse files
authored
Refactor configuration keys into protocol-based ConfigKeyKit (#15)
1 parent 9f7565e commit 0c77a33

File tree

5 files changed

+665
-73
lines changed

5 files changed

+665
-73
lines changed

Package.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ let package = Package(
8787
.visionOS(.v2)
8888
],
8989
products: [
90+
.library(name: "ConfigKeyKit", targets: ["ConfigKeyKit"]),
9091
.library(name: "BushelCloudKit", targets: ["BushelCloudKit"]),
9192
.executable(name: "bushel-cloud", targets: ["BushelCloudCLI"])
9293
],
@@ -102,9 +103,15 @@ let package = Package(
102103
)
103104
],
104105
targets: [
106+
.target(
107+
name: "ConfigKeyKit",
108+
dependencies: [],
109+
swiftSettings: swiftSettings
110+
),
105111
.target(
106112
name: "BushelCloudKit",
107113
dependencies: [
114+
.target(name: "ConfigKeyKit"),
108115
.product(name: "MistKit", package: "MistKit"),
109116
.product(name: "BushelLogging", package: "BushelKit"),
110117
.product(name: "BushelFoundation", package: "BushelKit"),
@@ -123,6 +130,13 @@ let package = Package(
123130
],
124131
swiftSettings: swiftSettings
125132
),
133+
.testTarget(
134+
name: "ConfigKeyKitTests",
135+
dependencies: [
136+
.target(name: "ConfigKeyKit")
137+
],
138+
swiftSettings: swiftSettings
139+
),
126140
.testTarget(
127141
name: "BushelCloudKitTests",
128142
dependencies: [

Sources/BushelCloudKit/Configuration/ConfigurationKeys.swift

Lines changed: 72 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,76 +5,112 @@
55
// Configuration keys for reading from providers
66
//
77

8+
import ConfigKeyKit
89
import Foundation
910

1011
/// Configuration keys for reading from providers
1112
internal enum ConfigurationKeys {
13+
// MARK: - CloudKit Configuration
14+
1215
/// CloudKit configuration keys
1316
internal enum CloudKit {
14-
internal static let containerID = "cloudkit.container_id"
15-
internal static let containerIDEnv = "CLOUDKIT_CONTAINER_ID"
16-
internal static let keyID = "cloudkit.key_id"
17-
internal static let keyIDEnv = "CLOUDKIT_KEY_ID"
18-
internal static let privateKeyPath = "cloudkit.private_key_path"
19-
internal static let privateKeyPathEnv = "CLOUDKIT_PRIVATE_KEY_PATH"
17+
// Using base key with auto-generation (no prefix for CloudKit ENV vars)
18+
internal static let containerID = ConfigKey<String>(
19+
"cloudkit.container_id",
20+
envPrefix: nil, // Generates: CLI="cloudkit.container_id", ENV="CLOUDKIT_CONTAINER_ID"
21+
default: "iCloud.com.brightdigit.Bushel"
22+
)
23+
24+
internal static let keyID = OptionalConfigKey<String>(
25+
"cloudkit.key_id",
26+
envPrefix: nil
27+
)
28+
29+
internal static let privateKeyPath = OptionalConfigKey<String>(
30+
"cloudkit.private_key_path",
31+
envPrefix: nil
32+
)
2033
}
2134

35+
// MARK: - VirtualBuddy Configuration
36+
2237
/// VirtualBuddy TSS API configuration keys
2338
internal enum VirtualBuddy {
24-
internal static let apiKey = "virtualbuddy.api_key"
25-
internal static let apiKeyEnv = "VIRTUALBUDDY_API_KEY"
39+
internal static let apiKey = OptionalConfigKey<String>(
40+
"virtualbuddy.api_key",
41+
envPrefix: nil // Generates: ENV="VIRTUALBUDDY_API_KEY"
42+
)
2643
}
2744

45+
// MARK: - Fetch Configuration
46+
2847
/// Fetch throttling configuration keys
2948
internal enum Fetch {
30-
internal static let intervalGlobal = "fetch.interval_global"
31-
internal static let intervalGlobalEnv = "BUSHEL_FETCH_INTERVAL_GLOBAL"
49+
internal static let intervalGlobal = OptionalConfigKey<Double>(
50+
bushelPrefixed: "fetch.interval_global" // Generates: ENV="BUSHEL_FETCH_INTERVAL_GLOBAL"
51+
)
3252

33-
/// Per-source interval key prefix (e.g., "fetch.interval.appledb_dev")
34-
internal static func intervalKey(for source: String) -> String {
35-
"fetch.interval.\(source.replacingOccurrences(of: ".", with: "_"))"
53+
/// Generate per-source interval key dynamically
54+
/// - Parameter source: Data source identifier (e.g., "appledb.dev")
55+
/// - Returns: An OptionalConfigKey<Double> for the source-specific interval
56+
internal static func intervalKey(for source: String) -> OptionalConfigKey<Double> {
57+
let normalized = source.replacingOccurrences(of: ".", with: "_")
58+
return OptionalConfigKey<Double>(
59+
"fetch.interval.\(normalized)",
60+
envPrefix: nil // CLI: "fetch.interval.appledb_dev", ENV: "FETCH_INTERVAL_APPLEDB_DEV"
61+
)
3662
}
3763
}
3864

39-
/// Sync command configuration keys
65+
// MARK: - Sync Command Configuration
66+
67+
/// Sync command configuration keys (using base key with BUSHEL prefix)
4068
internal enum Sync {
41-
internal static let dryRun = "sync.dry_run"
42-
internal static let restoreImagesOnly = "sync.restore_images_only"
43-
internal static let xcodeOnly = "sync.xcode_only"
44-
internal static let swiftOnly = "sync.swift_only"
45-
internal static let noBetas = "sync.no_betas"
46-
internal static let noAppleWiki = "sync.no_apple_wiki"
47-
internal static let verbose = "sync.verbose"
48-
internal static let force = "sync.force"
49-
internal static let minInterval = "sync.min_interval"
50-
internal static let source = "sync.source"
69+
internal static let dryRun = ConfigKey<Bool>(bushelPrefixed: "sync.dry_run")
70+
internal static let restoreImagesOnly = ConfigKey<Bool>(bushelPrefixed: "sync.restore_images_only")
71+
internal static let xcodeOnly = ConfigKey<Bool>(bushelPrefixed: "sync.xcode_only")
72+
internal static let swiftOnly = ConfigKey<Bool>(bushelPrefixed: "sync.swift_only")
73+
internal static let noBetas = ConfigKey<Bool>(bushelPrefixed: "sync.no_betas")
74+
internal static let noAppleWiki = ConfigKey<Bool>(bushelPrefixed: "sync.no_apple_wiki")
75+
internal static let verbose = ConfigKey<Bool>(bushelPrefixed: "sync.verbose")
76+
internal static let force = ConfigKey<Bool>(bushelPrefixed: "sync.force")
77+
internal static let minInterval = OptionalConfigKey<Int>(bushelPrefixed: "sync.min_interval")
78+
internal static let source = OptionalConfigKey<String>(bushelPrefixed: "sync.source")
5179
}
5280

81+
// MARK: - Export Command Configuration
82+
5383
/// Export command configuration keys
5484
internal enum Export {
55-
internal static let output = "export.output"
56-
internal static let pretty = "export.pretty"
57-
internal static let signedOnly = "export.signed_only"
58-
internal static let noBetas = "export.no_betas"
59-
internal static let verbose = "export.verbose"
85+
internal static let output = OptionalConfigKey<String>(bushelPrefixed: "export.output")
86+
internal static let pretty = ConfigKey<Bool>(bushelPrefixed: "export.pretty")
87+
internal static let signedOnly = ConfigKey<Bool>(bushelPrefixed: "export.signed_only")
88+
internal static let noBetas = ConfigKey<Bool>(bushelPrefixed: "export.no_betas")
89+
internal static let verbose = ConfigKey<Bool>(bushelPrefixed: "export.verbose")
6090
}
6191

92+
// MARK: - Status Command Configuration
93+
6294
/// Status command configuration keys
6395
internal enum Status {
64-
internal static let errorsOnly = "status.errors_only"
65-
internal static let detailed = "status.detailed"
96+
internal static let errorsOnly = ConfigKey<Bool>(bushelPrefixed: "status.errors_only")
97+
internal static let detailed = ConfigKey<Bool>(bushelPrefixed: "status.detailed")
6698
}
6799

100+
// MARK: - List Command Configuration
101+
68102
/// List command configuration keys
69103
internal enum List {
70-
internal static let restoreImages = "list.restore_images"
71-
internal static let xcodeVersions = "list.xcode_versions"
72-
internal static let swiftVersions = "list.swift_versions"
104+
internal static let restoreImages = ConfigKey<Bool>(bushelPrefixed: "list.restore_images")
105+
internal static let xcodeVersions = ConfigKey<Bool>(bushelPrefixed: "list.xcode_versions")
106+
internal static let swiftVersions = ConfigKey<Bool>(bushelPrefixed: "list.swift_versions")
73107
}
74108

109+
// MARK: - Clear Command Configuration
110+
75111
/// Clear command configuration keys
76112
internal enum Clear {
77-
internal static let yes = "clear.yes"
78-
internal static let verbose = "clear.verbose"
113+
internal static let yes = ConfigKey<Bool>(bushelPrefixed: "clear.yes")
114+
internal static let verbose = ConfigKey<Bool>(bushelPrefixed: "clear.verbose")
79115
}
80116
}

0 commit comments

Comments
 (0)