/
textEntry.go
71 lines (56 loc) · 1.34 KB
/
textEntry.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package param
import (
"fmt"
"strings"
"github.com/Blesmol/pfscf/pfscf/args"
"github.com/Blesmol/pfscf/pfscf/utils"
)
const (
typeText = "text"
)
type textEntry struct {
commonFields
TheExample string `yaml:"example"`
TheDescription string `yaml:"description"`
}
func (e *textEntry) Type() string {
return typeText
}
func (e *textEntry) Example() string {
return e.TheExample
}
func (e *textEntry) Description() string {
return e.TheDescription
}
func (e *textEntry) AcceptedValues() []string {
return []string{"Any text"}
}
func (e *textEntry) deepCopy() Entry {
copy := *e
return ©
}
func (e *textEntry) isValid() (err error) {
if !utils.IsSet(e.TheExample) {
return fmt.Errorf("Missing example")
}
if !utils.IsSet(e.TheDescription) {
return fmt.Errorf("Missing description")
}
return nil
}
func (e *textEntry) validateAndProcessArgs(*args.Store) error {
// text entries have not much to validate...
return nil
}
func (e *textEntry) describe(verbose bool) (result string) {
var sb strings.Builder
if !verbose {
fmt.Fprintf(&sb, "- %v: %v\n", e.id, e.Description())
} else {
fmt.Fprintf(&sb, "- %v\n", e.id)
fmt.Fprintf(&sb, "\tDesc: %v\n", e.Description())
fmt.Fprintf(&sb, "\tType: %v\n", e.Type())
fmt.Fprintf(&sb, "\tExample: %v\n", genericContentUsageExample(e.id, e.Example()))
}
return sb.String()
}