From 877f3bc21ef6bb1ae636caaad8f62733f6de2f72 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 9 Sep 2018 20:13:46 +0200 Subject: status: add a function to parse a status --- bug/status.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'bug') diff --git a/bug/status.go b/bug/status.go index 0eee6cf1..f15924e2 100644 --- a/bug/status.go +++ b/bug/status.go @@ -1,5 +1,10 @@ package bug +import ( + "fmt" + "strings" +) + type Status int const ( @@ -29,3 +34,16 @@ func (s Status) Action() string { return "unknown status" } } + +func StatusFromString(str string) (Status, error) { + cleaned := strings.ToLower(strings.TrimSpace(str)) + + switch cleaned { + case "open": + return OpenStatus, nil + case "closed": + return ClosedStatus, nil + default: + return 0, fmt.Errorf("unknow status") + } +} -- cgit