Skip to content

Commit 28c5730

Browse files
authored
Update index store to enum (#3469) (#3493)
motivation: The issue is caused by indexStoreMode: Bool? so it's set to nil when running --help on any subcommand. It can be solved by setting to either true or false, but by choosing either true or false we lose auto which is our default. Using an enum solves the issue of having a nil value by using the case autoIndexStoreand preserves the ability to use auto as our default. changes: move indexStoreMode to an enum (cherry picked from commit 09ec01b)
1 parent 509abfa commit 28c5730

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

Sources/Commands/Options.swift

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,30 @@ public struct SwiftToolOptions: ParsableArguments {
246246
@Flag(name: [.long, .customLong("disable-automatic-resolution")], help: "Disable automatic resolution if Package.resolved file is out-of-date")
247247
var forceResolvedVersions: Bool = false
248248

249-
@Flag(name: .customLong("index-store"), inversion: .prefixedEnableDisable, help: "Enable or disable indexing-while-building feature")
250-
var indexStoreEnable: Bool?
251-
252-
/// The mode to use for indexing-while-building feature.
253-
var indexStore: BuildParameters.IndexStoreMode {
254-
guard let enable = indexStoreEnable else { return .auto }
255-
return enable ? .on : .off
249+
// @Flag works best when there is a default value present
250+
// if true, false aren't enough and a third state is needed
251+
// nil should not be the goto. Instead create an enum
252+
enum StoreMode: EnumerableFlag {
253+
case autoIndexStore
254+
case enableIndexStore
255+
case disableIndexStore
256+
257+
/// The mode to use for indexing-while-building feature.
258+
var indexStoreMode: BuildParameters.IndexStoreMode {
259+
switch self {
260+
case .autoIndexStore:
261+
return .auto
262+
case .enableIndexStore:
263+
return .on
264+
case .disableIndexStore:
265+
return .off
266+
}
267+
}
256268
}
257269

270+
@Flag(help: "Enable or disable indexing-while-building feature")
271+
var indexStoreMode: StoreMode = .autoIndexStore
272+
258273
/// Whether to enable generation of `.swiftinterface`s alongside `.swiftmodule`s.
259274
@Flag(name: .customLong("enable-parseable-module-interfaces"))
260275
var shouldEnableParseableModuleInterfaces: Bool = false

Sources/Commands/SwiftTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ public class SwiftTool {
795795
shouldLinkStaticSwiftStdlib: options.shouldLinkStaticSwiftStdlib,
796796
sanitizers: options.enabledSanitizers,
797797
enableCodeCoverage: options.shouldEnableCodeCoverage,
798-
indexStoreMode: options.indexStore,
798+
indexStoreMode: options.indexStoreMode.indexStoreMode,
799799
enableParseableModuleInterfaces: options.shouldEnableParseableModuleInterfaces,
800800
emitSwiftModuleSeparately: options.emitSwiftModuleSeparately,
801801
useIntegratedSwiftDriver: options.useIntegratedSwiftDriver,

0 commit comments

Comments
 (0)