Implement parsing of installer-environment key=value pairs

This commit is contained in:
Greg Neagle
2024-07-08 22:11:07 -07:00
parent 365a56df75
commit 974089fc0d
2 changed files with 18 additions and 2 deletions
@@ -169,6 +169,23 @@ struct ApplePackageOptions: ParsableArguments {
help: ArgumentHelp("Specifies a key/value pair to set environment variables for use by /usr/sbin/installer. A key/value pair of USER=CURRENT_CONSOLE_USER indicates that USER be set to the GUI user, otherwise root. Can be specified multiple times.", valueName: "key=value")
)
var installerEnvironment = [String]()
var installerEnvironmentDict: [String: String] {
var dict = [String: String]()
for line in installerEnvironment {
let parts = line.split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false)
if parts.count == 2 {
dict[String(parts[0])] = String(parts[1])
}
}
return dict
}
mutating func validate() throws {
if !installerEnvironment.isEmpty, installerEnvironmentDict.isEmpty {
throw ValidationError("'installer-environment' values must take the form of 'key=value")
}
}
}
struct UnattendedInstallOptions: ParsableArguments {
+1 -2
View File
@@ -522,8 +522,7 @@ func makepkginfo(_ filepath: String?,
pkginfo["uninstallable"] = true
}
if !options.pkg.installerEnvironment.isEmpty {
// TODO: actually support installer_environment correctly
pkginfo["installer_environment"] = options.pkg.installerEnvironment
pkginfo["installer_environment"] = options.pkg.installerEnvironmentDict
}
if let notes = options.other.notes {
pkginfo["notes"] = readFileOrString(notes)