Allow to save .swift-version even .swift-version is missing (#385)

Allow to save .swift-version even for the first time
This commit is contained in:
Tatsuyuki Kobayashi 2022-10-08 19:38:17 +09:00 committed by GitHub
parent 94691a349b
commit db91a617e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 15 deletions

View File

@ -27,23 +27,22 @@ struct Local: ParsableCommand {
func run() throws {
let terminal = InteractiveWriter.stdout
let toolchainSystem = ToolchainSystem(fileSystem: localFileSystem)
guard let localVersion = try toolchainSystem.fetchLocalSwiftVersion() else {
terminal.logLookup("Version file is not present: ", toolchainSystem.swiftVersionPath)
return
}
guard let version = version else {
terminal.write("\(localVersion)", inColor: .green)
return
}
let versions = try toolchainSystem.fetchAllSwiftVersions()
if versions.contains(version) {
_ = try toolchainSystem.setLocalSwiftVersion(version)
if let version = version {
let versions = try toolchainSystem.fetchAllSwiftVersions()
if versions.contains(version) {
_ = try toolchainSystem.setLocalSwiftVersion(version)
} else {
terminal.write("The version \(version) hasn't been installed!", inColor: .red)
}
} else {
terminal.write("The version \(version) hasn't been installed!", inColor: .red)
let localVersion = try toolchainSystem.fetchLocalSwiftVersion()
if let localVersion = localVersion {
terminal.write("\(localVersion)", inColor: .green)
} else {
terminal.logLookup("Version file is not present: ", toolchainSystem.swiftVersionPath)
}
}
}
}