@@ -3,13 +3,17 @@ import SwiftlyCore
33
44internal struct Use : SwiftlyCommand {
55 public static var configuration = CommandConfiguration (
6- abstract: " Set the active toolchain. "
6+ abstract: " Set the active toolchain. If no toolchain is provided, print the currently in-use toolchain, if any. "
77 )
88
99 @Argument ( help: ArgumentHelp (
1010 " The toolchain to use. " ,
1111 discussion: """
1212
13+ If no toolchain is provided, the currently in-use toolchain will be printed, if any:
14+
15+ $ swiftly use
16+
1317 The string " latest " can be provided to use the most recent stable version release:
1418
1519 $ swiftly use latest
@@ -32,18 +36,26 @@ internal struct Use: SwiftlyCommand {
3236 Likewise, the latest snapshot associated with a given development branch can be \
3337 used by omitting the date:
3438
35- $ swiftly install 5.7-snapshot
36- $ swiftly install main-snapshot
39+ $ swiftly use 5.7-snapshot
40+ $ swiftly use main-snapshot
3741 """
3842 ) )
39- var toolchain : String
43+ var toolchain : String ?
4044
4145 internal mutating func run( ) async throws {
42- let selector = try ToolchainSelector ( parsing: self . toolchain)
4346 var config = try Config . load ( )
4447
48+ guard let toolchain = self . toolchain else {
49+ if let inUse = config. inUse {
50+ SwiftlyCore . print ( " \( inUse) (in use) " )
51+ }
52+ return
53+ }
54+
55+ let selector = try ToolchainSelector ( parsing: toolchain)
56+
4557 guard let toolchain = config. listInstalledToolchains ( selector: selector) . max ( ) else {
46- SwiftlyCore . print ( " No installed toolchains match \" \( self . toolchain) \" " )
58+ SwiftlyCore . print ( " No installed toolchains match \" \( toolchain) \" " )
4759 return
4860 }
4961
0 commit comments