Created
December 8, 2016 00:01
Revisions
-
lukesutton created this gist
Dec 8, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ 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"))