Skip to content

Commit 76ef042

Browse files
authored
Update documentation and online help around global default toolchains (#224)
Update documentation and online help to add more clarity about the global default and in-use toolchains Skip prompting to update an existing swift version file Add more informative messages when using toolchains to indicate what actually changed
1 parent 0550466 commit 76ef042

File tree

3 files changed

+54
-20
lines changed

3 files changed

+54
-20
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Note that listing available snapshots before the latest release (major and minor
145145

146146
## use
147147

148-
Set the in-use toolchain. If no toolchain is provided, print the currently in-use toolchain, if any.
148+
Set the in-use or default toolchain. If no toolchain is provided, print the currently in-use toolchain, if any.
149149

150150
```
151151
swiftly use [--print-location] [--global-default] [--assume-yes] [--verbose] [<toolchain>] [--version] [--help]
@@ -158,7 +158,7 @@ swiftly use [--print-location] [--global-default] [--assume-yes] [--verbose] [<t
158158

159159
**--global-default:**
160160

161-
*Use the global default, ignoring any .swift-version files.*
161+
*Set the global default toolchain that is used when there are no .swift-version files.*
162162

163163

164164
**--assume-yes:**
@@ -176,7 +176,7 @@ swiftly use [--print-location] [--global-default] [--assume-yes] [--verbose] [<t
176176
*The toolchain to use.*
177177

178178

179-
If no toolchain is provided, the currently in-use toolchain will be printed, if any:
179+
If no toolchain is provided, the currently in-use toolchain will be printed, if any. This is based on the current working directory and `.swift-version` files if one is present. If the in-use toolchain is also the global default then it will be shown as the default.
180180

181181
$ swiftly use
182182

Documentation/SwiftlyDocs.docc/use-toolchains.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ When you install a toolchain you can start using it right away. If you don't hav
99
```
1010
$ swiftly install latest
1111
$ swift --version
12-
Swift version 6.0.1 (swift-6.0.1-RELEASE)
12+
Swift version 6.0.3 (swift-6.0.3-RELEASE)
1313
Target: aarch64-unknown-linux-gnu
1414
$ swift build # Build with the current toolchain
1515
```
@@ -27,11 +27,18 @@ $ swift build # Builds with the latest snapshot toolchain on the main branch
2727
$ lldb # Run the debugger from the latest snapshot toolchain
2828
```
2929

30+
The use command doesn't require a full version. It is sufficient to provide just a major version, or the major and minor versions. Swiftly will use the newest matching version that you have installed, if any.
31+
32+
```
33+
$ swiftly use 5
34+
swift --version # Version matches the 5.10.1 toolchain that was installed above
35+
```
36+
3037
If you're not certain which toolchain is in-use then use the bare `swiftly use` command to provide details:
3138

3239
```
3340
$ swiftly use
34-
Swift 6.0.1 (default)
41+
Swift 5.10.1 (default)
3542
```
3643

3744
You can print the exact toolchain location with the `--print-location` flag:
@@ -54,7 +61,7 @@ $ cat .swift-version
5461
6.0.1
5562
```
5663

57-
When a team member uses swiftly with this git repository it can use the correct toolchain version automatically:
64+
When a team member uses swiftly with this git repository the toolchain that is in use matches the version in the file.
5865

5966
```
6067
$ cd path/to/git/repository
@@ -63,7 +70,7 @@ Swift version 6.0.1 (swift-6.0.1-RELEASE)
6370
Target: aarch64-unknown-linux-gnu
6471
```
6572

66-
If that team member doesn't have the toolchain installed on their system there will be a warning. They can install the selected toolchain automatically like this:
73+
If that team member doesn't have the toolchain installed on their system there will be an error. They can install the selected toolchain automatically like this:
6774

6875
```
6976
$ cd path/to/git/repository
@@ -77,3 +84,30 @@ $ swiftly run swift build +main-snapshot
7784
```
7885

7986
> Note: The toolchain must be installed on your system before you can run with it.
87+
88+
The `.swift version` file, if it is present in your working directory (or parent) will select the toolchain that is in use. If you are working in a directory that doesn't have this file, then you can set a global default toolchain to use in these places.
89+
90+
```
91+
$ swiftly use --global-default 6.0.1
92+
```
93+
94+
Here the `--global-default` flag ensures that the default is set globally to the "6.0.1" toolchain whenever there isn't a swift version file, and there isn't a version specified in the `swiftly run` command. Also, this flag doesn't attempt to create a swift version file, or update it if it already exists.
95+
96+
## In use toolchains and default toolchains
97+
98+
When you list installed toolchains or use the `swiftly use` command to print the current in use toolchain there will be tags for both "in use" and "default." Sometimes the same toolchain will have both tags!
99+
100+
```
101+
$ swiftly list
102+
Installed release toolchains
103+
----------------------------
104+
Swift 6.0.3
105+
Swift 6.0.2 (in use) (default)
106+
107+
Installed snapshot toolchains
108+
-----------------------------
109+
```
110+
111+
Whenever a toolchain is tagged as "in use" indicates the toolchain that will be used when running toolchain commands from your current working directory. The one that is selected is based either on what is in a `.swift-version` file or the global default if there is no such file there.
112+
113+
The default tag is used to show the global default toolchain, which is independent of any swift version file. The global default is there for cases where the file doesn't exist. It sets the toolchain that is in use in those cases.

Sources/Swiftly/Use.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import SwiftlyCore
44

55
internal struct Use: SwiftlyCommand {
66
public static var configuration = CommandConfiguration(
7-
abstract: "Set the in-use toolchain. If no toolchain is provided, print the currently in-use toolchain, if any."
7+
abstract: "Set the in-use or default toolchain. If no toolchain is provided, print the currently in-use toolchain, if any."
88
)
99

1010
@Flag(name: .shortAndLong, help: "Print the location of the in-use toolchain. This is valid only when there is no toolchain argument.")
1111
var printLocation: Bool = false
1212

13-
@Flag(name: .shortAndLong, help: "Use the global default, ignoring any .swift-version files.")
13+
@Flag(name: .shortAndLong, help: "Set the global default toolchain that is used when there are no .swift-version files.")
1414
var globalDefault: Bool = false
1515

1616
@OptionGroup var root: GlobalOptions
@@ -19,7 +19,10 @@ internal struct Use: SwiftlyCommand {
1919
"The toolchain to use.",
2020
discussion: """
2121
22-
If no toolchain is provided, the currently in-use toolchain will be printed, if any:
22+
If no toolchain is provided, the currently in-use toolchain will be printed, if any. \
23+
This is based on the current working directory and `.swift-version` files if one is \
24+
present. If the in-use toolchain is also the global default then it will be shown as \
25+
the default.
2326
2427
$ swiftly use
2528
@@ -107,18 +110,13 @@ internal struct Use: SwiftlyCommand {
107110
internal static func execute(_ toolchain: ToolchainVersion, globalDefault: Bool, assumeYes: Bool = true, _ config: inout Config) async throws {
108111
let (selectedVersion, result) = try await selectToolchain(config: &config, globalDefault: globalDefault)
109112

110-
if case let .swiftVersionFile(versionFile, _, _) = result {
111-
if !assumeYes {
112-
SwiftlyCore.print("The file `\(versionFile)` will be updated to set the new in-use toolchain for this project. Alternatively, you can set your default globally with the `--global-default` flag. Proceed with modifying this file?")
113-
114-
guard SwiftlyCore.promptForConfirmation(defaultBehavior: true) else {
115-
SwiftlyCore.print("Aborting setting in-use toolchain")
116-
return
117-
}
118-
}
113+
var message: String
119114

115+
if case let .swiftVersionFile(versionFile, _, _) = result {
120116
// We don't care in this case if there were any problems with the swift version files, just overwrite it with the new value
121117
try toolchain.name.write(to: versionFile, atomically: true, encoding: .utf8)
118+
119+
message = "The file `\(versionFile)` has been set to `\(toolchain)`"
122120
} else if let newVersionFile = findNewVersionFile(), !globalDefault {
123121
if !assumeYes {
124122
SwiftlyCore.print("A new file `\(newVersionFile)` will be created to set the new in-use toolchain for this project. Alternatively, you can set your default globally with the `--global-default` flag. Proceed with creating this file?")
@@ -130,12 +128,14 @@ internal struct Use: SwiftlyCommand {
130128
}
131129

132130
try toolchain.name.write(to: newVersionFile, atomically: true, encoding: .utf8)
131+
132+
message = "The file `\(newVersionFile)` has been set to `\(toolchain)`"
133133
} else {
134134
config.inUse = toolchain
135135
try config.save()
136+
message = "The global default toolchain has set to `\(toolchain)`"
136137
}
137138

138-
var message = "Set the in-use toolchain to \(toolchain)"
139139
if let selectedVersion = selectedVersion {
140140
message += " (was \(selectedVersion.name))"
141141
}

0 commit comments

Comments
 (0)