From e901381e7d2ca9ceefd26c42d0e760d8ffc57fb2 Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Tue, 16 Nov 2021 20:16:07 +0100 Subject: add urgency --- branding/motd-cli/README.md | 5 ++++- branding/motd-cli/main.go | 18 ++++++++++++++++-- branding/motd-cli/motd-example.json | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/branding/motd-cli/README.md b/branding/motd-cli/README.md index cfe8a38..926a982 100644 --- a/branding/motd-cli/README.md +++ b/branding/motd-cli/README.md @@ -19,6 +19,7 @@ The structure of the `motd.json` file is like follows: "end": "Dec 31 2021 23:59:00", "type": "daily", "platform": "all", + "urgency": "normal", "text": [ { "lang": "en", "str": "This is a test!"}, @@ -33,7 +34,8 @@ Valid values are: * Begin, End are date strings, like "Jan 1 2021 00:00:00". * Type: "once" for a one-shot message, "daily" for a message that is displayed daily during the specified duration. -* Platform: one of "windows", "linux", "osx" or "all". +* Platform: one of "windows", "osx", "snap", "linux", or "all". +* Urgency: either "normal" or "critical". The text message can contain links. @@ -48,6 +50,7 @@ Message 1 ✓ ----------- Type: daily ✓ Platform: all ✓ +Urgency: normal ✓ Languages: 2 ✓ ``` diff --git a/branding/motd-cli/main.go b/branding/motd-cli/main.go index 6cfd29e..1c9191c 100644 --- a/branding/motd-cli/main.go +++ b/branding/motd-cli/main.go @@ -28,20 +28,24 @@ type Message struct { End string `json:"end"` Type string `json:"type"` Platform string `json:"platform"` + Urgency string `json:"urgency"` Text []LocalizedText `json:"text"` } func (m *Message) IsValid() bool { valid := (m.IsValidBegin() && m.IsValidEnd() && - m.IsValidType() && m.IsValidPlatform() && m.HasLocalizedText()) + m.IsValidType() && m.IsValidPlatform() && m.IsValidUrgency() && + m.HasLocalizedText()) return valid } func (m *Message) IsValidBegin() bool { + // FIXME check that begin is before 1y for instance return true } func (m *Message) IsValidEnd() bool { + // FIXME check end is within next year/months return true } @@ -63,8 +67,17 @@ func (m *Message) IsValidPlatform() bool { } } +func (m *Message) IsValidUrgency() bool { + switch m.Urgency { + case "normal", "critical": + return true + default: + return false + } +} + func (m *Message) HasLocalizedText() bool { - return true + return len(m.Text) > 0 } type LocalizedText struct { @@ -89,6 +102,7 @@ func main() { fmt.Printf("Message %d %v\n-----------\n", i+1, mark(msg.IsValid())) fmt.Printf("Type: %s %v\n", msg.Type, mark(msg.IsValidType())) fmt.Printf("Platform: %s %v\n", msg.Platform, mark(msg.IsValidPlatform())) + fmt.Printf("Urgency: %s %v\n", msg.Urgency, mark(msg.IsValidUrgency())) fmt.Printf("Languages: %d %v\n", len(msg.Text), mark(msg.HasLocalizedText())) if !msg.IsValid() { os.Exit(1) diff --git a/branding/motd-cli/motd-example.json b/branding/motd-cli/motd-example.json index 47bf635..9ebb5f5 100644 --- a/branding/motd-cli/motd-example.json +++ b/branding/motd-cli/motd-example.json @@ -4,6 +4,7 @@ "end": "Dec 31 2021 23:59:00", "type": "daily", "platform": "all", + "urgency": "normal", "text": [ { "lang": "en", "str": "This is a test!"}, -- cgit v1.2.3