Reorder items in generated source files.

Ideally they would always have been sorted as such, but this seems more
critical in migrating from one service definition to another where the ordering might
change.
This commit is contained in:
John Beisley committed 2022-03-13 09:02:29 +00:00
1 parent 730ab6506b
commit ca81a64b42
8 files changed
+11755 -11715

No files matched your search

+4 -4
View File
@@ -29,16 +29,16 @@ import (
var _ time.Time
// Device URNs:
const ({{range .DeviceTypes}}
const ({{range .OrderedDeviceTypes}}
{{.Const}} = "{{.URN}}"{{end}}
)
// Service URNs:
const ({{range .ServiceTypes}}
const ({{range .OrderedServiceTypes}}
{{.Const}} = "{{.URN}}"{{end}}
)
{{range .Services}}
{{range .OrderedServices}}
{{$srv := .}}
{{$srvIdent := printf "%s%s" .Name .Version}}
@@ -102,7 +102,7 @@ func new{{$srvIdent}}ClientsFromGenericClients(genericClients []goupnp.ServiceCl
return clients
}
{{range .SCPD.Actions}}{{/* loops over *SCPDWithURN values */}}
{{range .SCPD.OrderedActions}}{{/* loops over *SCPDWithURN values */}}
{{$winargs := $srv.WrapArguments .InputArguments}}
{{$woutargs := $srv.WrapArguments .OutputArguments}}
+29
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"sort"
"strings"
"github.com/huin/goupnp"
@@ -85,6 +86,7 @@ func (dcp *DCP) writeCode(outFile string, useGofmt bool) error {
return err
}
}
if err = packageTmpl.Execute(output, dcp); err != nil {
output.Close()
return err
@@ -92,6 +94,33 @@ func (dcp *DCP) writeCode(outFile string, useGofmt bool) error {
return output.Close()
}
func (dcp *DCP) OrderedServices() []SCPDWithURN {
services := append([]SCPDWithURN{}, dcp.Services...)
sort.SliceStable(services, func(i, j int) bool {
return services[i].URNParts.URN < services[j].URNParts.URN
})
return services
}
func orderedURNParts(urnMap map[string]*URNParts) []*URNParts {
urns := make([]*URNParts, 0, len(urnMap))
for _, urn := range urnMap {
urns = append(urns, urn)
}
sort.SliceStable(urns, func(i, j int) bool {
return urns[i].URN < urns[j].URN
})
return urns
}
func (dcp *DCP) OrderedDeviceTypes() []*URNParts {
return orderedURNParts(dcp.DeviceTypes)
}
func (dcp *DCP) OrderedServiceTypes() []*URNParts {
return orderedURNParts(dcp.ServiceTypes)
}
func (dcp *DCP) processSCPDFile(file *zip.File) error {
scpd := new(scpd.SCPD)
if err := unmarshalXmlFile(file, scpd); err != nil {