Attempt to add argument/return value documentation.
This commit is contained in:
parent
5ff1b1c840
commit
ea06094dea
@ -40,6 +40,28 @@ type {{$respType}} struct {{"{"}}{{range .Arguments}}{{if .IsOutput}}
|
||||
{{.Name}} {{$srv.SCPD.GoKindNameForVariable .RelatedStateVariable "string"}}
|
||||
{{end}}{{end}}}
|
||||
|
||||
// {{.Name}} action.
|
||||
// Arguments:
|
||||
//{{range .Arguments}}{{if .IsInput}}
|
||||
// * {{.Name}}: {{$v := $srv.SCPD.GetStateVariable .RelatedStateVariable}}
|
||||
{{if $v}}// (related state variable: {{$v.Name}})
|
||||
// - {{if $v.AllowedValueRange}}allowed range: {{$v.AllowedValueRange.Minimum}} to {{$v.AllowedValueRange.Maximum}}{{end}}
|
||||
// - {{if $v.AllowedValues}}allowed values:
|
||||
// {{range $i, $val := $v.AllowedValues}}{{if $i}}|{{end}}{{$val}}{{end}}{{end}}
|
||||
//{{else}}
|
||||
// (unknown){{end}}
|
||||
//{{end}}{{end}}
|
||||
//
|
||||
// Return values:
|
||||
//{{range .Arguments}}{{if .IsOutput}}
|
||||
// * {{.Name}}: {{$v := $srv.SCPD.GetStateVariable .RelatedStateVariable}}
|
||||
{{if $v}}// (related state variable: {{$v.Name}})
|
||||
// - {{if $v.AllowedValueRange}}allowed range: {{$v.AllowedValueRange.Minimum}} to {{$v.AllowedValueRange.Maximum}}{{end}}
|
||||
// - {{if $v.AllowedValues}}allowed values:
|
||||
// {{range $i, $val := $v.AllowedValues}}{{if $i}}|{{end}}{{$val}}{{end}}{{end}}
|
||||
//{{else}}
|
||||
// (unknown){{end}}
|
||||
//{{end}}{{end}}
|
||||
func (client *{{$srvIdent}}) {{.Name}}({{range .Arguments}}{{if .IsInput}}
|
||||
{{.Name}} {{$srv.SCPD.GoKindNameForVariable .RelatedStateVariable "string"}},
|
||||
{{end}}{{end}}) ({{range .Arguments}}{{if .IsOutput}}
|
||||
|
29
scpd/scpd.go
29
scpd/scpd.go
@ -62,13 +62,22 @@ var dataTypeToGoKindName = map[string]string{
|
||||
// "uuid"
|
||||
}
|
||||
|
||||
func (scpd *SCPD) GetStateVariable(variable string) *StateVariable {
|
||||
for i := range scpd.StateVariables {
|
||||
v := &scpd.StateVariables[i]
|
||||
if v.Name == variable {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Returns the name of the Go "kind" of type for the named state variable. If
|
||||
// the state variable is unknown, returns default_.
|
||||
func (scpd *SCPD) GoKindNameForVariable(variable string, default_ string) string {
|
||||
for i := range scpd.StateVariables {
|
||||
v := &scpd.StateVariables[i]
|
||||
if v.Name != variable {
|
||||
continue
|
||||
v := scpd.GetStateVariable(variable)
|
||||
if v == nil {
|
||||
return default_
|
||||
}
|
||||
|
||||
if kindName, ok := dataTypeToGoKindName[v.DataType.Name]; ok {
|
||||
@ -77,8 +86,6 @@ func (scpd *SCPD) GoKindNameForVariable(variable string, default_ string) string
|
||||
return default_
|
||||
}
|
||||
}
|
||||
return default_
|
||||
}
|
||||
|
||||
// SpecVersion is part of a SCPD document, describes the version of the
|
||||
// specification that the data adheres to.
|
||||
@ -127,8 +134,8 @@ type StateVariable struct {
|
||||
Multicast string `xml:"multicast,attr"` // yes|no
|
||||
DataType DataType `xml:"dataType"`
|
||||
DefaultValue string `xml:"defaultValue"`
|
||||
AllowedValueRange AllowedValueRange `xml:"allowedValueRange"`
|
||||
AllowedValue []string `xml:"allowedValueList>allowedValue"`
|
||||
AllowedValueRange *AllowedValueRange `xml:"allowedValueRange"`
|
||||
AllowedValues []string `xml:"allowedValueList>allowedValue"`
|
||||
}
|
||||
|
||||
func (v *StateVariable) clean() {
|
||||
@ -137,9 +144,11 @@ func (v *StateVariable) clean() {
|
||||
cleanWhitespace(&v.Multicast)
|
||||
v.DataType.clean()
|
||||
cleanWhitespace(&v.DefaultValue)
|
||||
if v.AllowedValueRange != nil {
|
||||
v.AllowedValueRange.clean()
|
||||
for i := range v.AllowedValue {
|
||||
cleanWhitespace(&v.AllowedValue[i])
|
||||
}
|
||||
for i := range v.AllowedValues {
|
||||
cleanWhitespace(&v.AllowedValues[i])
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user