mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-03-03 15:02:35 +02:00
docs: show possible values in step documentation (#1453)
* add possibleValues to model * include possible values into docs
This commit is contained in:
parent
2100632b54
commit
96439972e2
@ -52,6 +52,7 @@ type StepParameters struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Mandatory bool `json:"mandatory,omitempty"`
|
Mandatory bool `json:"mandatory,omitempty"`
|
||||||
Default interface{} `json:"default,omitempty"`
|
Default interface{} `json:"default,omitempty"`
|
||||||
|
PossibleValues []interface{} `json:"possibleValues,omitempty"`
|
||||||
Aliases []Alias `json:"aliases,omitempty"`
|
Aliases []Alias `json:"aliases,omitempty"`
|
||||||
Conditions []Condition `json:"conditions,omitempty"`
|
Conditions []Condition `json:"conditions,omitempty"`
|
||||||
Secret bool `json:"secret,omitempty"`
|
Secret bool `json:"secret,omitempty"`
|
||||||
|
@ -147,7 +147,7 @@ func createParametersTable(parameters []config.StepParameters) string {
|
|||||||
|
|
||||||
for _, param := range parameters {
|
for _, param := range parameters {
|
||||||
if v, ok := m[param.Name]; ok {
|
if v, ok := m[param.Name]; ok {
|
||||||
table += fmt.Sprintf(" | %v | %v | %v | |\n ", param.Name, ifThenElse(param.Mandatory && param.Default == nil, "Yes", "No"), ifThenElse(v == "<nil>", "", v))
|
table += fmt.Sprintf(" | %v | %v | %v | %v |\n ", param.Name, ifThenElse(param.Mandatory && param.Default == nil, "Yes", "No"), ifThenElse(v == "<nil>", "", v), possibleValuesToString(param.PossibleValues))
|
||||||
delete(m, param.Name)
|
delete(m, param.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -468,3 +468,17 @@ func sortStepParameters(stepData *config.StepData) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func possibleValuesToString(in []interface{}) (out string) {
|
||||||
|
if len(in) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
out = fmt.Sprintf("`%v`", in[0])
|
||||||
|
if len(in) == 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, value := range in[1:] {
|
||||||
|
out += fmt.Sprintf(", `%v`", value)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -400,3 +400,41 @@ func TestAddExistingParameterWithCondition(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRenderPossibleValues(t *testing.T) {
|
||||||
|
t.Run("none", func(t *testing.T) {
|
||||||
|
// init
|
||||||
|
var in []interface{}
|
||||||
|
// test
|
||||||
|
out := possibleValuesToString(in)
|
||||||
|
// assert
|
||||||
|
assert.Empty(t, out)
|
||||||
|
})
|
||||||
|
t.Run("one", func(t *testing.T) {
|
||||||
|
// init
|
||||||
|
var in []interface{}
|
||||||
|
in = append(in, "fu")
|
||||||
|
// test
|
||||||
|
out := possibleValuesToString(in)
|
||||||
|
// assert
|
||||||
|
assert.Equal(t, "`fu`", out)
|
||||||
|
})
|
||||||
|
t.Run("many", func(t *testing.T) {
|
||||||
|
// init
|
||||||
|
var in []interface{}
|
||||||
|
in = append(in, "fu", "fara")
|
||||||
|
// test
|
||||||
|
out := possibleValuesToString(in)
|
||||||
|
// assert
|
||||||
|
assert.Equal(t, "`fu`, `fara`", out)
|
||||||
|
})
|
||||||
|
t.Run("boolean", func(t *testing.T) {
|
||||||
|
// init
|
||||||
|
var in []interface{}
|
||||||
|
in = append(in, false, true)
|
||||||
|
// test
|
||||||
|
out := possibleValuesToString(in)
|
||||||
|
// assert
|
||||||
|
assert.Equal(t, "`false`, `true`", out)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user