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"}}
|
{{.Name}} {{$srv.SCPD.GoKindNameForVariable .RelatedStateVariable "string"}}
|
||||||
{{end}}{{end}}}
|
{{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}}
|
func (client *{{$srvIdent}}) {{.Name}}({{range .Arguments}}{{if .IsInput}}
|
||||||
{{.Name}} {{$srv.SCPD.GoKindNameForVariable .RelatedStateVariable "string"}},
|
{{.Name}} {{$srv.SCPD.GoKindNameForVariable .RelatedStateVariable "string"}},
|
||||||
{{end}}{{end}}) ({{range .Arguments}}{{if .IsOutput}}
|
{{end}}{{end}}) ({{range .Arguments}}{{if .IsOutput}}
|
||||||
|
53
scpd/scpd.go
53
scpd/scpd.go
@ -62,22 +62,29 @@ var dataTypeToGoKindName = map[string]string{
|
|||||||
// "uuid"
|
// "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
|
// Returns the name of the Go "kind" of type for the named state variable. If
|
||||||
// the state variable is unknown, returns default_.
|
// the state variable is unknown, returns default_.
|
||||||
func (scpd *SCPD) GoKindNameForVariable(variable string, default_ string) string {
|
func (scpd *SCPD) GoKindNameForVariable(variable string, default_ string) string {
|
||||||
for i := range scpd.StateVariables {
|
v := scpd.GetStateVariable(variable)
|
||||||
v := &scpd.StateVariables[i]
|
if v == nil {
|
||||||
if v.Name != variable {
|
return default_
|
||||||
continue
|
}
|
||||||
}
|
|
||||||
|
if kindName, ok := dataTypeToGoKindName[v.DataType.Name]; ok {
|
||||||
if kindName, ok := dataTypeToGoKindName[v.DataType.Name]; ok {
|
return kindName
|
||||||
return kindName
|
} else {
|
||||||
} else {
|
return default_
|
||||||
return default_
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return default_
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SpecVersion is part of a SCPD document, describes the version of the
|
// SpecVersion is part of a SCPD document, describes the version of the
|
||||||
@ -122,13 +129,13 @@ func (arg *Argument) IsOutput() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type StateVariable struct {
|
type StateVariable struct {
|
||||||
Name string `xml:"name"`
|
Name string `xml:"name"`
|
||||||
SendEvents string `xml:"sendEvents,attr"` // yes|no
|
SendEvents string `xml:"sendEvents,attr"` // yes|no
|
||||||
Multicast string `xml:"multicast,attr"` // yes|no
|
Multicast string `xml:"multicast,attr"` // yes|no
|
||||||
DataType DataType `xml:"dataType"`
|
DataType DataType `xml:"dataType"`
|
||||||
DefaultValue string `xml:"defaultValue"`
|
DefaultValue string `xml:"defaultValue"`
|
||||||
AllowedValueRange AllowedValueRange `xml:"allowedValueRange"`
|
AllowedValueRange *AllowedValueRange `xml:"allowedValueRange"`
|
||||||
AllowedValue []string `xml:"allowedValueList>allowedValue"`
|
AllowedValues []string `xml:"allowedValueList>allowedValue"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *StateVariable) clean() {
|
func (v *StateVariable) clean() {
|
||||||
@ -137,9 +144,11 @@ func (v *StateVariable) clean() {
|
|||||||
cleanWhitespace(&v.Multicast)
|
cleanWhitespace(&v.Multicast)
|
||||||
v.DataType.clean()
|
v.DataType.clean()
|
||||||
cleanWhitespace(&v.DefaultValue)
|
cleanWhitespace(&v.DefaultValue)
|
||||||
v.AllowedValueRange.clean()
|
if v.AllowedValueRange != nil {
|
||||||
for i := range v.AllowedValue {
|
v.AllowedValueRange.clean()
|
||||||
cleanWhitespace(&v.AllowedValue[i])
|
}
|
||||||
|
for i := range v.AllowedValues {
|
||||||
|
cleanWhitespace(&v.AllowedValues[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user