Skip to content

Commit ea98a31

Browse files
authored
Code and documentation cleanup (#256)
Omit internal access control, if let shorthand, fix typos.
1 parent f8a8dd4 commit ea98a31

22 files changed

+76
-79
lines changed

DESIGN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ To use the latest installed main snapshot, leave off the date:
223223

224224
`swiftly use main-snapshot`
225225

226-
The use subcommand also supports `.swift-version` files. If a ".swift-version" file is present in the current working directory, or an ancestory directory, then swiftly will update that file with the new version to use. This can be a useful feature for a team to share and align on toolchain versions with git. As a special case, if swiftly could not find a version file, but it could find a Package.swift file it will create a new version file for you in the package and set that to the requested toolchain version.
226+
The use subcommand also supports `.swift-version` files. If a ".swift-version" file is present in the current working directory, or an ancestry directory, then swiftly will update that file with the new version to use. This can be a useful feature for a team to share and align on toolchain versions with git. As a special case, if swiftly could not find a version file, but it could find a Package.swift file it will create a new version file for you in the package and set that to the requested toolchain version.
227227

228228
Note: The `.swift-version` file mechanisms can be overridden using the `--global-default` flag so that your swiftly installation's default toolchain can be set explicitly.
229229

Documentation/SwiftlyDocs.docc/automated-install.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ To begin using installed swiftly from your current shell, first run the followin
3434
. "/root/.local/share/swiftly/env.sh"
3535
```
3636

37-
> Note: on macOS systems you may need to run 'hash -r' to recalcuate the zsh PATH cache when installing swiftly and toolchains.
37+
> Note: on macOS systems you may need to run 'hash -r' to recalculate the zsh PATH cache when installing swiftly and toolchains.
3838
3939
You can go ahead and add this command to the list of commands in your build script so that the build can proceed to call swiftly from the path. The usual next step is to install a specific swift toolchain like this:
4040

Documentation/SwiftlyDocs.docc/swiftly-cli-reference.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Likewise, the available toolchains associated with a given minor version can be
123123

124124
$ swiftly list-available 5.2
125125

126-
The installed snapshots for a given devlopment branch can be listed by specifying the branch as the selector:
126+
The installed snapshots for a given development branch can be listed by specifying the branch as the selector:
127127

128128
$ swiftly list-available main-snapshot
129129
$ swiftly list-available x.y-snapshot
@@ -301,7 +301,7 @@ Likewise, the installed toolchains associated with a given minor version can be
301301

302302
$ swiftly list 5.2
303303

304-
The installed snapshots for a given devlopment branch can be listed by specifying the branch as the selector:
304+
The installed snapshots for a given development branch can be listed by specifying the branch as the selector:
305305

306306
$ swiftly list main-snapshot
307307
$ swiftly list 5.7-snapshot
@@ -522,7 +522,7 @@ If the command that you are running needs the arguments with the '+' prefixes th
522522

523523
$ swiftly run ./myscript.sh ++abcde
524524

525-
The script will receive the argument as '+abcde'. If there are multiple arguments with the '+' prefix that should be escaped you can disable the selection using a '++' argument, which turns off any selector argument processing for subsequent arguments. This is anologous to the '--' that turns off flag and option processing for subsequent arguments in many argument parsers.
525+
The script will receive the argument as '+abcde'. If there are multiple arguments with the '+' prefix that should be escaped you can disable the selection using a '++' argument, which turns off any selector argument processing for subsequent arguments. This is analogous to the '--' that turns off flag and option processing for subsequent arguments in many argument parsers.
526526

527527
$ swiftly run ./myscript.sh ++ +abcde +xyz
528528

Documentation/SwiftlyDocs.docc/uninstall-toolchains.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ If you have a released version that you want to uninstall then give the exact th
1010
$ swiftly uninstall 5.6.1
1111
```
1212

13-
When you're done working with every patch of a minor swift release you can remove them all by omiting the patch version.
13+
When you're done working with every patch of a minor swift release you can remove them all by omitting the patch version.
1414

1515
```
1616
$ swiftly uninstall 5.6

Sources/LinuxPlatform/Extract.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func copyData(readArchive: OpaquePointer?, writeArchive: OpaquePointer?) throws
4444
/// the provided closure which will return the path the file will be written to.
4545
///
4646
/// This uses libarchive under the hood, so a wide variety of archive formats are supported (e.g. .tar.gz).
47-
internal func extractArchive(atPath archivePath: URL, transform: (String) -> URL) throws {
47+
func extractArchive(atPath archivePath: URL, transform: (String) -> URL) throws {
4848
var flags = Int32(0)
4949
flags = ARCHIVE_EXTRACT_TIME
5050
flags |= ARCHIVE_EXTRACT_PERM

Sources/LinuxPlatform/Linux.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public struct Linux: Platform {
248248
if requireSignatureValidation {
249249
guard (try? self.runProgram("gpg", "--version", quiet: true)) != nil else {
250250
var msg = "gpg is not installed. "
251-
if let manager = manager {
251+
if let manager {
252252
msg += """
253253
You can install it by running this command as root:
254254
\(manager) -y install gpg
@@ -416,7 +416,7 @@ public struct Linux: Platform {
416416
}
417417

418418
private func manualSelectPlatform(_ platformPretty: String?) async -> PlatformDefinition {
419-
if let platformPretty = platformPretty {
419+
if let platformPretty {
420420
print("\(platformPretty) is not an officially supported platform, but the toolchains for another platform may still work on it.")
421421
} else {
422422
print("This platform could not be detected, but a toolchain for one of the supported platforms may work on it.")

Sources/Swiftly/Config.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public struct Config: Codable, Equatable {
1111
public var platform: PlatformDefinition
1212
public var version: SwiftlyVersion?
1313

14-
internal init(inUse: ToolchainVersion?, installedToolchains: Set<ToolchainVersion>, platform: PlatformDefinition) {
14+
init(inUse: ToolchainVersion?, installedToolchains: Set<ToolchainVersion>, platform: PlatformDefinition) {
1515
self.inUse = inUse
1616
self.installedToolchains = installedToolchains
1717
self.platform = platform

Sources/Swiftly/Init.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ArgumentParser
22
import Foundation
33
import SwiftlyCore
44

5-
internal struct Init: SwiftlyCommand {
5+
struct Init: SwiftlyCommand {
66
public static var configuration = CommandConfiguration(
77
abstract: "Perform swiftly initialization into your user account."
88
)
@@ -29,12 +29,12 @@ internal struct Init: SwiftlyCommand {
2929

3030
public mutating func validate() throws {}
3131

32-
internal mutating func run() async throws {
32+
mutating func run() async throws {
3333
try await Self.execute(assumeYes: self.root.assumeYes, noModifyProfile: self.noModifyProfile, overwrite: self.overwrite, platform: self.platform, verbose: self.root.verbose, skipInstall: self.skipInstall, quietShellFollowup: self.quietShellFollowup)
3434
}
3535

3636
/// Initialize the installation of swiftly.
37-
internal static func execute(assumeYes: Bool, noModifyProfile: Bool, overwrite: Bool, platform: String?, verbose: Bool, skipInstall: Bool, quietShellFollowup: Bool) async throws {
37+
static func execute(assumeYes: Bool, noModifyProfile: Bool, overwrite: Bool, platform: String?, verbose: Bool, skipInstall: Bool, quietShellFollowup: Bool) async throws {
3838
try Swiftly.currentPlatform.verifySwiftlySystemPrerequisites()
3939

4040
var config = try? Config.load()

Sources/Swiftly/List.swift

+9-10
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ struct List: SwiftlyCommand {
2525
2626
$ swiftly list 5.2
2727
28-
The installed snapshots for a given devlopment branch can be listed by specifying the branch as the selector:
28+
The installed snapshots for a given development branch can be listed by specifying the branch as the selector:
2929
3030
$ swiftly list main-snapshot
3131
$ swiftly list 5.7-snapshot
3232
"""
3333
))
3434
var toolchainSelector: String?
3535

36-
internal mutating func run() async throws {
36+
mutating func run() async throws {
3737
try validateSwiftly()
3838
let selector = try self.toolchainSelector.map { input in
3939
try ToolchainSelector(parsing: input)
@@ -46,7 +46,7 @@ struct List: SwiftlyCommand {
4646

4747
let printToolchain = { (toolchain: ToolchainVersion) in
4848
var message = "\(toolchain)"
49-
if let inUse = inUse, toolchain == inUse {
49+
if let inUse, toolchain == inUse {
5050
message += " (in use)"
5151
}
5252
if toolchain == config.inUse {
@@ -56,20 +56,19 @@ struct List: SwiftlyCommand {
5656
}
5757

5858
if let selector {
59-
let modifier: String
60-
switch selector {
59+
let modifier = switch selector {
6160
case let .stable(major, minor, nil):
6261
if let minor {
63-
modifier = "Swift \(major).\(minor) release"
62+
"Swift \(major).\(minor) release"
6463
} else {
65-
modifier = "Swift \(major) release"
64+
"Swift \(major) release"
6665
}
6766
case .snapshot(.main, nil):
68-
modifier = "main development snapshot"
67+
"main development snapshot"
6968
case let .snapshot(.release(major, minor), nil):
70-
modifier = "\(major).\(minor) development snapshot"
69+
"\(major).\(minor) development snapshot"
7170
default:
72-
modifier = "matching"
71+
"matching"
7372
}
7473

7574
let message = "Installed \(modifier) toolchains"

Sources/Swiftly/ListAvailable.swift

+8-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct ListAvailable: SwiftlyCommand {
2525
2626
$ swiftly list-available 5.2
2727
28-
The installed snapshots for a given devlopment branch can be listed by specifying the branch as the selector:
28+
The installed snapshots for a given development branch can be listed by specifying the branch as the selector:
2929
3030
$ swiftly list-available main-snapshot
3131
$ swiftly list-available x.y-snapshot
@@ -39,7 +39,7 @@ struct ListAvailable: SwiftlyCommand {
3939
case toolchainSelector
4040
}
4141

42-
internal mutating func run() async throws {
42+
mutating func run() async throws {
4343
try validateSwiftly()
4444
let selector = try self.toolchainSelector.map { input in
4545
try ToolchainSelector(parsing: input)
@@ -80,20 +80,19 @@ struct ListAvailable: SwiftlyCommand {
8080
}
8181

8282
if let selector {
83-
let modifier: String
84-
switch selector {
83+
let modifier = switch selector {
8584
case let .stable(major, minor, nil):
8685
if let minor {
87-
modifier = "Swift \(major).\(minor) release"
86+
"Swift \(major).\(minor) release"
8887
} else {
89-
modifier = "Swift \(major) release"
88+
"Swift \(major) release"
9089
}
9190
case .snapshot(.main, nil):
92-
modifier = "main development snapshot"
91+
"main development snapshot"
9392
case let .snapshot(.release(major, minor), nil):
94-
modifier = "\(major).\(minor) development snapshot"
93+
"\(major).\(minor) development snapshot"
9594
default:
96-
modifier = "matching"
95+
"matching"
9796
}
9897

9998
let message = "Available \(modifier) toolchains"

Sources/Swiftly/Run.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ArgumentParser
22
import Foundation
33
import SwiftlyCore
44

5-
internal struct Run: SwiftlyCommand {
5+
struct Run: SwiftlyCommand {
66
public static var configuration = CommandConfiguration(
77
abstract: "Run a command while proxying to the selected toolchain commands."
88
)
@@ -43,7 +43,7 @@ internal struct Run: SwiftlyCommand {
4343
4444
The script will receive the argument as '+abcde'. If there are multiple arguments with the '+' prefix \
4545
that should be escaped you can disable the selection using a '++' argument, which turns off any \
46-
selector argument processing for subsequent arguments. This is anologous to the '--' that turns off \
46+
selector argument processing for subsequent arguments. This is analogous to the '--' that turns off \
4747
flag and option processing for subsequent arguments in many argument parsers.
4848
4949
$ swiftly run ./myscript.sh ++ +abcde +xyz
@@ -53,7 +53,7 @@ internal struct Run: SwiftlyCommand {
5353
))
5454
var command: [String]
5555

56-
internal mutating func run() async throws {
56+
mutating func run() async throws {
5757
try validateSwiftly()
5858

5959
// Handle the specific case where help is requested of the run subcommand
@@ -67,9 +67,9 @@ internal struct Run: SwiftlyCommand {
6767

6868
let toolchain: ToolchainVersion?
6969

70-
if let selector = selector {
70+
if let selector {
7171
let matchedToolchain = config.listInstalledToolchains(selector: selector).max()
72-
guard let matchedToolchain = matchedToolchain else {
72+
guard let matchedToolchain else {
7373
throw SwiftlyError(message: "The selected toolchain \(selector.description) didn't match any of the installed toolchains. You can install it with `swiftly install \(selector.description)`")
7474
}
7575

@@ -78,14 +78,14 @@ internal struct Run: SwiftlyCommand {
7878
let (version, result) = try await selectToolchain(config: &config)
7979

8080
// Abort on any errors relating to swift version files
81-
if case let .swiftVersionFile(_, _, error) = result, let error = error {
81+
if case let .swiftVersionFile(_, _, error) = result, let error {
8282
throw error
8383
}
8484

8585
toolchain = version
8686
}
8787

88-
guard let toolchain = toolchain else {
88+
guard let toolchain else {
8989
throw SwiftlyError(message: "No installed swift toolchain is selected from either from a .swift-version file, or the default. You can try using one that's already installed with `swiftly use <toolchain version>` or install a new toolchain to use with `swiftly install --use <toolchain version>`.")
9090
}
9191

Sources/Swiftly/SelfUpdate.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import TSCUtility
55

66
import SwiftlyCore
77

8-
internal struct SelfUpdate: SwiftlyCommand {
8+
struct SelfUpdate: SwiftlyCommand {
99
public static var configuration = CommandConfiguration(
1010
abstract: "Update the version of swiftly itself."
1111
)
@@ -16,7 +16,7 @@ internal struct SelfUpdate: SwiftlyCommand {
1616
case root
1717
}
1818

19-
internal mutating func run() async throws {
19+
mutating func run() async throws {
2020
try validateSwiftly()
2121

2222
let swiftlyBin = Swiftly.currentPlatform.swiftlyBinDir.appendingPathComponent("swiftly")

Sources/Swiftly/Swiftly.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public struct Swiftly: SwiftlyCommand {
4949
public init() {}
5050

5151
#if os(Linux)
52-
internal static let currentPlatform = Linux.currentPlatform
52+
static let currentPlatform = Linux.currentPlatform
5353
#elseif os(macOS)
54-
internal static let currentPlatform = MacOS.currentPlatform
54+
static let currentPlatform = MacOS.currentPlatform
5555
#endif
5656
}
5757

Sources/Swiftly/Update.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct Update: SwiftlyCommand {
120120
try await Uninstall.execute(parameters.oldToolchain, &config, verbose: self.root.verbose)
121121
SwiftlyCore.print("Successfully updated \(parameters.oldToolchain)\(newToolchain)")
122122

123-
if let postInstallScript = postInstallScript {
123+
if let postInstallScript {
124124
guard let postInstallFile = self.postInstallFile else {
125125
throw SwiftlyError(message: """
126126

Sources/Swiftly/Use.swift

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ArgumentParser
22
import Foundation
33
import SwiftlyCore
44

5-
internal struct Use: SwiftlyCommand {
5+
struct Use: SwiftlyCommand {
66
public static var configuration = CommandConfiguration(
77
abstract: "Set the in-use or default toolchain. If no toolchain is provided, print the currently in-use toolchain, if any."
88
)
@@ -54,7 +54,7 @@ internal struct Use: SwiftlyCommand {
5454
))
5555
var toolchain: String?
5656

57-
internal mutating func run() async throws {
57+
mutating func run() async throws {
5858
try validateSwiftly()
5959
var config = try Config.load()
6060

@@ -63,11 +63,11 @@ internal struct Use: SwiftlyCommand {
6363
let (selectedVersion, result) = try await selectToolchain(config: &config, globalDefault: self.globalDefault)
6464

6565
// Abort on any errors with the swift version files
66-
if case let .swiftVersionFile(_, _, error) = result, let error = error {
66+
if case let .swiftVersionFile(_, _, error) = result, let error {
6767
throw error
6868
}
6969

70-
guard let selectedVersion = selectedVersion else {
70+
guard let selectedVersion else {
7171
// Return with nothing if there's no toolchain that is selected
7272
return
7373
}
@@ -107,7 +107,7 @@ internal struct Use: SwiftlyCommand {
107107
}
108108

109109
/// Use a toolchain. This method can modify and save the input config and also create/modify a `.swift-version` file.
110-
internal static func execute(_ toolchain: ToolchainVersion, globalDefault: Bool, assumeYes: Bool = true, _ config: inout Config) async throws {
110+
static func execute(_ toolchain: ToolchainVersion, globalDefault: Bool, assumeYes: Bool = true, _ config: inout Config) async throws {
111111
let (selectedVersion, result) = try await selectToolchain(config: &config, globalDefault: globalDefault)
112112

113113
var message: String
@@ -136,14 +136,14 @@ internal struct Use: SwiftlyCommand {
136136
message = "The global default toolchain has been set to `\(toolchain)`"
137137
}
138138

139-
if let selectedVersion = selectedVersion {
139+
if let selectedVersion {
140140
message += " (was \(selectedVersion.name))"
141141
}
142142

143143
SwiftlyCore.print(message)
144144
}
145145

146-
internal static func findNewVersionFile() -> URL? {
146+
static func findNewVersionFile() -> URL? {
147147
var cwd = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
148148

149149
while cwd.path != "" && cwd.path != "/" {
@@ -203,7 +203,7 @@ public func selectToolchain(config: inout Config, globalDefault: Bool = false) a
203203
if FileManager.default.fileExists(atPath: svFile.path) {
204204
let contents = try? String(contentsOf: svFile, encoding: .utf8)
205205

206-
guard let contents = contents else {
206+
guard let contents else {
207207
return (nil, .swiftVersionFile(svFile, nil, SwiftlyError(message: "The swift version file could not be read: \(svFile)")))
208208
}
209209

@@ -219,7 +219,7 @@ public func selectToolchain(config: inout Config, globalDefault: Bool = false) a
219219
return (nil, .swiftVersionFile(svFile, nil, SwiftlyError(message: "The swift version file is malformed: \(svFile) \(error)")))
220220
}
221221

222-
guard let selector = selector else {
222+
guard let selector else {
223223
return (nil, .swiftVersionFile(svFile, nil, SwiftlyError(message: "The swift version file is malformed: \(svFile)")))
224224
}
225225

0 commit comments

Comments
 (0)