Skip to content

Commit

Permalink
Add Bazel support to guided setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ileitch committed Dec 18, 2024
1 parent c0e4371 commit 33c0b45
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
32 changes: 32 additions & 0 deletions Sources/Frontend/BazelProjectSetupGuide.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Foundation
import Logger
import ProjectDrivers
import Shared
import SystemPackage

final class BazelProjectSetupGuide: SetupGuideHelpers, SetupGuide {
static func detect() -> Self? {
guard BazelProjectDriver.isSupported else { return nil }
return Self()
}

var projectKindName: String {
"Bazel"
}

func perform() throws -> ProjectKind {
print(colorize("\nAdd the following snippet to your MODULE.bazel file:", .bold))
print(colorize("""
bazel_dep(name = "periphery", version = "\(PeripheryVersion)")
use_repo(use_extension("@periphery//bazel:generated.bzl", "generated"), "periphery_generated")
""", .lightGray))
print(colorize("\nEnter to continue when ready ", .bold), terminator: "")
_ = readLine()

return .bazel
}

var commandLineOptions: [String] {
["--bazel"]
}
}
13 changes: 11 additions & 2 deletions Sources/Frontend/GuidedSetup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ final class GuidedSetup: SetupGuideHelpers {
}
#endif

if let guide = BazelProjectSetupGuide.detect() {
projectGuides.append(guide)
}

var projectGuide_: SetupGuide?

if projectGuides.count > 1 {
print(colorize("Please select which project to use:", .bold))
print(colorize("Select which project to use:", .bold))
let kindName = select(single: projectGuides.map(\.projectKindName))
projectGuide_ = projectGuides.first { $0.projectKindName == kindName }
print("")
Expand Down Expand Up @@ -85,6 +89,11 @@ final class GuidedSetup: SetupGuideHelpers {
}

let parts = [bareCommand] + options
return parts.joined(separator: " \\\n ")

if options.count > 1 {
return parts.joined(separator: " \\\n ")
}

return parts.joined(separator: " ")
}
}
2 changes: 1 addition & 1 deletion Sources/Logger/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public enum ANSIColor: String {
case magenta = "\u{001B}[0;35m"
case boldMagenta = "\u{001B}[0;1;35m"
case cyan = "\u{001B}[0;36m"
case white = "\u{001B}[0;37m"
case lightGray = "\u{001B}[0;37m"
case gray = "\u{001B}[0;1;30m"
}

Expand Down

0 comments on commit 33c0b45

Please sign in to comment.