Skip to content

Commit e6d2490

Browse files
authored
fix cd bug, and clean up some color stuff (#2)
* clean up some color stuff * Update Sources/CreateProject/CreateProject.swift
1 parent 338e57d commit e6d2490

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

Sources/CreateProject/Color.swift

+13
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,17 @@ enum Color: String {
88
case magenta = "\u{001B}[0;35m"
99
case cyan = "\u{001B}[0;36m"
1010
case white = "\u{001B}[0;37m"
11+
12+
case bgBlack = "\u{001B}[0;40m"
13+
case bgRed = "\u{001B}[0;41m"
14+
case bgGreen = "\u{001B}[0;42m"
15+
case bgYellow = "\u{001B}[0;43m"
16+
case bgBlue = "\u{001B}[0;44m"
17+
case bgMagenta = "\u{001B}[0;45m"
18+
case bgCyan = "\u{001B}[0;46m"
19+
case bgWhite = "\u{001B}[0;47m"
20+
21+
static func +(color: Color, text: String) -> String {
22+
return color.rawValue + text + Color.reset.rawValue
23+
}
1124
}

Sources/CreateProject/CreateProject.swift

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ private struct CreateProject {
1111
let (projectPathExists, projectPathIsDirectory) = fileManager.directoryExists(atPath: projectPath)
1212

1313
if !projectPathExists, !projectPathIsDirectory {
14-
if try UserChoice.getBool(message: Color.yellow.rawValue + "There is no directory at path: \(projectPath), would you like to create it?" + Color.reset.rawValue) {
14+
if try UserChoice.getBool(message: Color.yellow + "There is no directory at path: \(projectPath), would you like to create it?") {
1515
try fileManager.createDirectory(atPath: projectPath, withIntermediateDirectories: true)
1616
} else {
1717
print("Goodbye")
@@ -24,8 +24,7 @@ private struct CreateProject {
2424
}
2525

2626
let projectName: String = try UserChoice.get(message: "Please enter the name of the project: ")
27-
28-
let contents = try fileManager.contentsOfDirectory(atPath: projectPath)
27+
let contents = try fileManager.contentsOfDirectory(atPath: fileManager.currentDirectoryPath)
2928
guard contents.isEmpty else {
3029
print(color: .red, "Directory at \(projectPath) must be empty, but found: \(contents.joined(separator: ", "))")
3130
exit(1)
@@ -43,8 +42,8 @@ private struct CreateProject {
4342
}
4443

4544
let godotPath: String = switch ProcessInfo.processInfo.environment["GODOT"] {
46-
case .some(let value): value
47-
case .none: try UserChoice.get(message: "Please enter the full path to the Godot 4.2 executable: ")
45+
case .some(let value) where value.isEmpty == false: value
46+
default: try UserChoice.get(message: Color.yellow + "GODOT not set\n" + "Please enter the full path to the Godot 4.2 executable: ")
4847
}
4948

5049
print(color: .green, "Created \(try FileFactory.createPackageFile(projectName: projectName))")
@@ -80,5 +79,5 @@ private struct CreateProject {
8079
}
8180

8281
func print(color: Color, _ message: String) {
83-
print(color.rawValue + message + Color.reset.rawValue)
82+
print(color + message)
8483
}

0 commit comments

Comments
 (0)