       print("Wrong Value\n")
       continue
     }
-
+    
     switch num {
     case 0:
-      if isRootUserWithSudoCommand(selectNumber: 0) {
-        print("CustomTemplate must be executed without sudo command")
-        return
-      }
-      break
+      guard !isRootUserWithSudoCommand() else {
+        terminateWithAlert(needSudo: false)
+        return
+      }
     case 1:
-      if isRootUserWithSudoCommand(selectNumber: 1) {
-        print("CustomTemplate must be executed without sudo command")
-        return
-      }
-      pathEndPoint = "/Library/Developer/Xcode/Templates/Project Templates/Custom"
-      directoryPath = customTemplatePath
+      guard !isRootUserWithSudoCommand() else {
+        terminateWithAlert(needSudo: false)
+        return
+      }
+      directoryPath = userHomeDirectory
+      pathEndPoint = PathEndPoint.customProjectTemplate.rawValue
     case 2:
-      if !isRootUserWithSudoCommand(selectNumber: 2) {
-        print("XcodeTemplatePath need to be executed with sudo command")
-        return
-      }
-      pathEndPoint = "/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Source"
-      directoryPath = XcodeTemplatePath
+      guard isRootUserWithSudoCommand() else {
+        terminateWithAlert(needSudo: true)
+        return
+      }
+      directoryPath = xcodeBasePath
+      pathEndPoint = PathEndPoint.xcodeFileTemplate.rawValue
     case 3:
-      if !isRootUserWithSudoCommand(selectNumber: 3) {
-        print("XcodeTemplatePath need to be executed with sudo command")
-        return
-      }
-      pathEndPoint = "/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/iOS/Application"
-      directoryPath = XcodeTemplatePath
+      guard isRootUserWithSudoCommand() else {
+        terminateWithAlert(needSudo: true)
+        return
+      }
+      directoryPath = xcodeBasePath
+      pathEndPoint = PathEndPoint.xcodeProjectTemplate.rawValue
     default:
       break
     }
-
+    
     directoryPath.append(pathEndPoint)
-
+    
     printInConsole("Template will be installed at \(directoryPath)")
     break
   }
-
-
+  
+  
   let filePath = directoryPath.appending("/\(templateName)")
-
+  
   do {
     let _ = bash(command: "mkdir", arguments: ["-p", directoryPath])
     

//  Copyright © 2017 giftbott. All rights reserved.
//

//=============
//MARK: Declare
//=============
import Foundation


let fileManager = FileManager.default

/// Select Template, only if more than one template
func setup() {
  let contentsFilter = try? fileManager
    .contentsOfDirectory(atPath: ".")
    .filter { $0.hasSuffix(".xctemplate") }
  
  guard let templates = contentsFilter, templates.count > 0 else {
    printInConsole("xctemplate directory does not exist")
    return
  }

  guard templates.count > 1 else {
      installTemplate(templates[0])
      return
  }
  
  /// Show xctemplates in current directory

  print("2: Xcode File Template (admin only)")
  print("3: Xcode Project Template (admin only)")
  print(String(repeating: "#", count:40), terminator: "\n\n")
  
  
  // Select Target
  let userHomeDirectory = "/Users/".appending(bash(command: "whoami", arguments: []))
  let xcodeBasePath = bash(command: "xcode-select", arguments: ["--print-path"])
  
  // Default Path (For Custom File Template)
  var directoryPath = userHomeDirectory
  var pathEndPoint = PathEndPoint.customFileTemplate.rawValue
  
  while true {
    print("Select Target Path Number : ", terminator: "")
    let input = readLine() ?? "0"
