Files
cunicu/pkg/config/types.go
Steffen Vogel 3bee839348 fix: Update copyright years
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
2025-01-01 22:45:39 +01:00

54 lines
1.0 KiB
Go

// SPDX-FileCopyrightText: 2023-2025 Steffen Vogel <post@steffenvogel.de>
// SPDX-License-Identifier: Apache-2.0
package config
import (
"errors"
"fmt"
)
type OutputFormat string //nolint:recvcheck
const (
OutputFormatJSON OutputFormat = "json"
OutputFormatLogger OutputFormat = "logger"
OutputFormatHuman OutputFormat = "human"
)
//nolint:gochecknoglobals
var OutputFormats = []OutputFormat{
OutputFormatJSON,
OutputFormatLogger,
OutputFormatHuman,
}
var errUnknownFormat = errors.New("unknown output format")
func (f *OutputFormat) UnmarshalText(text []byte) error {
*f = OutputFormat(text)
switch *f {
case OutputFormatJSON, OutputFormatLogger, OutputFormatHuman:
return nil
}
return fmt.Errorf("%w: %s", errUnknownFormat, string(text))
}
func (f OutputFormat) MarshalText() ([]byte, error) {
return []byte(f), nil
}
func (f OutputFormat) String() string {
return string(f)
}
func (f *OutputFormat) Set(str string) error {
return f.UnmarshalText([]byte(str))
}
func (f *OutputFormat) Type() string {
return "string"
}