motivation.go

 1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
 2//
 3// SPDX-License-Identifier: AGPL-3.0-or-later
 4
 5package lunatask
 6
 7import (
 8	"errors"
 9	"fmt"
10	"strings"
11)
12
13// Errors returned by Motivation operations.
14var (
15	// ErrInvalidMotivation is returned when parsing an unknown motivation string.
16	ErrInvalidMotivation = errors.New("invalid motivation")
17)
18
19// ParseMotivation parses a string to a Motivation value (case-insensitive).
20// Valid values: "unknown", "must", "should", "want".
21func ParseMotivation(str string) (Motivation, error) {
22	switch strings.ToLower(str) {
23	case "unknown":
24		return MotivationUnknown, nil
25	case "must":
26		return MotivationMust, nil
27	case "should":
28		return MotivationShould, nil
29	case "want":
30		return MotivationWant, nil
31	default:
32		return "", fmt.Errorf("%w: %q", ErrInvalidMotivation, str)
33	}
34}