Skip to content

Instantly share code, notes, and snippets.

@lukesutton
Created December 8, 2016 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukesutton/da97e657f1e6781f77efb05c29da4940 to your computer and use it in GitHub Desktop.
Save lukesutton/da97e657f1e6781f77efb05c29da4940 to your computer and use it in GitHub Desktop.
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