2424// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2525// SOFTWARE.
2626
27- import Foundation
27+ import Consler
2828import Files
29+ import Foundation
2930
3031struct CPInteractor {
3132
@@ -53,7 +54,7 @@ struct CPInteractor {
5354 return ( cpFile, cpModel, headFile)
5455 } catch {
5556 cpDebugPrint ( error)
56- throw CPError . fileReadWriteError
57+ throw CPError . cpFileIOError
5758 }
5859 }
5960
@@ -64,24 +65,24 @@ struct CPInteractor {
6465 try commitPrefixFile. write ( modelData)
6566 } catch {
6667 cpDebugPrint ( error)
67- throw CPError . fileReadWriteError
68+ throw CPError . cpFileIOError
6869 }
6970 }
7071
7172 private func branchPrefixes( ) throws -> [ String ] {
7273 guard let regexValue = commitPrefixModel. regexValue else {
73- throw CPTermination . branchValidatorNotPresent
74+ throw CPError . branchValidatorNotFound
7475 }
7576
7677 guard let branch = try ? gitHEADFile. readAsString ( encodedAs: . utf8) else {
77- throw CPTermination . unableToReadHEAD
78+ throw CPError . headFileIOError
7879 }
7980
8081 let matches = branch. occurances ( ofRegex: regexValue)
8182
8283 guard matches. count > 0 else {
8384 let validator = commitPrefixModel. branchValidator ?? " Validator Not Present "
84- throw CPTermination . invalidBranchPrefix ( validator: validator)
85+ throw CPError . invalidBranchPrefix ( validator: validator)
8586 }
8687
8788 let uniqueMatches = Set ( matches)
@@ -101,20 +102,20 @@ struct CPInteractor {
101102 let containsNoNumbers = validator. occurances ( ofRegex: #"(\d+)"# ) . isEmpty
102103 let atLeastTwoCharacters = validator. count > 1
103104 guard containsNoNumbers && atLeastTwoCharacters else {
104- throw CPError . branchValidatorFormatError
105+ throw CPError . invalidBranchValidatorFormat
105106 }
106107 return validator
107108 }
108109
109- func outputPrefixes( ) throws -> String {
110+ func outputPrefixes( ) throws -> ConslerOutput {
110111 switch commitPrefixModel. prefixMode {
111112 case . normal:
112- return commitPrefixModel. prefixes. joined ( )
113+ return ConslerOutput ( commitPrefixModel. prefixes. joined ( ) )
113114 case . branchParse:
114115 let retrievedBranchPrefixes = try branchPrefixes ( )
115116 let branchPrefixes = retrievedBranchPrefixes. map { " [ \( $0) ] " } . joined ( )
116117 let normalPrefixes = commitPrefixModel. prefixes. joined ( )
117- return branchPrefixes + normalPrefixes
118+ return ConslerOutput ( branchPrefixes, normalPrefixes)
118119 }
119120 }
120121
@@ -138,34 +139,37 @@ struct CPInteractor {
138139 }
139140 }
140141
141- func deletePrefixes( ) throws -> String {
142+ func deletePrefixes( ) throws -> ConslerOutput {
142143 let newModel = commitPrefixModel. updated ( with: [ ] )
143144 try saveCommitPrefix ( model: newModel)
144- return " CommitPrefix DELETED "
145+ return ConslerOutput ( " CommitPrefix " , " DELETED " ) . describedBy ( . normal , . red )
145146 }
146147
147- func writeNew( prefixes rawValue: String ) throws -> String {
148+ func writeNew( prefixes rawValue: String ) throws -> ConslerOutput {
148149 let newPrefixes = prefixFormatter ( rawValue)
149150 let newModel = commitPrefixModel. updated ( with: newPrefixes)
150151 try saveCommitPrefix ( model: newModel)
151- return " CommitPrefix STORED \( newPrefixes. joined ( ) ) "
152+ return ConslerOutput ( " CommitPrefix " , " STORED " , newPrefixes. joined ( ) )
153+ . describedBy ( . normal, . green, . green)
152154 }
153155
154- func activateBranchMode( with validator: String ) throws -> String {
156+ func activateBranchMode( with validator: String ) throws -> ConslerOutput {
155157 let formattedValidator = try validatorFormatter ( validator)
156158 let newModel = commitPrefixModel. updatedAsBranchMode ( with: formattedValidator)
157159 try saveCommitPrefix ( model: newModel)
158- return " CommitPrefix MODE BRANCH_PARSE \( formattedValidator) "
160+ return ConslerOutput ( " CommitPrefix " , " MODE BRANCH_PARSE " , formattedValidator)
161+ . describedBy ( . normal, . cyan, . green)
159162 }
160163
161- func activateNormalMode( ) throws -> String {
164+ func activateNormalMode( ) throws -> ConslerOutput {
162165 switch commitPrefixModel. prefixMode {
163166 case . normal:
164- return " CommitPrefix already in MODE NORMAL "
167+ return ConslerOutput ( " CommitPrefix " , " already in " , " MODE NORMAL " )
168+ . describedBy ( . normal, . yellow, . cyan)
165169 case . branchParse:
166170 let newModel = commitPrefixModel. updatedAsNormalMode ( )
167171 try saveCommitPrefix ( model: newModel)
168- return " CommitPrefix MODE NORMAL "
172+ return ConslerOutput ( " CommitPrefix " , " MODE NORMAL " ) . describedBy ( . normal , . cyan )
169173 }
170174 }
171175
0 commit comments