Skip to content

Commit 341d049

Browse files
authored
Merge pull request open-telemetry#69 from jjackson-s/feature
User formatting assistance and user error checking
2 parents 6db3df4 + ef2587f commit 341d049

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

cmd/configschema/configwiz/configwiz/component.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func handleComponent(
5151
typeMap := map[string]interface{}{}
5252
m[componentGroup+"s"] = typeMap
5353
for _, name := range names {
54-
cfgInfo, err := configschema.GetCfgInfo(factories, componentGroup, name)
54+
cfgInfo, err := configschema.GetCfgInfo(factories, componentGroup, strings.Split(name, "/")[0])
5555
if err != nil {
5656
panic(err)
5757
}
@@ -87,7 +87,11 @@ func handleField(p indentingPrinter, field *configschema.Field, out map[string]i
8787
p.println("Field: " + field.Name)
8888
typ := resolveType(field)
8989
if typ != "" {
90-
p.println("Type: " + typ)
90+
typString := "Type: " + typ
91+
if typ == "time.Duration" {
92+
typString += " (examples: 1h2m3s, 5m10s, 45s)"
93+
}
94+
p.println(typString)
9195
}
9296
if field.Doc != "" {
9397
p.println("Docs: " + strings.ReplaceAll(field.Doc, "\n", " "))
@@ -100,7 +104,6 @@ func handleField(p indentingPrinter, field *configschema.Field, out map[string]i
100104
if field.Default != nil {
101105
defaultVal = fmt.Sprintf("%v", field.Default)
102106
}
103-
104107
in := readline(defaultVal)
105108
if in == "" {
106109
return

cmd/configschema/configwiz/configwiz/pipelines.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
"go.opentelemetry.io/collector/component/componenterror"
2626
)
2727

28+
const invalidMsg = "Invalid input. Try again."
29+
2830
func pipelinesWizard(factories component.Factories) map[string]interface{} {
2931
out := map[string]interface{}{}
3032
for {
@@ -55,12 +57,15 @@ func singlePipelineWizard(factories component.Factories) (string, rpe) {
5557
fmt.Print("> ")
5658
pipelineID := readline("")
5759
switch pipelineID {
60+
case "":
61+
return "", rpe{}
5862
case "1":
5963
return pipelineTypeWizard("metrics", receiverNames(factories, isMetricsReceiver), exporterNames(factories, isMetricsExporter))
6064
case "2":
6165
return pipelineTypeWizard("traces", receiverNames(factories, isTracesReceiver), exporterNames(factories, isTracesExporter))
6266
}
63-
return "", rpe{}
67+
fmt.Println(invalidMsg)
68+
return singlePipelineWizard(factories)
6469
}
6570

6671
// pipelineTypeWizard for a given pipelineType (e.g. "metrics", "traces")
@@ -120,6 +125,10 @@ func componentNameWizard(pr indentingPrinter, componentType string, componentNam
120125
return "", ""
121126
}
122127
i, _ := strconv.Atoi(choice)
128+
if i < 0 || i > len(componentNames)-1 {
129+
fmt.Println(invalidMsg)
130+
return componentNameWizard(pr, componentType, componentNames)
131+
}
123132
key := componentNames[i]
124133
pr.print(fmt.Sprintf("%s %s extended name (optional) > ", key, componentType))
125134
return key, readline("")

0 commit comments

Comments
 (0)