-
Notifications
You must be signed in to change notification settings - Fork 18
/
usage.go
79 lines (67 loc) · 1.97 KB
/
usage.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
72
73
74
75
76
77
78
79
package routingslip
import (
"fmt"
"strings"
"github.com/open-component-model/ocm/pkg/cobrautils/flagsets"
"github.com/open-component-model/ocm/pkg/runtime"
"github.com/open-component-model/ocm/pkg/utils"
)
func EntryUsage(scheme EntryTypeScheme, cli bool) string {
s := `
The following list describes the well-known entry types explicitly supported
by this version of the CLI, their versions and specification formats. Other
kinds of entries can be configured using the <code>--entry</code> option.
`
type method struct {
desc string
versions map[string]string
options flagsets.ConfigOptionTypeSetHandler
}
descs := map[string]*method{}
// gather info for kinds and versions
for _, n := range scheme.KnownTypeNames() {
kind, vers := runtime.KindVersion(n)
info := descs[kind]
if info == nil {
info = &method{versions: map[string]string{}}
descs[kind] = info
}
if vers == "" {
vers = "v1"
}
if _, ok := info.versions[vers]; !ok {
info.versions[vers] = ""
}
t := scheme.GetType(n)
if t.ConfigOptionTypeSetHandler() != nil {
info.options = t.ConfigOptionTypeSetHandler()
}
desc := t.Description()
if desc != "" {
info.desc = desc
}
desc = t.Format()
if desc != "" {
info.versions[vers] = desc
}
}
for _, t := range utils.StringMapKeys(descs) {
info := descs[t]
desc := strings.Trim(info.desc, "\n")
if desc != "" {
s = fmt.Sprintf("%s\n- Entry type <code>%s</code>\n\n%s\n\n", s, t, utils.IndentLines(desc, " "))
format := ""
for _, f := range utils.StringMapKeys(info.versions) {
desc = strings.Trim(info.versions[f], "\n")
if desc != "" {
format = fmt.Sprintf("%s\n- Version <code>%s</code>\n\n%s\n", format, f, utils.IndentLines(desc, " "))
}
}
if format != "" {
s += fmt.Sprintf(" The following versions are supported:\n%s\n", strings.Trim(utils.IndentLines(format, " "), "\n"))
}
}
s += utils.IndentLines(flagsets.FormatConfigOptions(info.options), " ")
}
return s
}