aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/admin/vespa-wrapper/logfmt/formatflags.go
blob: 1869692b40b827c8c347d20d8064e191e85c7299 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package logfmt

import (
	"fmt"
	"strings"
)

type OutputFormat int

const (
	FormatVespa OutputFormat = iota //default is vespa
	FormatRaw
	FormatJSON
)

func (v *OutputFormat) Type() string {
	return "output format"
}

func (v *OutputFormat) String() string {
	flagNames := []string{
		"vespa",
		"raw",
		"json",
	}
	return flagNames[*v]
}

func (v *OutputFormat) Set(val string) error {
	switch strings.ToLower(val) {
	case "vespa":
		*v = FormatVespa
	case "raw":
		*v = FormatRaw
	case "json":
		*v = FormatJSON
	default:
		return fmt.Errorf("'%s' is not a valid format argument", val)
	}
	return nil
}