Created
December 8, 2016 00:01
-
-
Save lukesutton/da97e657f1e6781f77efb05c29da4940 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct StatusSummary { | |
let items: [Item] | |
enum Staging { | |
case staged | |
case unstaged | |
case unknown | |
} | |
enum Status { | |
case modified | |
case untracked | |
case deleted | |
case renamed | |
case unknown | |
} | |
struct Item { | |
let staging: Staging | |
let status: Status | |
let filename: String | |
} | |
} | |
func parse(item: String) -> StatusSummary.Item { | |
let chars = item.characters | |
let status = String(chars.prefix(3)) | |
let file = String(chars.suffix(chars.count - 3)) | |
switch(status) { | |
case " M ": | |
return StatusSummary.Item( | |
staging: .unstaged, | |
status: .modified, | |
filename: file | |
) | |
case "M ": | |
return StatusSummary.Item( | |
staging: .staged, | |
status: .modified, | |
filename: file | |
) | |
default: | |
return StatusSummary.Item( | |
staging: .unknown, | |
status: .unknown, | |
filename: file | |
) | |
} | |
} | |
print(parse(item: " M derp/what-even.rb")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment