Skip to content

Commit

Permalink
Improve Error Reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
toshi0383 committed May 1, 2017
1 parent 2c74aed commit c40ad1b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
30 changes: 30 additions & 0 deletions Sources/xcconfig-extractor/ErrorReporter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// ErrorReporter.swift
// xcconfig-extractor
//
// Created by Toshihiro Suzuki on 2017/04/30.
// Copyright © 2017 Toshihiro Suzuki. All rights reserved.
//

import Foundation

func printStdError(_ message: String) {
fputs("\(ANSI.red)\(message)\(ANSI.reset)", stderr)
}

private enum ANSI : String, CustomStringConvertible {
case red = "\u{001B}[0;31m"
case green = "\u{001B}[0;32m"
case yellow = "\u{001B}[0;33m"

case bold = "\u{001B}[0;1m"
case reset = "\u{001B}[0;0m"

var description:String {
if isatty(STDOUT_FILENO) > 0 {
return rawValue
}
return ""
}
}

16 changes: 0 additions & 16 deletions Sources/xcconfig-extractor/XCConfigExtractorError.swift

This file was deleted.

17 changes: 9 additions & 8 deletions Sources/xcconfig-extractor/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ let main = command(

let pbxprojPath = xcodeprojPath + Path("project.pbxproj")
guard pbxprojPath.isFile else {
print("pbxproj not exist!: \(pbxprojPath.string)")
printStdError("pbxproj not exist!: \(pbxprojPath.string)")
exit(1)
}
let projRoot = xcodeprojPath + ".."
// validate DIR
guard dirPath.absolute().components.starts(with: projRoot.absolute().components) else {
print("Invalid DIR parameter: \(dirPath.string)\nIt must be descendant of xcodeproj's root dir: \(projRoot.string)")
printStdError("Invalid DIR parameter: \(dirPath.string)\nIt must be descendant of xcodeproj's root dir: \(projRoot.string)")
exit(1)
}

if dirPath.exists == false {
if dirPath.isFile {
print("file already exists: \(dirPath.string)")
exit(1)
}
if dirPath.isFile {
printStdError("file already exists: \(dirPath.string)")
exit(1)
}
if dirPath.isDirectory == false {
try! dirPath.mkpath()
}

Expand All @@ -54,7 +54,8 @@ let main = command(
//
let data: Data = try pbxprojPath.read()
guard let pbxproj = Pbxproj(data: data) else {
fatalError("Failed to parse Pbxproj")
printStdError("Failed to parse Pbxproj")
exit(1)
}

//
Expand Down

0 comments on commit c40ad1b

Please sign in to comment.