github.com/beauknowssoftware/makehcl@v0.0.0-20200322000747-1b9bb1e1c008/internal/parse2/commandBlock.go (about) 1 package parse2 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/hcl/v2" 7 ) 8 9 type CommandBlock struct { 10 block *hcl.Block 11 content *hcl.BodyContent 12 Name string 13 Command *StringArray 14 attributes []attribute 15 scope scope 16 } 17 18 var ( 19 commandCommandAttributeSchema = hcl.AttributeSchema{Name: "command", Required: true} 20 commandSchema = &hcl.BodySchema{ 21 Attributes: []hcl.AttributeSchema{ 22 commandCommandAttributeSchema, 23 }, 24 } 25 ) 26 27 func (blk *CommandBlock) initAttributes(gs scope) hcl.Diagnostics { 28 con, result := blk.block.Body.Content(commandSchema) 29 30 if con == nil { 31 return result 32 } 33 34 blk.content = con 35 36 blk.attributes = make([]attribute, 0, len(con.Attributes)) 37 38 blk.scope = &nestedScope{outer: gs} 39 40 local := fmt.Sprintf("command.%v", blk.block.DefRange) 41 42 blk.Name = blk.block.Labels[0] 43 44 for _, attr := range con.Attributes { 45 if attr.Name == commandCommandAttributeSchema.Name { 46 blk.Command = &StringArray{attribute: attr} 47 attr := attribute{ 48 name: fmt.Sprintf("%v.command", local), 49 fillable: blk.Command, 50 scope: blk.scope, 51 dependencies: getDependencies(local, blk.Command.attribute.Expr), 52 } 53 blk.attributes = append(blk.attributes, attr) 54 } 55 } 56 57 return result 58 }