refactor ifs to reduce indentation
This commit is contained in:
parent
f128b8c4fa
commit
b59c64245b
|
@ -344,36 +344,40 @@ func setElementCompareValue(schema *configschema.Block, v cty.Value, isConfig bo
|
||||||
attrs[name] = cv
|
attrs[name] = cv
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if l := cv.LengthInt(); l > 0 {
|
if l := cv.LengthInt(); l > 0 {
|
||||||
elems := make([]cty.Value, 0, l)
|
elems := make([]cty.Value, 0, l)
|
||||||
for it := cv.ElementIterator(); it.Next(); {
|
for it := cv.ElementIterator(); it.Next(); {
|
||||||
_, ev := it.Element()
|
_, ev := it.Element()
|
||||||
elems = append(elems, setElementCompareValue(&blockType.Block, ev, isConfig))
|
elems = append(elems, setElementCompareValue(&blockType.Block, ev, isConfig))
|
||||||
}
|
}
|
||||||
if blockType.Nesting == configschema.NestingSet {
|
|
||||||
|
switch {
|
||||||
|
case blockType.Nesting == configschema.NestingSet:
|
||||||
// SetValEmpty would panic if given elements that are not
|
// SetValEmpty would panic if given elements that are not
|
||||||
// all of the same type, but that's guaranteed not to
|
// all of the same type, but that's guaranteed not to
|
||||||
// happen here because our input value was _already_ a
|
// happen here because our input value was _already_ a
|
||||||
// set and we've not changed the types of any elements here.
|
// set and we've not changed the types of any elements here.
|
||||||
attrs[name] = cty.SetVal(elems)
|
attrs[name] = cty.SetVal(elems)
|
||||||
} else {
|
|
||||||
if blockType.Block.ImpliedType().HasDynamicTypes() {
|
// NestingList cases
|
||||||
|
case blockType.Block.ImpliedType().HasDynamicTypes():
|
||||||
attrs[name] = cty.TupleVal(elems)
|
attrs[name] = cty.TupleVal(elems)
|
||||||
} else {
|
default:
|
||||||
attrs[name] = cty.ListVal(elems)
|
attrs[name] = cty.ListVal(elems)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if blockType.Nesting == configschema.NestingSet {
|
switch {
|
||||||
|
case blockType.Nesting == configschema.NestingSet:
|
||||||
attrs[name] = cty.SetValEmpty(blockType.Block.ImpliedType())
|
attrs[name] = cty.SetValEmpty(blockType.Block.ImpliedType())
|
||||||
} else {
|
|
||||||
if blockType.Block.ImpliedType().HasDynamicTypes() {
|
// NestingList cases
|
||||||
|
case blockType.Block.ImpliedType().HasDynamicTypes():
|
||||||
attrs[name] = cty.EmptyTupleVal
|
attrs[name] = cty.EmptyTupleVal
|
||||||
} else {
|
default:
|
||||||
attrs[name] = cty.ListValEmpty(blockType.Block.ImpliedType())
|
attrs[name] = cty.ListValEmpty(blockType.Block.ImpliedType())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case configschema.NestingMap:
|
case configschema.NestingMap:
|
||||||
cv := v.GetAttr(name)
|
cv := v.GetAttr(name)
|
||||||
|
@ -386,9 +390,10 @@ func setElementCompareValue(schema *configschema.Block, v cty.Value, isConfig bo
|
||||||
kv, ev := it.Element()
|
kv, ev := it.Element()
|
||||||
elems[kv.AsString()] = setElementCompareValue(&blockType.Block, ev, isConfig)
|
elems[kv.AsString()] = setElementCompareValue(&blockType.Block, ev, isConfig)
|
||||||
}
|
}
|
||||||
if blockType.Block.ImpliedType().HasDynamicTypes() {
|
switch {
|
||||||
|
case blockType.Block.ImpliedType().HasDynamicTypes():
|
||||||
attrs[name] = cty.ObjectVal(elems)
|
attrs[name] = cty.ObjectVal(elems)
|
||||||
} else {
|
default:
|
||||||
attrs[name] = cty.MapVal(elems)
|
attrs[name] = cty.MapVal(elems)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue