Skip to content

Commit 09ec01b

Browse files
authored
Update index store to enum (#3469)
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
1 parent 8d49d0b commit 09ec01b

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

Sources/Commands/Options.swift

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,29 @@ 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?
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
251256

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
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
}
269+
270+
@Flag(help: "Enable or disable indexing-while-building feature")
271+
var indexStoreMode: StoreMode = .autoIndexStore
257272

258273
/// Whether to enable generation of `.swiftinterface`s alongside `.swiftmodule`s.
259274
@Flag(name: .customLong("enable-parseable-module-interfaces"))

Sources/Commands/SwiftTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ public class SwiftTool {
782782
shouldLinkStaticSwiftStdlib: options.shouldLinkStaticSwiftStdlib,
783783
sanitizers: options.enabledSanitizers,
784784
enableCodeCoverage: options.shouldEnableCodeCoverage,
785-
indexStoreMode: options.indexStore,
785+
indexStoreMode: options.indexStoreMode.indexStoreMode,
786786
enableParseableModuleInterfaces: options.shouldEnableParseableModuleInterfaces,
787787
emitSwiftModuleSeparately: options.emitSwiftModuleSeparately,
788788
useIntegratedSwiftDriver: options.useIntegratedSwiftDriver,

0 commit comments

Comments
 (0)