Skip to content

Commit

Permalink
fix cd bug, and clean up some color stuff (#2)
Browse files Browse the repository at this point in the history
* clean up some color stuff

* Update Sources/CreateProject/CreateProject.swift
  • Loading branch information
EstevanBR authored Jul 26, 2024
1 parent 338e57d commit e6d2490
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
13 changes: 13 additions & 0 deletions Sources/CreateProject/Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,17 @@ enum Color: String {
case magenta = "\u{001B}[0;35m"
case cyan = "\u{001B}[0;36m"
case white = "\u{001B}[0;37m"

case bgBlack = "\u{001B}[0;40m"
case bgRed = "\u{001B}[0;41m"
case bgGreen = "\u{001B}[0;42m"
case bgYellow = "\u{001B}[0;43m"
case bgBlue = "\u{001B}[0;44m"
case bgMagenta = "\u{001B}[0;45m"
case bgCyan = "\u{001B}[0;46m"
case bgWhite = "\u{001B}[0;47m"

static func +(color: Color, text: String) -> String {
return color.rawValue + text + Color.reset.rawValue
}
}
11 changes: 5 additions & 6 deletions Sources/CreateProject/CreateProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ private struct CreateProject {
let (projectPathExists, projectPathIsDirectory) = fileManager.directoryExists(atPath: projectPath)

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

let projectName: String = try UserChoice.get(message: "Please enter the name of the project: ")

let contents = try fileManager.contentsOfDirectory(atPath: projectPath)
let contents = try fileManager.contentsOfDirectory(atPath: fileManager.currentDirectoryPath)
guard contents.isEmpty else {
print(color: .red, "Directory at \(projectPath) must be empty, but found: \(contents.joined(separator: ", "))")
exit(1)
Expand All @@ -43,8 +42,8 @@ private struct CreateProject {
}

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

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

func print(color: Color, _ message: String) {
print(color.rawValue + message + Color.reset.rawValue)
print(color + message)
}

0 comments on commit e6d2490

Please sign in to comment.