refactor ifs to reduce indentation
This commit is contained in:
parent
f128b8c4fa
commit
b59c64245b
|
@ -344,34 +344,38 @@ 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
|
||||||
attrs[name] = cty.TupleVal(elems)
|
case blockType.Block.ImpliedType().HasDynamicTypes():
|
||||||
} else {
|
attrs[name] = cty.TupleVal(elems)
|
||||||
attrs[name] = cty.ListVal(elems)
|
default:
|
||||||
}
|
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
|
||||||
attrs[name] = cty.EmptyTupleVal
|
case blockType.Block.ImpliedType().HasDynamicTypes():
|
||||||
} else {
|
attrs[name] = cty.EmptyTupleVal
|
||||||
attrs[name] = cty.ListValEmpty(blockType.Block.ImpliedType())
|
default:
|
||||||
}
|
attrs[name] = cty.ListValEmpty(blockType.Block.ImpliedType())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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