github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/plugins/shared/hclspec/spec.go (about) 1 package hclspec 2 3 // ObjectSpec wraps the object and returns a spec. 4 func ObjectSpec(obj *Object) *Spec { 5 return &Spec{ 6 Block: &Spec_Object{ 7 Object: obj, 8 }, 9 } 10 } 11 12 // ArraySpec wraps the array and returns a spec. 13 func ArraySpec(array *Array) *Spec { 14 return &Spec{ 15 Block: &Spec_Array{ 16 Array: array, 17 }, 18 } 19 } 20 21 // AttrSpec wraps the attr and returns a spec. 22 func AttrSpec(attr *Attr) *Spec { 23 return &Spec{ 24 Block: &Spec_Attr{ 25 Attr: attr, 26 }, 27 } 28 } 29 30 // BlockSpec wraps the block and returns a spec. 31 func BlockSpec(block *Block) *Spec { 32 return &Spec{ 33 Block: &Spec_BlockValue{ 34 BlockValue: block, 35 }, 36 } 37 } 38 39 // BlockListSpec wraps the block list and returns a spec. 40 func BlockListSpec(blockList *BlockList) *Spec { 41 return &Spec{ 42 Block: &Spec_BlockList{ 43 BlockList: blockList, 44 }, 45 } 46 } 47 48 // BlockSetSpec wraps the block set and returns a spec. 49 func BlockSetSpec(blockSet *BlockSet) *Spec { 50 return &Spec{ 51 Block: &Spec_BlockSet{ 52 BlockSet: blockSet, 53 }, 54 } 55 } 56 57 // BlockMapSpec wraps the block map and returns a spec. 58 func BlockMapSpec(blockMap *BlockMap) *Spec { 59 return &Spec{ 60 Block: &Spec_BlockMap{ 61 BlockMap: blockMap, 62 }, 63 } 64 } 65 66 // DefaultSpec wraps the default and returns a spec. 67 func DefaultSpec(d *Default) *Spec { 68 return &Spec{ 69 Block: &Spec_Default{ 70 Default: d, 71 }, 72 } 73 } 74 75 // LiteralSpec wraps the literal and returns a spec. 76 func LiteralSpec(l *Literal) *Spec { 77 return &Spec{ 78 Block: &Spec_Literal{ 79 Literal: l, 80 }, 81 } 82 } 83 84 // NewObject returns a new object spec. 85 func NewObject(attrs map[string]*Spec) *Spec { 86 return ObjectSpec(&Object{ 87 Attributes: attrs, 88 }) 89 } 90 91 // NewAttr returns a new attribute spec. 92 func NewAttr(name, attrType string, required bool) *Spec { 93 return AttrSpec(&Attr{ 94 Name: name, 95 Type: attrType, 96 Required: required, 97 }) 98 } 99 100 // NewBlock returns a new block spec. 101 func NewBlock(name string, required bool, nested *Spec) *Spec { 102 return BlockSpec(&Block{ 103 Name: name, 104 Required: required, 105 Nested: nested, 106 }) 107 } 108 109 // NewBlockList returns a new block list spec that has no limits. 110 func NewBlockList(name string, nested *Spec) *Spec { 111 return NewBlockListLimited(name, 0, 0, nested) 112 } 113 114 // NewBlockListLimited returns a new block list spec that limits the number of 115 // blocks. 116 func NewBlockListLimited(name string, min, max uint64, nested *Spec) *Spec { 117 return BlockListSpec(&BlockList{ 118 Name: name, 119 MinItems: min, 120 MaxItems: max, 121 Nested: nested, 122 }) 123 } 124 125 // NewBlockSet returns a new block set spec that has no limits. 126 func NewBlockSet(name string, nested *Spec) *Spec { 127 return NewBlockSetLimited(name, 0, 0, nested) 128 } 129 130 // NewBlockSetLimited returns a new block set spec that limits the number of 131 // blocks. 132 func NewBlockSetLimited(name string, min, max uint64, nested *Spec) *Spec { 133 return BlockSetSpec(&BlockSet{ 134 Name: name, 135 MinItems: min, 136 MaxItems: max, 137 Nested: nested, 138 }) 139 } 140 141 // NewBlockMap returns a new block map spec. 142 func NewBlockMap(name string, labels []string, nested *Spec) *Spec { 143 return BlockMapSpec(&BlockMap{ 144 Name: name, 145 Labels: labels, 146 Nested: nested, 147 }) 148 } 149 150 // NewLiteral returns a new literal spec. 151 func NewLiteral(value string) *Spec { 152 return LiteralSpec(&Literal{ 153 Value: value, 154 }) 155 } 156 157 // NewDefault returns a new default spec. 158 func NewDefault(primary, defaultValue *Spec) *Spec { 159 return DefaultSpec(&Default{ 160 Primary: primary, 161 Default: defaultValue, 162 }) 163 } 164 165 // NewArray returns a new array spec. 166 func NewArray(values []*Spec) *Spec { 167 return ArraySpec(&Array{ 168 Values: values, 169 }) 170 }