Skip to content

Commit 942c4e4

Browse files
committed
Re-introduce the bare swiftly invocation in an uninstalled state redirecting to swiftly init subcommand
1 parent 55fc274 commit 942c4e4

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

Sources/Swiftly/Proxy.swift

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,32 @@ public enum Proxy {
1111
}
1212

1313
guard binName != "swiftly" else {
14-
// Treat this as a swiftly invocation
15-
await Swiftly.main()
16-
return
14+
// Treat this as a swiftly invocation, but first check that we are installed, bootstrapping
15+
// the installation process if we aren't.
16+
let configResult = Result { try Config.load() }
17+
18+
switch configResult {
19+
case .success:
20+
await Swiftly.main()
21+
return
22+
case let .failure(err):
23+
guard CommandLine.arguments.count > 0 else { fatalError("argv is not set") }
24+
25+
if CommandLine.arguments.count == 1 {
26+
// User ran swiftly with no extra arguments in an uninstalled environment, so we jump directly into
27+
// an simple init.
28+
try await Init.execute(assumeYes: false, noModifyProfile: false, overwrite: false, platform: nil, verbose: false, skipInstall: false)
29+
return
30+
} else if CommandLine.arguments.count >= 2 && CommandLine.arguments[1] == "init" {
31+
// Let the user run the init command with their arguments, if any.
32+
await Swiftly.main()
33+
return
34+
} else {
35+
// We've been invoked outside the "init" subcommand and we're not yet configured.
36+
// This will throw if the configuration couldn't be loaded and give the user an actionable message.
37+
throw err
38+
}
39+
}
1740
}
1841

1942
var config = try Config.load()

0 commit comments

Comments
 (0)