Condense switch fallthroughs into expr lists
This commit is contained in:
parent
a363bd9b34
commit
b82bd0c280
|
@ -51,11 +51,7 @@ func (p *ResourceProvisioner) Validate(c *terraform.ResourceConfig) (ws []string
|
||||||
num := 0
|
num := 0
|
||||||
for name := range c.Raw {
|
for name := range c.Raw {
|
||||||
switch name {
|
switch name {
|
||||||
case "scripts":
|
case "scripts", "script", "inline":
|
||||||
fallthrough
|
|
||||||
case "script":
|
|
||||||
fallthrough
|
|
||||||
case "inline":
|
|
||||||
num++
|
num++
|
||||||
default:
|
default:
|
||||||
es = append(es, fmt.Errorf("Unknown configuration '%s'", name))
|
es = append(es, fmt.Errorf("Unknown configuration '%s'", name))
|
||||||
|
|
|
@ -33,9 +33,7 @@ type fileLoaderFunc func(path string) (configurable, []string, error)
|
||||||
func loadTree(root string) (*importTree, error) {
|
func loadTree(root string) (*importTree, error) {
|
||||||
var f fileLoaderFunc
|
var f fileLoaderFunc
|
||||||
switch ext(root) {
|
switch ext(root) {
|
||||||
case ".tf":
|
case ".tf", ".tf.json":
|
||||||
fallthrough
|
|
||||||
case ".tf.json":
|
|
||||||
f = loadFileHcl
|
f = loadFileHcl
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
|
@ -299,9 +299,7 @@ func (x *parserLex) lexString(yylval *parserSymType, quoted bool) (int, bool) {
|
||||||
// Let's check to see if we're escaping anything.
|
// Let's check to see if we're escaping anything.
|
||||||
if c == '\\' {
|
if c == '\\' {
|
||||||
switch n := x.next(); n {
|
switch n := x.next(); n {
|
||||||
case '\\':
|
case '\\', '"':
|
||||||
fallthrough
|
|
||||||
case '"':
|
|
||||||
c = n
|
c = n
|
||||||
case 'n':
|
case 'n':
|
||||||
c = '\n'
|
c = '\n'
|
||||||
|
|
|
@ -78,19 +78,11 @@ func addrToSchema(addr []string, schemaMap map[string]*Schema) []*Schema {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch t := current.Type; t {
|
switch t := current.Type; t {
|
||||||
case TypeBool:
|
case TypeBool, TypeInt, TypeFloat, TypeString:
|
||||||
fallthrough
|
|
||||||
case TypeInt:
|
|
||||||
fallthrough
|
|
||||||
case TypeFloat:
|
|
||||||
fallthrough
|
|
||||||
case TypeString:
|
|
||||||
if len(addr) > 0 {
|
if len(addr) > 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
case TypeList:
|
case TypeList, TypeSet:
|
||||||
fallthrough
|
|
||||||
case TypeSet:
|
|
||||||
switch v := current.Elem.(type) {
|
switch v := current.Elem.(type) {
|
||||||
case *Resource:
|
case *Resource:
|
||||||
current = &Schema{
|
current = &Schema{
|
||||||
|
|
|
@ -80,13 +80,7 @@ func (r *ConfigFieldReader) readField(
|
||||||
k := strings.Join(address, ".")
|
k := strings.Join(address, ".")
|
||||||
schema := schemaList[len(schemaList)-1]
|
schema := schemaList[len(schemaList)-1]
|
||||||
switch schema.Type {
|
switch schema.Type {
|
||||||
case TypeBool:
|
case TypeBool, TypeFloat, TypeInt, TypeString:
|
||||||
fallthrough
|
|
||||||
case TypeFloat:
|
|
||||||
fallthrough
|
|
||||||
case TypeInt:
|
|
||||||
fallthrough
|
|
||||||
case TypeString:
|
|
||||||
return r.readPrimitive(k, schema)
|
return r.readPrimitive(k, schema)
|
||||||
case TypeList:
|
case TypeList:
|
||||||
return readListField(&nestedConfigFieldReader{r}, address, schema)
|
return readListField(&nestedConfigFieldReader{r}, address, schema)
|
||||||
|
|
|
@ -39,13 +39,7 @@ func (r *DiffFieldReader) ReadField(address []string) (FieldReadResult, error) {
|
||||||
|
|
||||||
schema := schemaList[len(schemaList)-1]
|
schema := schemaList[len(schemaList)-1]
|
||||||
switch schema.Type {
|
switch schema.Type {
|
||||||
case TypeBool:
|
case TypeBool, TypeInt, TypeFloat, TypeString:
|
||||||
fallthrough
|
|
||||||
case TypeInt:
|
|
||||||
fallthrough
|
|
||||||
case TypeFloat:
|
|
||||||
fallthrough
|
|
||||||
case TypeString:
|
|
||||||
return r.readPrimitive(address, schema)
|
return r.readPrimitive(address, schema)
|
||||||
case TypeList:
|
case TypeList:
|
||||||
return readListField(r, address, schema)
|
return readListField(r, address, schema)
|
||||||
|
|
|
@ -21,13 +21,7 @@ func (r *MapFieldReader) ReadField(address []string) (FieldReadResult, error) {
|
||||||
|
|
||||||
schema := schemaList[len(schemaList)-1]
|
schema := schemaList[len(schemaList)-1]
|
||||||
switch schema.Type {
|
switch schema.Type {
|
||||||
case TypeBool:
|
case TypeBool, TypeInt, TypeFloat, TypeString:
|
||||||
fallthrough
|
|
||||||
case TypeInt:
|
|
||||||
fallthrough
|
|
||||||
case TypeFloat:
|
|
||||||
fallthrough
|
|
||||||
case TypeString:
|
|
||||||
return r.readPrimitive(address, schema)
|
return r.readPrimitive(address, schema)
|
||||||
case TypeList:
|
case TypeList:
|
||||||
return readListField(r, address, schema)
|
return readListField(r, address, schema)
|
||||||
|
|
|
@ -74,13 +74,7 @@ func (w *MapFieldWriter) set(addr []string, value interface{}) error {
|
||||||
|
|
||||||
schema := schemaList[len(schemaList)-1]
|
schema := schemaList[len(schemaList)-1]
|
||||||
switch schema.Type {
|
switch schema.Type {
|
||||||
case TypeBool:
|
case TypeBool, TypeInt, TypeFloat, TypeString:
|
||||||
fallthrough
|
|
||||||
case TypeInt:
|
|
||||||
fallthrough
|
|
||||||
case TypeFloat:
|
|
||||||
fallthrough
|
|
||||||
case TypeString:
|
|
||||||
return w.setPrimitive(addr, value, schema)
|
return w.setPrimitive(addr, value, schema)
|
||||||
case TypeList:
|
case TypeList:
|
||||||
return w.setList(addr, value, schema)
|
return w.setList(addr, value, schema)
|
||||||
|
|
|
@ -378,13 +378,7 @@ func (m schemaMap) Input(
|
||||||
|
|
||||||
var value interface{}
|
var value interface{}
|
||||||
switch v.Type {
|
switch v.Type {
|
||||||
case TypeBool:
|
case TypeBool, TypeInt, TypeFloat, TypeSet:
|
||||||
fallthrough
|
|
||||||
case TypeInt:
|
|
||||||
fallthrough
|
|
||||||
case TypeFloat:
|
|
||||||
fallthrough
|
|
||||||
case TypeSet:
|
|
||||||
continue
|
continue
|
||||||
case TypeString:
|
case TypeString:
|
||||||
value, err = m.inputString(input, k, v)
|
value, err = m.inputString(input, k, v)
|
||||||
|
@ -522,13 +516,7 @@ func (m schemaMap) diff(
|
||||||
all bool) error {
|
all bool) error {
|
||||||
var err error
|
var err error
|
||||||
switch schema.Type {
|
switch schema.Type {
|
||||||
case TypeBool:
|
case TypeBool, TypeInt, TypeFloat, TypeString:
|
||||||
fallthrough
|
|
||||||
case TypeInt:
|
|
||||||
fallthrough
|
|
||||||
case TypeFloat:
|
|
||||||
fallthrough
|
|
||||||
case TypeString:
|
|
||||||
err = m.diffString(k, schema, diff, d, all)
|
err = m.diffString(k, schema, diff, d, all)
|
||||||
case TypeList:
|
case TypeList:
|
||||||
err = m.diffList(k, schema, diff, d, all)
|
err = m.diffList(k, schema, diff, d, all)
|
||||||
|
@ -1170,9 +1158,7 @@ func (m schemaMap) validateType(
|
||||||
var ws []string
|
var ws []string
|
||||||
var es []error
|
var es []error
|
||||||
switch schema.Type {
|
switch schema.Type {
|
||||||
case TypeSet:
|
case TypeSet, TypeList:
|
||||||
fallthrough
|
|
||||||
case TypeList:
|
|
||||||
ws, es = m.validateList(k, raw, schema, c)
|
ws, es = m.validateList(k, raw, schema, c)
|
||||||
case TypeMap:
|
case TypeMap:
|
||||||
ws, es = m.validateMap(k, raw, schema, c)
|
ws, es = m.validateMap(k, raw, schema, c)
|
||||||
|
|
|
@ -149,15 +149,11 @@ func (d *ModuleDiff) ChangeType() DiffChangeType {
|
||||||
for _, r := range d.Resources {
|
for _, r := range d.Resources {
|
||||||
change := r.ChangeType()
|
change := r.ChangeType()
|
||||||
switch change {
|
switch change {
|
||||||
case DiffCreate:
|
case DiffCreate, DiffDestroy:
|
||||||
fallthrough
|
|
||||||
case DiffDestroy:
|
|
||||||
if result == DiffNone {
|
if result == DiffNone {
|
||||||
result = change
|
result = change
|
||||||
}
|
}
|
||||||
case DiffDestroyCreate:
|
case DiffDestroyCreate, DiffUpdate:
|
||||||
fallthrough
|
|
||||||
case DiffUpdate:
|
|
||||||
result = DiffUpdate
|
result = DiffUpdate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,9 +148,7 @@ func (n *GraphNodeConfigResource) DynamicExpand(ctx EvalContext) (*Graph, error)
|
||||||
// Primary and non-destroy modes are responsible for creating/destroying
|
// Primary and non-destroy modes are responsible for creating/destroying
|
||||||
// all the nodes, expanding counts.
|
// all the nodes, expanding counts.
|
||||||
switch n.DestroyMode {
|
switch n.DestroyMode {
|
||||||
case DestroyNone:
|
case DestroyNone, DestroyPrimary:
|
||||||
fallthrough
|
|
||||||
case DestroyPrimary:
|
|
||||||
steps = append(steps, &ResourceCountTransformer{
|
steps = append(steps, &ResourceCountTransformer{
|
||||||
Resource: n.Resource,
|
Resource: n.Resource,
|
||||||
Destroy: n.DestroyMode != DestroyNone,
|
Destroy: n.DestroyMode != DestroyNone,
|
||||||
|
|
Loading…
Reference in New Issue