Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Compilation fails if Default*Pairs unimplemented in service #821

Merged
merged 5 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cmd/definitions/gen_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,18 @@ GetStorageSystemMetadata will get StorageSystemMetadata from Storage.
for _, feature := range ns.ParsedFeatures() {
featureNameP := templateutils.ToPascal(feature.Name)

gg.If(gg.S("result.hasEnable%s", featureNameP)).
group.
NewIf(gg.S("result.hasEnable%s", featureNameP)).
AddBody(
gg.S("result.Has%sFeatures = true", nsNameP),
gg.S("result.%sFeatures.%s = true", nsNameP, featureNameP),
)
}
return group
}),
gg.LineComment("Default pairs"),
gg.Embed(func() gg.Node {
// Generate default pari handle logic here.
// Generate default pair handle logic here.
group := gg.NewGroup()

for _, dp := range ns.ParsedDefaultable() {
Expand Down
35 changes: 29 additions & 6 deletions cmd/definitions/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func (d *Data) LoadService(filePath string) {
d.Service = &Service{
d: d,
}
d.Service.Pairs = make(map[string]*Pair)
err = parseTOML(bs, d.Service)
if err != nil {
log.Fatalf("parse service: %v", err)
Expand Down Expand Up @@ -307,14 +308,36 @@ func (d *Data) LoadService(filePath string) {
ns.New.srv = srv
ns.New.ns = ns
ns.New.Implemented = true
for _, v := range d.PairsMap {
if v.Defaultable {
ns.New.Optional = append(ns.New.Optional, "default_"+v.Name)
for _, v := range ns.ParsedDefaultable() {
ns.New.Optional = append(ns.New.Optional, "default_"+v.Pair.Name)
}
// add default_*_pairs and *_features
hasDefaultNsPairs := false
hasNsFeatures := false
defaultNsPairsName := fmt.Sprintf("default_%s_pairs", ns.Name)
nsFeaturesName := fmt.Sprintf("%s_features", ns.Name)
for _, v := range ns.New.Optional {
if v == defaultNsPairsName {
log.Warnf("Please remove %s pair as it will be automatically generated.", defaultNsPairsName)
hasDefaultNsPairs = true
Xuanwo marked this conversation as resolved.
Show resolved Hide resolved
}
if v == nsFeaturesName {
log.Warnf("Please remove %s pair as it will be automatically generated.", nsFeaturesName)
hasNsFeatures = true
}
}
if !hasDefaultNsPairs {
ns.New.Optional = append(ns.New.Optional, defaultNsPairsName)
srv.Pairs[defaultNsPairsName] = &Pair{
Name: defaultNsPairsName,
Type: templateutils.ToPascal(defaultNsPairsName),
}
}
for _, v := range srv.Pairs {
if v.Defaultable {
ns.New.Optional = append(ns.New.Optional, "default_"+v.Name)
if !hasNsFeatures {
ns.New.Optional = append(ns.New.Optional, nsFeaturesName)
srv.Pairs[nsFeaturesName] = &Pair{
Name: nsFeaturesName,
Type: templateutils.ToPascal(nsFeaturesName),
}
}

Expand Down
36 changes: 11 additions & 25 deletions tests/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.