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}}
|
||||
|
53
scpd/scpd.go
53
scpd/scpd.go
@ -62,22 +62,29 @@ 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
|
||||
}
|
||||
|
||||
if kindName, ok := dataTypeToGoKindName[v.DataType.Name]; ok {
|
||||
return kindName
|
||||
} else {
|
||||
return default_
|
||||
}
|
||||
v := scpd.GetStateVariable(variable)
|
||||
if v == nil {
|
||||
return default_
|
||||
}
|
||||
|
||||
if kindName, ok := dataTypeToGoKindName[v.DataType.Name]; ok {
|
||||
return kindName
|
||||
} else {
|
||||
return default_
|
||||
}
|
||||
return default_
|
||||
}
|
||||
|
||||
// SpecVersion is part of a SCPD document, describes the version of the
|
||||
@ -122,13 +129,13 @@ func (arg *Argument) IsOutput() bool {
|
||||
}
|
||||
|
||||
type StateVariable struct {
|
||||
Name string `xml:"name"`
|
||||
SendEvents string `xml:"sendEvents,attr"` // yes|no
|
||||
Multicast string `xml:"multicast,attr"` // yes|no
|
||||
DataType DataType `xml:"dataType"`
|
||||
DefaultValue string `xml:"defaultValue"`
|
||||
AllowedValueRange AllowedValueRange `xml:"allowedValueRange"`
|
||||
AllowedValue []string `xml:"allowedValueList>allowedValue"`
|
||||
Name string `xml:"name"`
|
||||
SendEvents string `xml:"sendEvents,attr"` // yes|no
|
||||
Multicast string `xml:"multicast,attr"` // yes|no
|
||||
DataType DataType `xml:"dataType"`
|
||||
DefaultValue string `xml:"defaultValue"`
|
||||
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)
|
||||
v.AllowedValueRange.clean()
|
||||
for i := range v.AllowedValue {
|
||||
cleanWhitespace(&v.AllowedValue[i])
|
||||
if v.AllowedValueRange != nil {
|
||||
v.AllowedValueRange.clean()
|
||||
}
|
||||
for i := range v.AllowedValues {
|
||||
cleanWhitespace(&v.AllowedValues[i])
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user