Let's walk through the process of adding a new String-typed setting:
-
Add a new setting to BenchmarkSettings.swift:
a. Add a new setting type:
public struct MySetting: BenchmarkSetting { var value: String init(_ value: String) { self.value = value } }
b. Add a default (if appropriate) to the
defaultSettings
in the same file:public let defaultSettings: [BenchmarkSetting] = [ ... MySetting("...") // default value goes here ... ]
c. Add a convenience getter to the
BenchmarkSettings
extension:var mySetting: String? { return self[MySetting.self]?.value }
If your setting has a default you can unwrap the optional and return non-optional result:
var mySetting: String { if let value = self[MySetting.self]?.value { return value } else { fatalError("MySetting setting must have a default.") } }
-
Add a new benchmark flag to BenchmarkArguments.swift:
a. Add a flag property:
@Option(help: "Useful description of MySetting here.") var mySettingFlagName: String?
b. Validate your flag value in
BenchmarkArguments.validate()
function if necessary.c. Convert command-line flag to a setting in
BenchmarkArgument.settings
computed property:if let value = mySettingFlagName { settings.append(MySetting(value)) }