Skip to content

Commit

Permalink
Split out error codes for not-installed vs. not-initialized.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Sneed committed Jan 31, 2017
1 parent 6c9592e commit 1b7d794
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
29 changes: 16 additions & 13 deletions ModuloKit/ErrorCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ import Foundation

public enum ErrorCode: Int {
case success = 0
case unknownError = 1
case commandError = 2
case specNotFound = 3
case specNotWritable = 4
case noSCMFoundOrInitialized = 5
case alreadyInitialized = 6
case notInitialized = 7
case noMatchingDependencies = 8
case dependencyAlreadyExists = 9
case dependencyUnclean = 10
case dependencyUnknown = 11
case unknownError
case commandError
case specNotFound
case specNotWritable
case scmNotFound
case scmNotInitialized
case alreadyInitialized
case notInitialized
case noMatchingDependencies
case dependencyAlreadyExists
case dependencyUnclean
case dependencyUnknown

var description: String {
var result: String = ""
Expand All @@ -40,8 +41,10 @@ public enum ErrorCode: Int {
result = ".modulo file not found."
case .specNotWritable:
result = ".modulo cannot be written to, check permissions."
case .noSCMFoundOrInitialized:
result = "No supported SCM was found to be initialized."
case .scmNotFound:
result = "No supported SCM was found."
case .scmNotInitialized:
result = "An SCM has not been initialized in this directory."
case .alreadyInitialized:
result = "Modulo has already been initialized."
case .notInitialized:
Expand Down
12 changes: 8 additions & 4 deletions ModuloKit/SCM/SCM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,20 @@ public func currentSCM() -> SCM {
let installed = scm.isInstalled
let initialized = scm.isInitialized

if !installed {
exit(.scmNotFound)
}

if !initialized {
exit(.scmNotInitialized)
}

if installed && initialized {
result = scm
break
}
}

if result == nil {
exit(.noSCMFoundOrInitialized)
}

return result!
}

0 comments on commit 1b7d794

Please sign in to comment.