├── .gitignore ├── Godeps ├── Godeps.json ├── Readme └── _workspace │ ├── .gitignore │ └── src │ ├── github.com │ ├── GoogleCloudPlatform │ │ └── kubernetes │ │ │ └── pkg │ │ │ └── api │ │ │ └── resource │ │ │ ├── quantity.go │ │ │ ├── quantity_example_test.go │ │ │ ├── quantity_test.go │ │ │ └── suffix.go │ ├── appc │ │ └── spec │ │ │ └── schema │ │ │ ├── doc.go │ │ │ ├── image.go │ │ │ ├── image_test.go │ │ │ ├── kind.go │ │ │ ├── pod.go │ │ │ ├── pod_test.go │ │ │ ├── types │ │ │ ├── acidentifier.go │ │ │ ├── acidentifier_test.go │ │ │ ├── ackind.go │ │ │ ├── ackind_test.go │ │ │ ├── acname.go │ │ │ ├── acname_test.go │ │ │ ├── annotations.go │ │ │ ├── annotations_test.go │ │ │ ├── app.go │ │ │ ├── app_test.go │ │ │ ├── date.go │ │ │ ├── date_test.go │ │ │ ├── dependencies.go │ │ │ ├── dependencies_test.go │ │ │ ├── doc.go │ │ │ ├── environment.go │ │ │ ├── environment_test.go │ │ │ ├── errors.go │ │ │ ├── event_handler.go │ │ │ ├── exec.go │ │ │ ├── exec_test.go │ │ │ ├── hash.go │ │ │ ├── hash_test.go │ │ │ ├── isolator.go │ │ │ ├── isolator_linux_specific.go │ │ │ ├── isolator_resources.go │ │ │ ├── isolator_test.go │ │ │ ├── labels.go │ │ │ ├── labels_test.go │ │ │ ├── mountpoint.go │ │ │ ├── mountpoint_test.go │ │ │ ├── port.go │ │ │ ├── port_test.go │ │ │ ├── semver.go │ │ │ ├── semver_test.go │ │ │ ├── url.go │ │ │ ├── url_test.go │ │ │ ├── uuid.go │ │ │ ├── uuid_test.go │ │ │ ├── volume.go │ │ │ └── volume_test.go │ │ │ └── version.go │ ├── coreos │ │ └── go-semver │ │ │ └── semver │ │ │ ├── semver.go │ │ │ ├── semver_test.go │ │ │ └── sort.go │ └── spf13 │ │ └── pflag │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── bool.go │ │ ├── bool_test.go │ │ ├── duration.go │ │ ├── example_test.go │ │ ├── export_test.go │ │ ├── flag.go │ │ ├── flag_test.go │ │ ├── float32.go │ │ ├── float64.go │ │ ├── int.go │ │ ├── int32.go │ │ ├── int64.go │ │ ├── int8.go │ │ ├── int_slice.go │ │ ├── int_slice_test.go │ │ ├── ip.go │ │ ├── ipmask.go │ │ ├── string.go │ │ ├── string_slice.go │ │ ├── string_slice_test.go │ │ ├── uint.go │ │ ├── uint16.go │ │ ├── uint32.go │ │ ├── uint64.go │ │ └── uint8.go │ └── speter.net │ └── go │ └── exp │ └── math │ └── dec │ └── inf │ ├── LICENSE │ ├── benchmark_test.go │ ├── dec.go │ ├── dec_go1_2_test.go │ ├── dec_internal_test.go │ ├── dec_test.go │ ├── example_test.go │ ├── rounder.go │ ├── rounder_example_test.go │ └── rounder_test.go ├── LICENSE ├── Makefile ├── README.md ├── deb2aci └── main.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /Godeps/Godeps.json: -------------------------------------------------------------------------------- 1 | { 2 | "ImportPath": "github.com/klizhentas/deb2aci", 3 | "GoVersion": "go1.4.2", 4 | "Packages": [ 5 | "." 6 | ], 7 | "Deps": [ 8 | { 9 | "ImportPath": "github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource", 10 | "Comment": "v0.16.1-271-g86751e8", 11 | "Rev": "86751e8c90a3c0e852afb78d26cb6ba8cdbc37ba" 12 | }, 13 | { 14 | "ImportPath": "github.com/appc/spec/schema", 15 | "Comment": "v0.6.1-10-g806b17c", 16 | "Rev": "806b17c86ba5e5d595fca3f7ed339c8a22fb46c3" 17 | }, 18 | { 19 | "ImportPath": "github.com/coreos/go-semver/semver", 20 | "Rev": "568e959cd89871e61434c1143528d9162da89ef2" 21 | }, 22 | { 23 | "ImportPath": "github.com/spf13/pflag", 24 | "Rev": "67cbc198fd11dab704b214c1e629a97af392c085" 25 | }, 26 | { 27 | "ImportPath": "speter.net/go/exp/math/dec/inf", 28 | "Rev": "42ca6cd68aa922bc3f32f1e056e61b65945d9ad7" 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /Godeps/Readme: -------------------------------------------------------------------------------- 1 | This directory tree is generated automatically by godep. 2 | 3 | Please do not edit. 4 | 5 | See https://github.com/tools/godep for more information. 6 | -------------------------------------------------------------------------------- /Godeps/_workspace/.gitignore: -------------------------------------------------------------------------------- 1 | /pkg 2 | /bin 3 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource/quantity_example_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package resource_test 18 | 19 | import ( 20 | "fmt" 21 | 22 | "github.com/klizhentas/deb2aci/Godeps/_workspace/src/github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource" 23 | ) 24 | 25 | func ExampleFormat() { 26 | memorySize := resource.NewQuantity(5*1024*1024*1024, resource.BinarySI) 27 | fmt.Printf("memorySize = %v\n", memorySize) 28 | 29 | diskSize := resource.NewQuantity(5*1000*1000*1000, resource.DecimalSI) 30 | fmt.Printf("diskSize = %v\n", diskSize) 31 | 32 | cores := resource.NewMilliQuantity(5300, resource.DecimalSI) 33 | fmt.Printf("cores = %v\n", cores) 34 | 35 | // Output: 36 | // memorySize = 5Gi 37 | // diskSize = 5G 38 | // cores = 5300m 39 | } 40 | 41 | func ExampleMustParse() { 42 | memorySize := resource.MustParse("5Gi") 43 | fmt.Printf("memorySize = %v (%v)\n", memorySize.Value(), memorySize.Format) 44 | 45 | diskSize := resource.MustParse("5G") 46 | fmt.Printf("diskSize = %v (%v)\n", diskSize.Value(), diskSize.Format) 47 | 48 | cores := resource.MustParse("5300m") 49 | fmt.Printf("milliCores = %v (%v)\n", cores.MilliValue(), cores.Format) 50 | 51 | cores2 := resource.MustParse("5.4") 52 | fmt.Printf("milliCores = %v (%v)\n", cores2.MilliValue(), cores2.Format) 53 | 54 | // Output: 55 | // memorySize = 5368709120 (BinarySI) 56 | // diskSize = 5000000000 (DecimalSI) 57 | // milliCores = 5300 (DecimalSI) 58 | // milliCores = 5400 (DecimalSI) 59 | } 60 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource/suffix.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors All rights reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package resource 18 | 19 | import ( 20 | "strconv" 21 | ) 22 | 23 | type suffix string 24 | 25 | // suffixer can interpret and construct suffixes. 26 | type suffixer interface { 27 | interpret(suffix) (base, exponent int, fmt Format, ok bool) 28 | construct(base, exponent int, fmt Format) (s suffix, ok bool) 29 | } 30 | 31 | // quantitySuffixer handles suffixes for all three formats that quantity 32 | // can handle. 33 | var quantitySuffixer = newSuffixer() 34 | 35 | type bePair struct { 36 | base, exponent int 37 | } 38 | 39 | type listSuffixer struct { 40 | suffixToBE map[suffix]bePair 41 | beToSuffix map[bePair]suffix 42 | } 43 | 44 | func (ls *listSuffixer) addSuffix(s suffix, pair bePair) { 45 | if ls.suffixToBE == nil { 46 | ls.suffixToBE = map[suffix]bePair{} 47 | } 48 | if ls.beToSuffix == nil { 49 | ls.beToSuffix = map[bePair]suffix{} 50 | } 51 | ls.suffixToBE[s] = pair 52 | ls.beToSuffix[pair] = s 53 | } 54 | 55 | func (ls *listSuffixer) lookup(s suffix) (base, exponent int, ok bool) { 56 | pair, ok := ls.suffixToBE[s] 57 | if !ok { 58 | return 0, 0, false 59 | } 60 | return pair.base, pair.exponent, true 61 | } 62 | 63 | func (ls *listSuffixer) construct(base, exponent int) (s suffix, ok bool) { 64 | s, ok = ls.beToSuffix[bePair{base, exponent}] 65 | return 66 | } 67 | 68 | type suffixHandler struct { 69 | decSuffixes listSuffixer 70 | binSuffixes listSuffixer 71 | } 72 | 73 | func newSuffixer() suffixer { 74 | sh := &suffixHandler{} 75 | 76 | sh.binSuffixes.addSuffix("Ki", bePair{2, 10}) 77 | sh.binSuffixes.addSuffix("Mi", bePair{2, 20}) 78 | sh.binSuffixes.addSuffix("Gi", bePair{2, 30}) 79 | sh.binSuffixes.addSuffix("Ti", bePair{2, 40}) 80 | sh.binSuffixes.addSuffix("Pi", bePair{2, 50}) 81 | sh.binSuffixes.addSuffix("Ei", bePair{2, 60}) 82 | // Don't emit an error when trying to produce 83 | // a suffix for 2^0. 84 | sh.decSuffixes.addSuffix("", bePair{2, 0}) 85 | 86 | sh.decSuffixes.addSuffix("m", bePair{10, -3}) 87 | sh.decSuffixes.addSuffix("", bePair{10, 0}) 88 | sh.decSuffixes.addSuffix("k", bePair{10, 3}) 89 | sh.decSuffixes.addSuffix("M", bePair{10, 6}) 90 | sh.decSuffixes.addSuffix("G", bePair{10, 9}) 91 | sh.decSuffixes.addSuffix("T", bePair{10, 12}) 92 | sh.decSuffixes.addSuffix("P", bePair{10, 15}) 93 | sh.decSuffixes.addSuffix("E", bePair{10, 18}) 94 | 95 | return sh 96 | } 97 | 98 | func (sh *suffixHandler) construct(base, exponent int, fmt Format) (s suffix, ok bool) { 99 | switch fmt { 100 | case DecimalSI: 101 | return sh.decSuffixes.construct(base, exponent) 102 | case BinarySI: 103 | return sh.binSuffixes.construct(base, exponent) 104 | case DecimalExponent: 105 | if base != 10 { 106 | return "", false 107 | } 108 | if exponent == 0 { 109 | return "", true 110 | } 111 | return suffix("e" + strconv.FormatInt(int64(exponent), 10)), true 112 | } 113 | return "", false 114 | } 115 | 116 | func (sh *suffixHandler) interpret(suffix suffix) (base, exponent int, fmt Format, ok bool) { 117 | // Try lookup tables first 118 | if b, e, ok := sh.decSuffixes.lookup(suffix); ok { 119 | return b, e, DecimalSI, true 120 | } 121 | if b, e, ok := sh.binSuffixes.lookup(suffix); ok { 122 | return b, e, BinarySI, true 123 | } 124 | 125 | if len(suffix) > 1 && (suffix[0] == 'E' || suffix[0] == 'e') { 126 | parsed, err := strconv.ParseInt(string(suffix[1:]), 10, 64) 127 | if err != nil { 128 | return 0, 0, DecimalExponent, false 129 | } 130 | return 10, int(parsed), DecimalExponent, true 131 | } 132 | 133 | return 0, 0, DecimalExponent, false 134 | } 135 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package schema provides definitions for the JSON schema of the different 16 | // manifests in the App Container Specification. The manifests are canonically 17 | // represented in their respective structs: 18 | // - `ImageManifest` 19 | // - `PodManifest` 20 | // 21 | // Validation is performed through serialization: if a blob of JSON data will 22 | // unmarshal to one of the *Manifests, it is considered a valid implementation 23 | // of the standard. Similarly, if a constructed *Manifest struct marshals 24 | // successfully to JSON, it must be valid. 25 | package schema 26 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/image.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package schema 16 | 17 | import ( 18 | "encoding/json" 19 | "errors" 20 | 21 | "github.com/klizhentas/deb2aci/Godeps/_workspace/src/github.com/appc/spec/schema/types" 22 | ) 23 | 24 | const ( 25 | ACIExtension = ".aci" 26 | ImageManifestKind = types.ACKind("ImageManifest") 27 | ) 28 | 29 | type ImageManifest struct { 30 | ACKind types.ACKind `json:"acKind"` 31 | ACVersion types.SemVer `json:"acVersion"` 32 | Name types.ACIdentifier `json:"name"` 33 | Labels types.Labels `json:"labels,omitempty"` 34 | App *types.App `json:"app,omitempty"` 35 | Annotations types.Annotations `json:"annotations,omitempty"` 36 | Dependencies types.Dependencies `json:"dependencies,omitempty"` 37 | PathWhitelist []string `json:"pathWhitelist,omitempty"` 38 | } 39 | 40 | // imageManifest is a model to facilitate extra validation during the 41 | // unmarshalling of the ImageManifest 42 | type imageManifest ImageManifest 43 | 44 | func BlankImageManifest() *ImageManifest { 45 | return &ImageManifest{ACKind: ImageManifestKind, ACVersion: AppContainerVersion} 46 | } 47 | 48 | func (im *ImageManifest) UnmarshalJSON(data []byte) error { 49 | a := imageManifest(*im) 50 | err := json.Unmarshal(data, &a) 51 | if err != nil { 52 | return err 53 | } 54 | nim := ImageManifest(a) 55 | if err := nim.assertValid(); err != nil { 56 | return err 57 | } 58 | *im = nim 59 | return nil 60 | } 61 | 62 | func (im ImageManifest) MarshalJSON() ([]byte, error) { 63 | if err := im.assertValid(); err != nil { 64 | return nil, err 65 | } 66 | return json.Marshal(imageManifest(im)) 67 | } 68 | 69 | var imKindError = types.InvalidACKindError(ImageManifestKind) 70 | 71 | // assertValid performs extra assertions on an ImageManifest to ensure that 72 | // fields are set appropriately, etc. It is used exclusively when marshalling 73 | // and unmarshalling an ImageManifest. Most field-specific validation is 74 | // performed through the individual types being marshalled; assertValid() 75 | // should only deal with higher-level validation. 76 | func (im *ImageManifest) assertValid() error { 77 | if im.ACKind != ImageManifestKind { 78 | return imKindError 79 | } 80 | if im.ACVersion.Empty() { 81 | return errors.New(`acVersion must be set`) 82 | } 83 | if im.Name.Empty() { 84 | return errors.New(`name must be set`) 85 | } 86 | return nil 87 | } 88 | 89 | func (im *ImageManifest) GetLabel(name string) (val string, ok bool) { 90 | return im.Labels.Get(name) 91 | } 92 | 93 | func (im *ImageManifest) GetAnnotation(name string) (val string, ok bool) { 94 | return im.Annotations.Get(name) 95 | } 96 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/image_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package schema 16 | 17 | import "testing" 18 | 19 | func TestEmptyApp(t *testing.T) { 20 | imj := ` 21 | { 22 | "acKind": "ImageManifest", 23 | "acVersion": "0.6.1", 24 | "name": "example.com/test" 25 | } 26 | ` 27 | 28 | var im ImageManifest 29 | 30 | err := im.UnmarshalJSON([]byte(imj)) 31 | if err != nil { 32 | t.Errorf("unexpected error: %v", err) 33 | } 34 | 35 | // Marshal and Unmarshal to verify that no "app": {} is generated on 36 | // Marshal and converted to empty struct on Unmarshal 37 | buf, err := im.MarshalJSON() 38 | if err != nil { 39 | t.Errorf("unexpected error: %v", err) 40 | } 41 | 42 | err = im.UnmarshalJSON(buf) 43 | if err != nil { 44 | t.Errorf("unexpected error: %v", err) 45 | } 46 | } 47 | 48 | func TestImageManifestMerge(t *testing.T) { 49 | imj := `{"name": "example.com/test"}` 50 | im := &ImageManifest{} 51 | 52 | if im.UnmarshalJSON([]byte(imj)) == nil { 53 | t.Fatal("Manifest JSON without acKind and acVersion unmarshalled successfully") 54 | } 55 | 56 | im = BlankImageManifest() 57 | 58 | err := im.UnmarshalJSON([]byte(imj)) 59 | if err != nil { 60 | t.Errorf("unexpected error: %v", err) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/kind.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package schema 16 | 17 | import ( 18 | "encoding/json" 19 | 20 | "github.com/klizhentas/deb2aci/Godeps/_workspace/src/github.com/appc/spec/schema/types" 21 | ) 22 | 23 | type Kind struct { 24 | ACVersion types.SemVer `json:"acVersion"` 25 | ACKind types.ACKind `json:"acKind"` 26 | } 27 | 28 | type kind Kind 29 | 30 | func (k *Kind) UnmarshalJSON(data []byte) error { 31 | nk := kind{} 32 | err := json.Unmarshal(data, &nk) 33 | if err != nil { 34 | return err 35 | } 36 | *k = Kind(nk) 37 | return nil 38 | } 39 | 40 | func (k Kind) MarshalJSON() ([]byte, error) { 41 | return json.Marshal(kind(k)) 42 | } 43 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/pod.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package schema 16 | 17 | import ( 18 | "encoding/json" 19 | "errors" 20 | "fmt" 21 | 22 | "github.com/klizhentas/deb2aci/Godeps/_workspace/src/github.com/appc/spec/schema/types" 23 | ) 24 | 25 | const PodManifestKind = types.ACKind("PodManifest") 26 | 27 | type PodManifest struct { 28 | ACVersion types.SemVer `json:"acVersion"` 29 | ACKind types.ACKind `json:"acKind"` 30 | Apps AppList `json:"apps"` 31 | Volumes []types.Volume `json:"volumes"` 32 | Isolators []types.Isolator `json:"isolators"` 33 | Annotations types.Annotations `json:"annotations"` 34 | Ports []types.ExposedPort `json:"ports"` 35 | } 36 | 37 | // podManifest is a model to facilitate extra validation during the 38 | // unmarshalling of the PodManifest 39 | type podManifest PodManifest 40 | 41 | func BlankPodManifest() *PodManifest { 42 | return &PodManifest{ACKind: PodManifestKind, ACVersion: AppContainerVersion} 43 | } 44 | 45 | func (pm *PodManifest) UnmarshalJSON(data []byte) error { 46 | p := podManifest(*pm) 47 | err := json.Unmarshal(data, &p) 48 | if err != nil { 49 | return err 50 | } 51 | npm := PodManifest(p) 52 | if err := npm.assertValid(); err != nil { 53 | return err 54 | } 55 | *pm = npm 56 | return nil 57 | } 58 | 59 | func (pm PodManifest) MarshalJSON() ([]byte, error) { 60 | if err := pm.assertValid(); err != nil { 61 | return nil, err 62 | } 63 | return json.Marshal(podManifest(pm)) 64 | } 65 | 66 | var pmKindError = types.InvalidACKindError(PodManifestKind) 67 | 68 | // assertValid performs extra assertions on an PodManifest to 69 | // ensure that fields are set appropriately, etc. It is used exclusively when 70 | // marshalling and unmarshalling an PodManifest. Most 71 | // field-specific validation is performed through the individual types being 72 | // marshalled; assertValid() should only deal with higher-level validation. 73 | func (pm *PodManifest) assertValid() error { 74 | if pm.ACKind != PodManifestKind { 75 | return pmKindError 76 | } 77 | return nil 78 | } 79 | 80 | type AppList []RuntimeApp 81 | 82 | type appList AppList 83 | 84 | func (al *AppList) UnmarshalJSON(data []byte) error { 85 | a := appList{} 86 | err := json.Unmarshal(data, &a) 87 | if err != nil { 88 | return err 89 | } 90 | nal := AppList(a) 91 | if err := nal.assertValid(); err != nil { 92 | return err 93 | } 94 | *al = nal 95 | return nil 96 | } 97 | 98 | func (al AppList) MarshalJSON() ([]byte, error) { 99 | if err := al.assertValid(); err != nil { 100 | return nil, err 101 | } 102 | return json.Marshal(appList(al)) 103 | } 104 | 105 | func (al AppList) assertValid() error { 106 | seen := map[types.ACName]bool{} 107 | for _, a := range al { 108 | if _, ok := seen[a.Name]; ok { 109 | return fmt.Errorf(`duplicate apps of name %q`, a.Name) 110 | } 111 | seen[a.Name] = true 112 | } 113 | return nil 114 | } 115 | 116 | // Get retrieves an app by the specified name from the AppList; if there is 117 | // no such app, nil is returned. The returned *RuntimeApp MUST be considered 118 | // read-only. 119 | func (al AppList) Get(name types.ACName) *RuntimeApp { 120 | for _, a := range al { 121 | if name.Equals(a.Name) { 122 | aa := a 123 | return &aa 124 | } 125 | } 126 | return nil 127 | } 128 | 129 | // Mount describes the mapping between a volume and an apps 130 | // MountPoint that will be fulfilled at runtime. 131 | type Mount struct { 132 | Volume types.ACName `json:"volume"` 133 | MountPoint types.ACName `json:"mountPoint"` 134 | } 135 | 136 | func (r Mount) assertValid() error { 137 | if r.Volume.Empty() { 138 | return errors.New("volume must be set") 139 | } 140 | if r.MountPoint.Empty() { 141 | return errors.New("mountPoint must be set") 142 | } 143 | return nil 144 | } 145 | 146 | // RuntimeApp describes an application referenced in a PodManifest 147 | type RuntimeApp struct { 148 | Name types.ACName `json:"name"` 149 | Image RuntimeImage `json:"image"` 150 | App *types.App `json:"app,omitempty"` 151 | Mounts []Mount `json:"mounts,omitempty"` 152 | Annotations types.Annotations `json:"annotations,omitempty"` 153 | } 154 | 155 | // RuntimeImage describes an image referenced in a RuntimeApp 156 | type RuntimeImage struct { 157 | Name *types.ACIdentifier `json:"name,omitempty"` 158 | ID types.Hash `json:"id"` 159 | Labels types.Labels `json:"labels,omitempty"` 160 | } 161 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/pod_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package schema 16 | 17 | import ( 18 | "testing" 19 | 20 | "github.com/klizhentas/deb2aci/Godeps/_workspace/src/github.com/appc/spec/schema/types" 21 | ) 22 | 23 | func TestPodManifestMerge(t *testing.T) { 24 | pmj := `{}` 25 | pm := &PodManifest{} 26 | 27 | if pm.UnmarshalJSON([]byte(pmj)) == nil { 28 | t.Fatal("Manifest JSON without acKind and acVersion unmarshalled successfully") 29 | } 30 | 31 | pm = BlankPodManifest() 32 | 33 | err := pm.UnmarshalJSON([]byte(pmj)) 34 | if err != nil { 35 | t.Errorf("unexpected error: %v", err) 36 | } 37 | } 38 | 39 | func TestAppList(t *testing.T) { 40 | ri := RuntimeImage{ 41 | ID: *types.NewHashSHA512([]byte{}), 42 | } 43 | al := AppList{ 44 | RuntimeApp{ 45 | Name: "foo", 46 | Image: ri, 47 | }, 48 | RuntimeApp{ 49 | Name: "bar", 50 | Image: ri, 51 | }, 52 | } 53 | if _, err := al.MarshalJSON(); err != nil { 54 | t.Errorf("want err=nil, got %v", err) 55 | } 56 | dal := AppList{ 57 | RuntimeApp{ 58 | Name: "foo", 59 | Image: ri, 60 | }, 61 | RuntimeApp{ 62 | Name: "bar", 63 | Image: ri, 64 | }, 65 | RuntimeApp{ 66 | Name: "foo", 67 | Image: ri, 68 | }, 69 | } 70 | if _, err := dal.MarshalJSON(); err == nil { 71 | t.Errorf("want err, got nil") 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/acidentifier.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "errors" 20 | "regexp" 21 | "strings" 22 | ) 23 | 24 | var ( 25 | // ValidACIdentifier is a regular expression that defines a valid ACIdentifier 26 | ValidACIdentifier = regexp.MustCompile("^[a-z0-9]+([-._~/][a-z0-9]+)*$") 27 | 28 | invalidACIdentifierChars = regexp.MustCompile("[^a-z0-9-._~/]") 29 | invalidACIdentifierEdges = regexp.MustCompile("(^[-._~/]+)|([-._~/]+$)") 30 | 31 | ErrEmptyACIdentifier = ACIdentifierError("ACIdentifier cannot be empty") 32 | ErrInvalidEdgeInACIdentifier = ACIdentifierError("ACIdentifier must start and end with only lower case " + 33 | "alphanumeric characters") 34 | ErrInvalidCharInACIdentifier = ACIdentifierError("ACIdentifier must contain only lower case " + 35 | `alphanumeric characters plus "-._~/"`) 36 | ) 37 | 38 | // ACIdentifier (an App-Container Identifier) is a format used by keys in image names 39 | // and image labels of the App Container Standard. An ACIdentifier is restricted to numeric 40 | // and lowercase URI unreserved characters defined in URI RFC[1]; all alphabetical characters 41 | // must be lowercase only. Furthermore, the first and last character ("edges") must be 42 | // alphanumeric, and an ACIdentifier cannot be empty. Programmatically, an ACIdentifier must 43 | // conform to the regular expression ValidACIdentifier. 44 | // 45 | // [1] http://tools.ietf.org/html/rfc3986#section-2.3 46 | type ACIdentifier string 47 | 48 | func (n ACIdentifier) String() string { 49 | return string(n) 50 | } 51 | 52 | // Set sets the ACIdentifier to the given value, if it is valid; if not, 53 | // an error is returned. 54 | func (n *ACIdentifier) Set(s string) error { 55 | nn, err := NewACIdentifier(s) 56 | if err == nil { 57 | *n = *nn 58 | } 59 | return err 60 | } 61 | 62 | // Equals checks whether a given ACIdentifier is equal to this one. 63 | func (n ACIdentifier) Equals(o ACIdentifier) bool { 64 | return strings.ToLower(string(n)) == strings.ToLower(string(o)) 65 | } 66 | 67 | // Empty returns a boolean indicating whether this ACIdentifier is empty. 68 | func (n ACIdentifier) Empty() bool { 69 | return n.String() == "" 70 | } 71 | 72 | // NewACIdentifier generates a new ACIdentifier from a string. If the given string is 73 | // not a valid ACIdentifier, nil and an error are returned. 74 | func NewACIdentifier(s string) (*ACIdentifier, error) { 75 | n := ACIdentifier(s) 76 | if err := n.assertValid(); err != nil { 77 | return nil, err 78 | } 79 | return &n, nil 80 | } 81 | 82 | // MustACIdentifier generates a new ACIdentifier from a string, If the given string is 83 | // not a valid ACIdentifier, it panics. 84 | func MustACIdentifier(s string) *ACIdentifier { 85 | n, err := NewACIdentifier(s) 86 | if err != nil { 87 | panic(err) 88 | } 89 | return n 90 | } 91 | 92 | func (n ACIdentifier) assertValid() error { 93 | s := string(n) 94 | if len(s) == 0 { 95 | return ErrEmptyACIdentifier 96 | } 97 | if invalidACIdentifierChars.MatchString(s) { 98 | return ErrInvalidCharInACIdentifier 99 | } 100 | if invalidACIdentifierEdges.MatchString(s) { 101 | return ErrInvalidEdgeInACIdentifier 102 | } 103 | return nil 104 | } 105 | 106 | // UnmarshalJSON implements the json.Unmarshaler interface 107 | func (n *ACIdentifier) UnmarshalJSON(data []byte) error { 108 | var s string 109 | if err := json.Unmarshal(data, &s); err != nil { 110 | return err 111 | } 112 | nn, err := NewACIdentifier(s) 113 | if err != nil { 114 | return err 115 | } 116 | *n = *nn 117 | return nil 118 | } 119 | 120 | // MarshalJSON implements the json.Marshaler interface 121 | func (n ACIdentifier) MarshalJSON() ([]byte, error) { 122 | if err := n.assertValid(); err != nil { 123 | return nil, err 124 | } 125 | return json.Marshal(n.String()) 126 | } 127 | 128 | // SanitizeACIdentifier replaces every invalid ACIdentifier character in s with an underscore 129 | // making it a legal ACIdentifier string. If the character is an upper case letter it 130 | // replaces it with its lower case. It also removes illegal edge characters 131 | // (hyphens, period, underscore, tilde and slash). 132 | // 133 | // This is a helper function and its algorithm is not part of the spec. It 134 | // should not be called without the user explicitly asking for a suggestion. 135 | func SanitizeACIdentifier(s string) (string, error) { 136 | s = strings.ToLower(s) 137 | s = invalidACIdentifierChars.ReplaceAllString(s, "_") 138 | s = invalidACIdentifierEdges.ReplaceAllString(s, "") 139 | 140 | if s == "" { 141 | return "", errors.New("must contain at least one valid character") 142 | } 143 | 144 | return s, nil 145 | } 146 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/ackind.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "fmt" 20 | ) 21 | 22 | var ( 23 | ErrNoACKind = ACKindError("ACKind must be set") 24 | ) 25 | 26 | // ACKind wraps a string to define a field which must be set with one of 27 | // several ACKind values. If it is unset, or has an invalid value, the field 28 | // will refuse to marshal/unmarshal. 29 | type ACKind string 30 | 31 | func (a ACKind) String() string { 32 | return string(a) 33 | } 34 | 35 | func (a ACKind) assertValid() error { 36 | s := a.String() 37 | switch s { 38 | case "ImageManifest", "PodManifest": 39 | return nil 40 | case "": 41 | return ErrNoACKind 42 | default: 43 | msg := fmt.Sprintf("bad ACKind: %s", s) 44 | return ACKindError(msg) 45 | } 46 | } 47 | 48 | func (a ACKind) MarshalJSON() ([]byte, error) { 49 | if err := a.assertValid(); err != nil { 50 | return nil, err 51 | } 52 | return json.Marshal(a.String()) 53 | } 54 | 55 | func (a *ACKind) UnmarshalJSON(data []byte) error { 56 | var s string 57 | err := json.Unmarshal(data, &s) 58 | if err != nil { 59 | return err 60 | } 61 | na := ACKind(s) 62 | if err := na.assertValid(); err != nil { 63 | return err 64 | } 65 | *a = na 66 | return nil 67 | } 68 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/ackind_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "reflect" 20 | "testing" 21 | ) 22 | 23 | func TestACKindMarshalBad(t *testing.T) { 24 | tests := map[string]error{ 25 | "Foo": ACKindError("bad ACKind: Foo"), 26 | "ApplicationManifest": ACKindError("bad ACKind: ApplicationManifest"), 27 | "": ErrNoACKind, 28 | } 29 | for in, werr := range tests { 30 | a := ACKind(in) 31 | b, gerr := json.Marshal(a) 32 | if b != nil { 33 | t.Errorf("ACKind(%q): want b=nil, got %v", in, b) 34 | } 35 | if jerr, ok := gerr.(*json.MarshalerError); !ok { 36 | t.Errorf("expected JSONMarshalerError") 37 | } else { 38 | if e := jerr.Err; e != werr { 39 | t.Errorf("err=%#v, want %#v", e, werr) 40 | } 41 | } 42 | } 43 | } 44 | 45 | func TestACKindMarshalGood(t *testing.T) { 46 | for i, in := range []string{ 47 | "ImageManifest", 48 | "PodManifest", 49 | } { 50 | a := ACKind(in) 51 | b, err := json.Marshal(a) 52 | if !reflect.DeepEqual(b, []byte(`"`+in+`"`)) { 53 | t.Errorf("#%d: marshalled=%v, want %v", i, b, []byte(in)) 54 | } 55 | if err != nil { 56 | t.Errorf("#%d: err=%v, want nil", i, err) 57 | } 58 | } 59 | } 60 | 61 | func TestACKindUnmarshalBad(t *testing.T) { 62 | tests := []string{ 63 | "ImageManifest", // Not a valid JSON-encoded string 64 | `"garbage"`, 65 | `"AppManifest"`, 66 | `""`, 67 | } 68 | for i, in := range tests { 69 | var a, b ACKind 70 | err := a.UnmarshalJSON([]byte(in)) 71 | if err == nil { 72 | t.Errorf("#%d: err=nil, want non-nil", i) 73 | } else if !reflect.DeepEqual(a, b) { 74 | t.Errorf("#%d: a=%v, want empty", i, a) 75 | } 76 | } 77 | } 78 | 79 | func TestACKindUnmarshalGood(t *testing.T) { 80 | tests := map[string]ACKind{ 81 | `"PodManifest"`: ACKind("PodManifest"), 82 | `"ImageManifest"`: ACKind("ImageManifest"), 83 | } 84 | for in, w := range tests { 85 | var a ACKind 86 | err := json.Unmarshal([]byte(in), &a) 87 | if err != nil { 88 | t.Errorf("%v: err=%v, want nil", in, err) 89 | } else if !reflect.DeepEqual(a, w) { 90 | t.Errorf("%v: a=%v, want %v", in, a, w) 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/acname.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "errors" 20 | "regexp" 21 | "strings" 22 | ) 23 | 24 | var ( 25 | // ValidACName is a regular expression that defines a valid ACName 26 | ValidACName = regexp.MustCompile("^[a-z0-9]+([-][a-z0-9]+)*$") 27 | 28 | invalidACNameChars = regexp.MustCompile("[^a-z0-9-]") 29 | invalidACNameEdges = regexp.MustCompile("(^[-]+)|([-]+$)") 30 | 31 | ErrEmptyACName = ACNameError("ACName cannot be empty") 32 | ErrInvalidEdgeInACName = ACNameError("ACName must start and end with only lower case " + 33 | "alphanumeric characters") 34 | ErrInvalidCharInACName = ACNameError("ACName must contain only lower case " + 35 | `alphanumeric characters plus "-"`) 36 | ) 37 | 38 | // ACName (an App-Container Name) is a format used by keys in different formats 39 | // of the App Container Standard. An ACName is restricted to numeric and lowercase 40 | // characters accepted by the DNS RFC[1] plus "-"; all alphabetical characters must 41 | // be lowercase only. Furthermore, the first and last character ("edges") must be 42 | // alphanumeric, and an ACName cannot be empty. Programmatically, an ACName must 43 | // conform to the regular expression ValidACName. 44 | // 45 | // [1] http://tools.ietf.org/html/rfc1123#page-13 46 | type ACName string 47 | 48 | func (n ACName) String() string { 49 | return string(n) 50 | } 51 | 52 | // Set sets the ACName to the given value, if it is valid; if not, 53 | // an error is returned. 54 | func (n *ACName) Set(s string) error { 55 | nn, err := NewACName(s) 56 | if err == nil { 57 | *n = *nn 58 | } 59 | return err 60 | } 61 | 62 | // Equals checks whether a given ACName is equal to this one. 63 | func (n ACName) Equals(o ACName) bool { 64 | return strings.ToLower(string(n)) == strings.ToLower(string(o)) 65 | } 66 | 67 | // Empty returns a boolean indicating whether this ACName is empty. 68 | func (n ACName) Empty() bool { 69 | return n.String() == "" 70 | } 71 | 72 | // NewACName generates a new ACName from a string. If the given string is 73 | // not a valid ACName, nil and an error are returned. 74 | func NewACName(s string) (*ACName, error) { 75 | n := ACName(s) 76 | if err := n.assertValid(); err != nil { 77 | return nil, err 78 | } 79 | return &n, nil 80 | } 81 | 82 | // MustACName generates a new ACName from a string, If the given string is 83 | // not a valid ACName, it panics. 84 | func MustACName(s string) *ACName { 85 | n, err := NewACName(s) 86 | if err != nil { 87 | panic(err) 88 | } 89 | return n 90 | } 91 | 92 | func (n ACName) assertValid() error { 93 | s := string(n) 94 | if len(s) == 0 { 95 | return ErrEmptyACName 96 | } 97 | if invalidACNameChars.MatchString(s) { 98 | return ErrInvalidCharInACName 99 | } 100 | if invalidACNameEdges.MatchString(s) { 101 | return ErrInvalidEdgeInACName 102 | } 103 | return nil 104 | } 105 | 106 | // UnmarshalJSON implements the json.Unmarshaler interface 107 | func (n *ACName) UnmarshalJSON(data []byte) error { 108 | var s string 109 | if err := json.Unmarshal(data, &s); err != nil { 110 | return err 111 | } 112 | nn, err := NewACName(s) 113 | if err != nil { 114 | return err 115 | } 116 | *n = *nn 117 | return nil 118 | } 119 | 120 | // MarshalJSON implements the json.Marshaler interface 121 | func (n ACName) MarshalJSON() ([]byte, error) { 122 | if err := n.assertValid(); err != nil { 123 | return nil, err 124 | } 125 | return json.Marshal(n.String()) 126 | } 127 | 128 | // SanitizeACName replaces every invalid ACName character in s with a dash 129 | // making it a legal ACName string. If the character is an upper case letter it 130 | // replaces it with its lower case. It also removes illegal edge characters 131 | // (hyphens). 132 | // 133 | // This is a helper function and its algorithm is not part of the spec. It 134 | // should not be called without the user explicitly asking for a suggestion. 135 | func SanitizeACName(s string) (string, error) { 136 | s = strings.ToLower(s) 137 | s = invalidACNameChars.ReplaceAllString(s, "-") 138 | s = invalidACNameEdges.ReplaceAllString(s, "") 139 | 140 | if s == "" { 141 | return "", errors.New("must contain at least one valid character") 142 | } 143 | 144 | return s, nil 145 | } 146 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/annotations.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "fmt" 20 | ) 21 | 22 | type Annotations []Annotation 23 | 24 | type annotations Annotations 25 | 26 | type Annotation struct { 27 | Name ACIdentifier `json:"name"` 28 | Value string `json:"value"` 29 | } 30 | 31 | func (a Annotations) assertValid() error { 32 | seen := map[ACIdentifier]string{} 33 | for _, anno := range a { 34 | _, ok := seen[anno.Name] 35 | if ok { 36 | return fmt.Errorf(`duplicate annotations of name %q`, anno.Name) 37 | } 38 | seen[anno.Name] = anno.Value 39 | } 40 | if c, ok := seen["created"]; ok { 41 | if _, err := NewDate(c); err != nil { 42 | return err 43 | } 44 | } 45 | if h, ok := seen["homepage"]; ok { 46 | if _, err := NewURL(h); err != nil { 47 | return err 48 | } 49 | } 50 | if d, ok := seen["documentation"]; ok { 51 | if _, err := NewURL(d); err != nil { 52 | return err 53 | } 54 | } 55 | 56 | return nil 57 | } 58 | 59 | func (a Annotations) MarshalJSON() ([]byte, error) { 60 | if err := a.assertValid(); err != nil { 61 | return nil, err 62 | } 63 | return json.Marshal(annotations(a)) 64 | } 65 | 66 | func (a *Annotations) UnmarshalJSON(data []byte) error { 67 | var ja annotations 68 | if err := json.Unmarshal(data, &ja); err != nil { 69 | return err 70 | } 71 | na := Annotations(ja) 72 | if err := na.assertValid(); err != nil { 73 | return err 74 | } 75 | *a = na 76 | return nil 77 | } 78 | 79 | // Retrieve the value of an annotation by the given name from Annotations, if 80 | // it exists. 81 | func (a Annotations) Get(name string) (val string, ok bool) { 82 | for _, anno := range a { 83 | if anno.Name.String() == name { 84 | return anno.Value, true 85 | } 86 | } 87 | return "", false 88 | } 89 | 90 | // Set sets the value of an annotation by the given name, overwriting if one already exists. 91 | func (a *Annotations) Set(name ACIdentifier, value string) { 92 | for i, anno := range *a { 93 | if anno.Name.Equals(name) { 94 | (*a)[i] = Annotation{ 95 | Name: name, 96 | Value: value, 97 | } 98 | return 99 | } 100 | } 101 | anno := Annotation{ 102 | Name: name, 103 | Value: value, 104 | } 105 | *a = append(*a, anno) 106 | } 107 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/app.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "errors" 20 | "fmt" 21 | "path" 22 | ) 23 | 24 | type App struct { 25 | Exec Exec `json:"exec"` 26 | EventHandlers []EventHandler `json:"eventHandlers,omitempty"` 27 | User string `json:"user"` 28 | Group string `json:"group"` 29 | WorkingDirectory string `json:"workingDirectory,omitempty"` 30 | Environment Environment `json:"environment,omitempty"` 31 | MountPoints []MountPoint `json:"mountPoints,omitempty"` 32 | Ports []Port `json:"ports,omitempty"` 33 | Isolators Isolators `json:"isolators,omitempty"` 34 | } 35 | 36 | // app is a model to facilitate extra validation during the 37 | // unmarshalling of the App 38 | type app App 39 | 40 | func (a *App) UnmarshalJSON(data []byte) error { 41 | ja := app(*a) 42 | err := json.Unmarshal(data, &ja) 43 | if err != nil { 44 | return err 45 | } 46 | na := App(ja) 47 | if err := na.assertValid(); err != nil { 48 | return err 49 | } 50 | if na.Environment == nil { 51 | na.Environment = make(Environment, 0) 52 | } 53 | *a = na 54 | return nil 55 | } 56 | 57 | func (a App) MarshalJSON() ([]byte, error) { 58 | if err := a.assertValid(); err != nil { 59 | return nil, err 60 | } 61 | return json.Marshal(app(a)) 62 | } 63 | 64 | func (a *App) assertValid() error { 65 | if err := a.Exec.assertValid(); err != nil { 66 | return err 67 | } 68 | if a.User == "" { 69 | return errors.New(`User is required`) 70 | } 71 | if a.Group == "" { 72 | return errors.New(`Group is required`) 73 | } 74 | if !path.IsAbs(a.WorkingDirectory) && a.WorkingDirectory != "" { 75 | return errors.New("WorkingDirectory must be an absolute path") 76 | } 77 | eh := make(map[string]bool) 78 | for _, e := range a.EventHandlers { 79 | name := e.Name 80 | if eh[name] { 81 | return fmt.Errorf("Only one eventHandler of name %q allowed", name) 82 | } 83 | eh[name] = true 84 | } 85 | if err := a.Environment.assertValid(); err != nil { 86 | return err 87 | } 88 | return nil 89 | } 90 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/date.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "fmt" 20 | "time" 21 | ) 22 | 23 | // Date wraps time.Time to marshal/unmarshal to/from JSON strings in strict 24 | // accordance with RFC3339 25 | // TODO(jonboulle): golang's implementation seems slightly buggy here; 26 | // according to http://tools.ietf.org/html/rfc3339#section-5.6 , applications 27 | // may choose to separate the date and time with a space instead of a T 28 | // character (for example, `date --rfc-3339` on GNU coreutils) - but this is 29 | // considered an error by go's parser. File a bug? 30 | type Date time.Time 31 | 32 | func NewDate(s string) (*Date, error) { 33 | t, err := time.Parse(time.RFC3339, s) 34 | if err != nil { 35 | return nil, fmt.Errorf("bad Date: %v", err) 36 | } 37 | d := Date(t) 38 | return &d, nil 39 | } 40 | 41 | func (d Date) String() string { 42 | return time.Time(d).Format(time.RFC3339) 43 | } 44 | 45 | func (d *Date) UnmarshalJSON(data []byte) error { 46 | var s string 47 | if err := json.Unmarshal(data, &s); err != nil { 48 | return err 49 | } 50 | nd, err := NewDate(s) 51 | if err != nil { 52 | return err 53 | } 54 | *d = *nd 55 | return nil 56 | } 57 | 58 | func (d Date) MarshalJSON() ([]byte, error) { 59 | return json.Marshal(d.String()) 60 | } 61 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/date_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "testing" 20 | "time" 21 | ) 22 | 23 | var ( 24 | pst = time.FixedZone("Pacific", -8*60*60) 25 | ) 26 | 27 | func TestUnmarshalDate(t *testing.T) { 28 | tests := []struct { 29 | in string 30 | 31 | wt time.Time 32 | }{ 33 | { 34 | `"2004-05-14T23:11:14+00:00"`, 35 | 36 | time.Date(2004, 05, 14, 23, 11, 14, 0, time.UTC), 37 | }, 38 | { 39 | `"2001-02-03T04:05:06Z"`, 40 | 41 | time.Date(2001, 02, 03, 04, 05, 06, 0, time.UTC), 42 | }, 43 | { 44 | `"2014-11-14T17:36:54-08:00"`, 45 | 46 | time.Date(2014, 11, 14, 17, 36, 54, 0, pst), 47 | }, 48 | { 49 | `"2004-05-14T23:11:14+00:00"`, 50 | 51 | time.Date(2004, 05, 14, 23, 11, 14, 0, time.UTC), 52 | }, 53 | } 54 | for i, tt := range tests { 55 | var d Date 56 | if err := json.Unmarshal([]byte(tt.in), &d); err != nil { 57 | t.Errorf("#%d: got err=%v, want nil", i, err) 58 | } 59 | if gt := time.Time(d); !gt.Equal(tt.wt) { 60 | t.Errorf("#%d: got time=%v, want %v", i, gt, tt.wt) 61 | } 62 | } 63 | } 64 | 65 | func TestUnmarshalDateBad(t *testing.T) { 66 | tests := []string{ 67 | `not a json string`, 68 | `2014-11-14T17:36:54-08:00`, 69 | `"garbage"`, 70 | `"1416015188"`, 71 | `"Fri Nov 14 17:53:02 PST 2014"`, 72 | `"2014-11-1417:36:54"`, 73 | } 74 | for i, tt := range tests { 75 | var d Date 76 | if err := json.Unmarshal([]byte(tt), &d); err == nil { 77 | t.Errorf("#%d: unexpected nil err", i) 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/dependencies.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "errors" 20 | ) 21 | 22 | type Dependencies []Dependency 23 | 24 | type Dependency struct { 25 | ImageName ACIdentifier `json:"imageName"` 26 | ImageID *Hash `json:"imageID,omitempty"` 27 | Labels Labels `json:"labels,omitempty"` 28 | Size uint `json:"size,omitempty"` 29 | } 30 | 31 | type dependency Dependency 32 | 33 | func (d Dependency) assertValid() error { 34 | if len(d.ImageName) < 1 { 35 | return errors.New(`imageName cannot be empty`) 36 | } 37 | return nil 38 | } 39 | 40 | func (d Dependency) MarshalJSON() ([]byte, error) { 41 | if err := d.assertValid(); err != nil { 42 | return nil, err 43 | } 44 | return json.Marshal(dependency(d)) 45 | } 46 | 47 | func (d *Dependency) UnmarshalJSON(data []byte) error { 48 | var jd dependency 49 | if err := json.Unmarshal(data, &jd); err != nil { 50 | return err 51 | } 52 | nd := Dependency(jd) 53 | if err := nd.assertValid(); err != nil { 54 | return err 55 | } 56 | *d = nd 57 | return nil 58 | } 59 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/dependencies_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import "testing" 18 | 19 | func TestEmptyHash(t *testing.T) { 20 | dj := `{"imageName": "example.com/reduce-worker-base"}` 21 | 22 | var d Dependency 23 | 24 | err := d.UnmarshalJSON([]byte(dj)) 25 | if err != nil { 26 | t.Fatalf("unexpected error: %v", err) 27 | } 28 | 29 | // Marshal to verify that marshalling works without validation errors 30 | buf, err := d.MarshalJSON() 31 | if err != nil { 32 | t.Fatalf("unexpected error: %v", err) 33 | } 34 | 35 | // Unmarshal to verify that the generated json will not create wrong empty hash 36 | err = d.UnmarshalJSON(buf) 37 | if err != nil { 38 | t.Fatalf("unexpected error: %v", err) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Package types contains structs representing the various types in the app 16 | // container specification. It is used by the [schema manifest types](../) 17 | // to enforce validation. 18 | package types 19 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/environment.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "fmt" 20 | "regexp" 21 | ) 22 | 23 | var ( 24 | envPattern = regexp.MustCompile("^[A-Za-z_][A-Za-z_0-9]*$") 25 | ) 26 | 27 | type Environment []EnvironmentVariable 28 | 29 | type environment Environment 30 | 31 | type EnvironmentVariable struct { 32 | Name string `json:"name"` 33 | Value string `json:"value"` 34 | } 35 | 36 | func (ev EnvironmentVariable) assertValid() error { 37 | if len(ev.Name) == 0 { 38 | return fmt.Errorf(`environment variable name must not be empty`) 39 | } 40 | if !envPattern.MatchString(ev.Name) { 41 | return fmt.Errorf(`environment variable does not have valid identifier %q`, ev.Name) 42 | } 43 | return nil 44 | } 45 | 46 | func (e Environment) assertValid() error { 47 | seen := map[string]bool{} 48 | for _, env := range e { 49 | if err := env.assertValid(); err != nil { 50 | return err 51 | } 52 | _, ok := seen[env.Name] 53 | if ok { 54 | return fmt.Errorf(`duplicate environment variable of name %q`, env.Name) 55 | } 56 | seen[env.Name] = true 57 | } 58 | 59 | return nil 60 | } 61 | 62 | func (e Environment) MarshalJSON() ([]byte, error) { 63 | if err := e.assertValid(); err != nil { 64 | return nil, err 65 | } 66 | return json.Marshal(environment(e)) 67 | } 68 | 69 | func (e *Environment) UnmarshalJSON(data []byte) error { 70 | var je environment 71 | if err := json.Unmarshal(data, &je); err != nil { 72 | return err 73 | } 74 | ne := Environment(je) 75 | if err := ne.assertValid(); err != nil { 76 | return err 77 | } 78 | *e = ne 79 | return nil 80 | } 81 | 82 | // Retrieve the value of an environment variable by the given name from 83 | // Environment, if it exists. 84 | func (e Environment) Get(name string) (value string, ok bool) { 85 | for _, env := range e { 86 | if env.Name == name { 87 | return env.Value, true 88 | } 89 | } 90 | return "", false 91 | } 92 | 93 | // Set sets the value of an environment variable by the given name, 94 | // overwriting if one already exists. 95 | func (e *Environment) Set(name string, value string) { 96 | for i, env := range *e { 97 | if env.Name == name { 98 | (*e)[i] = EnvironmentVariable{ 99 | Name: name, 100 | Value: value, 101 | } 102 | return 103 | } 104 | } 105 | env := EnvironmentVariable{ 106 | Name: name, 107 | Value: value, 108 | } 109 | *e = append(*e, env) 110 | } 111 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/environment_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | func TestEnvironmentAssertValid(t *testing.T) { 22 | tests := []struct { 23 | env Environment 24 | werr bool 25 | }{ 26 | // duplicate names should fail 27 | { 28 | Environment{ 29 | EnvironmentVariable{"DEBUG", "true"}, 30 | EnvironmentVariable{"DEBUG", "true"}, 31 | }, 32 | true, 33 | }, 34 | // empty name should fail 35 | { 36 | Environment{ 37 | EnvironmentVariable{"", "value"}, 38 | }, 39 | true, 40 | }, 41 | // name beginning with digit should fail 42 | { 43 | Environment{ 44 | EnvironmentVariable{"0DEBUG", "true"}, 45 | }, 46 | true, 47 | }, 48 | // name with non [A-Za-z0-9_] should fail 49 | { 50 | Environment{ 51 | EnvironmentVariable{"VERBOSE-DEBUG", "true"}, 52 | }, 53 | true, 54 | }, 55 | // accepted environment variable forms 56 | { 57 | Environment{ 58 | EnvironmentVariable{"DEBUG", "true"}, 59 | }, 60 | false, 61 | }, 62 | { 63 | Environment{ 64 | EnvironmentVariable{"_0_DEBUG_0_", "true"}, 65 | }, 66 | false, 67 | }, 68 | } 69 | for i, test := range tests { 70 | env := Environment(test.env) 71 | err := env.assertValid() 72 | if gerr := (err != nil); gerr != test.werr { 73 | t.Errorf("#%d: gerr=%t, want %t (err=%v)", i, gerr, test.werr, err) 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import "fmt" 18 | 19 | // An ACKindError is returned when the wrong ACKind is set in a manifest 20 | type ACKindError string 21 | 22 | func (e ACKindError) Error() string { 23 | return string(e) 24 | } 25 | 26 | func InvalidACKindError(kind ACKind) ACKindError { 27 | return ACKindError(fmt.Sprintf("missing or bad ACKind (must be %#v)", kind)) 28 | } 29 | 30 | // An ACVersionError is returned when a bad ACVersion is set in a manifest 31 | type ACVersionError string 32 | 33 | func (e ACVersionError) Error() string { 34 | return string(e) 35 | } 36 | 37 | // An ACIdentifierError is returned when a bad value is used for an ACIdentifier 38 | type ACIdentifierError string 39 | 40 | func (e ACIdentifierError) Error() string { 41 | return string(e) 42 | } 43 | 44 | // An ACNameError is returned when a bad value is used for an ACName 45 | type ACNameError string 46 | 47 | func (e ACNameError) Error() string { 48 | return string(e) 49 | } 50 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/event_handler.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "errors" 20 | "fmt" 21 | ) 22 | 23 | type EventHandler struct { 24 | Name string `json:"name"` 25 | Exec Exec `json:"exec"` 26 | } 27 | 28 | type eventHandler EventHandler 29 | 30 | func (e EventHandler) assertValid() error { 31 | s := e.Name 32 | switch s { 33 | case "pre-start", "post-stop": 34 | return nil 35 | case "": 36 | return errors.New(`eventHandler "name" cannot be empty`) 37 | default: 38 | return fmt.Errorf(`bad eventHandler "name": %q`, s) 39 | } 40 | } 41 | 42 | func (e EventHandler) MarshalJSON() ([]byte, error) { 43 | if err := e.assertValid(); err != nil { 44 | return nil, err 45 | } 46 | return json.Marshal(eventHandler(e)) 47 | } 48 | 49 | func (e *EventHandler) UnmarshalJSON(data []byte) error { 50 | var je eventHandler 51 | err := json.Unmarshal(data, &je) 52 | if err != nil { 53 | return err 54 | } 55 | ne := EventHandler(je) 56 | if err := ne.assertValid(); err != nil { 57 | return err 58 | } 59 | *e = ne 60 | return nil 61 | } 62 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/exec.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "errors" 20 | "path/filepath" 21 | ) 22 | 23 | type Exec []string 24 | 25 | type exec Exec 26 | 27 | func (e Exec) assertValid() error { 28 | if len(e) < 1 { 29 | return errors.New(`Exec cannot be empty`) 30 | } 31 | if !filepath.IsAbs(e[0]) { 32 | return errors.New(`Exec[0] must be absolute path`) 33 | } 34 | return nil 35 | } 36 | 37 | func (e Exec) MarshalJSON() ([]byte, error) { 38 | if err := e.assertValid(); err != nil { 39 | return nil, err 40 | } 41 | return json.Marshal(exec(e)) 42 | } 43 | 44 | func (e *Exec) UnmarshalJSON(data []byte) error { 45 | var je exec 46 | err := json.Unmarshal(data, &je) 47 | if err != nil { 48 | return err 49 | } 50 | ne := Exec(je) 51 | if err := ne.assertValid(); err != nil { 52 | return err 53 | } 54 | *e = ne 55 | return nil 56 | } 57 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/exec_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import "testing" 18 | 19 | func TestExecValid(t *testing.T) { 20 | tests := []Exec{ 21 | Exec{"/bin/httpd"}, 22 | Exec{"/app"}, 23 | Exec{"/app", "arg1", "arg2"}, 24 | } 25 | for i, tt := range tests { 26 | if err := tt.assertValid(); err != nil { 27 | t.Errorf("#%d: err == %v, want nil", i, err) 28 | } 29 | } 30 | } 31 | 32 | func TestExecInvalid(t *testing.T) { 33 | tests := []Exec{ 34 | Exec{}, 35 | Exec{"app"}, 36 | } 37 | for i, tt := range tests { 38 | if err := tt.assertValid(); err == nil { 39 | t.Errorf("#%d: err == nil, want non-nil", i) 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/hash.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "crypto/sha512" 19 | "encoding/json" 20 | "errors" 21 | "fmt" 22 | "reflect" 23 | "strings" 24 | ) 25 | 26 | const ( 27 | maxHashSize = (sha512.Size / 2) + len("sha512-") 28 | ) 29 | 30 | // Hash encodes a hash specified in a string of the form: 31 | // "-" 32 | // for example 33 | // "sha512-06c733b1838136838e6d2d3e8fa5aea4c7905e92[...]" 34 | // Valid types are currently: 35 | // * sha512 36 | type Hash struct { 37 | typ string 38 | Val string 39 | } 40 | 41 | func NewHash(s string) (*Hash, error) { 42 | elems := strings.Split(s, "-") 43 | if len(elems) != 2 { 44 | return nil, errors.New("badly formatted hash string") 45 | } 46 | nh := Hash{ 47 | typ: elems[0], 48 | Val: elems[1], 49 | } 50 | if err := nh.assertValid(); err != nil { 51 | return nil, err 52 | } 53 | return &nh, nil 54 | } 55 | 56 | func (h Hash) String() string { 57 | return fmt.Sprintf("%s-%s", h.typ, h.Val) 58 | } 59 | 60 | func (h *Hash) Set(s string) error { 61 | nh, err := NewHash(s) 62 | if err == nil { 63 | *h = *nh 64 | } 65 | return err 66 | } 67 | 68 | func (h Hash) Empty() bool { 69 | return reflect.DeepEqual(h, Hash{}) 70 | } 71 | 72 | func (h Hash) assertValid() error { 73 | switch h.typ { 74 | case "sha512": 75 | case "": 76 | return fmt.Errorf("unexpected empty hash type") 77 | default: 78 | return fmt.Errorf("unrecognized hash type: %v", h.typ) 79 | } 80 | if h.Val == "" { 81 | return fmt.Errorf("unexpected empty hash value") 82 | } 83 | return nil 84 | } 85 | 86 | func (h *Hash) UnmarshalJSON(data []byte) error { 87 | var s string 88 | if err := json.Unmarshal(data, &s); err != nil { 89 | return err 90 | } 91 | nh, err := NewHash(s) 92 | if err != nil { 93 | return err 94 | } 95 | *h = *nh 96 | return nil 97 | } 98 | 99 | func (h Hash) MarshalJSON() ([]byte, error) { 100 | if err := h.assertValid(); err != nil { 101 | return nil, err 102 | } 103 | return json.Marshal(h.String()) 104 | } 105 | 106 | func NewHashSHA512(b []byte) *Hash { 107 | h := sha512.New() 108 | h.Write(b) 109 | nh, _ := NewHash(fmt.Sprintf("sha512-%x", h.Sum(nil))) 110 | return nh 111 | } 112 | 113 | func ShortHash(hash string) string { 114 | if len(hash) > maxHashSize { 115 | return hash[:maxHashSize] 116 | } 117 | return hash 118 | } 119 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/hash_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "testing" 20 | ) 21 | 22 | func TestMarshalHash(t *testing.T) { 23 | tests := []struct { 24 | typ string 25 | val string 26 | 27 | wout string 28 | }{ 29 | { 30 | "sha512", 31 | "abcdefghi", 32 | 33 | `"sha512-abcdefghi"`, 34 | }, 35 | { 36 | "sha512", 37 | "06c733b1838136838e6d2d3e8fa5aea4c7905e92", 38 | 39 | `"sha512-06c733b1838136838e6d2d3e8fa5aea4c7905e92"`, 40 | }, 41 | } 42 | for i, tt := range tests { 43 | h := Hash{ 44 | typ: tt.typ, 45 | Val: tt.val, 46 | } 47 | b, err := json.Marshal(h) 48 | if err != nil { 49 | t.Errorf("#%d: unexpected err=%v", i, err) 50 | } 51 | if g := string(b); g != tt.wout { 52 | t.Errorf("#%d: got string=%v, want %v", i, g, tt.wout) 53 | } 54 | } 55 | } 56 | 57 | func TestMarshalHashBad(t *testing.T) { 58 | tests := []struct { 59 | typ string 60 | val string 61 | }{ 62 | { 63 | // empty value 64 | "sha512", 65 | "", 66 | }, 67 | { 68 | // bad type 69 | "sha1", 70 | "abcdef", 71 | }, 72 | { 73 | // empty type 74 | "", 75 | "abcdef", 76 | }, 77 | { 78 | // empty empty 79 | "", 80 | "", 81 | }, 82 | } 83 | for i, tt := range tests { 84 | h := Hash{ 85 | typ: tt.typ, 86 | Val: tt.val, 87 | } 88 | g, err := json.Marshal(h) 89 | if err == nil { 90 | t.Errorf("#%d: unexpected nil err", i) 91 | } 92 | if g != nil { 93 | t.Errorf("#%d: unexpected non-nil bytes: %v", i, g) 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/isolator.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | ) 20 | 21 | var ( 22 | isolatorMap map[ACIdentifier]IsolatorValueConstructor 23 | ) 24 | 25 | func init() { 26 | isolatorMap = make(map[ACIdentifier]IsolatorValueConstructor) 27 | } 28 | 29 | type IsolatorValueConstructor func() IsolatorValue 30 | 31 | func AddIsolatorValueConstructor(n ACIdentifier, i IsolatorValueConstructor) { 32 | isolatorMap[n] = i 33 | } 34 | 35 | func AddIsolatorName(n ACIdentifier, ns map[ACIdentifier]struct{}) { 36 | ns[n] = struct{}{} 37 | } 38 | 39 | type Isolators []Isolator 40 | 41 | // GetByName returns the last isolator in the list by the given name. 42 | func (is *Isolators) GetByName(name ACIdentifier) *Isolator { 43 | var i Isolator 44 | for j := len(*is) - 1; j >= 0; j-- { 45 | i = []Isolator(*is)[j] 46 | if i.Name == name { 47 | return &i 48 | } 49 | } 50 | return nil 51 | } 52 | 53 | // Unrecognized returns a set of isolators that are not recognized. 54 | // An isolator is not recognized if it has not had an associated 55 | // constructor registered with AddIsolatorValueConstructor. 56 | func (is *Isolators) Unrecognized() Isolators { 57 | u := Isolators{} 58 | for _, i := range *is { 59 | if i.value == nil { 60 | u = append(u, i) 61 | } 62 | } 63 | return u 64 | } 65 | 66 | type IsolatorValue interface { 67 | UnmarshalJSON(b []byte) error 68 | AssertValid() error 69 | } 70 | type Isolator struct { 71 | Name ACIdentifier `json:"name"` 72 | ValueRaw *json.RawMessage `json:"value"` 73 | value IsolatorValue 74 | } 75 | type isolator Isolator 76 | 77 | func (i *Isolator) Value() IsolatorValue { 78 | return i.value 79 | } 80 | 81 | func (i *Isolator) UnmarshalJSON(b []byte) error { 82 | var ii isolator 83 | err := json.Unmarshal(b, &ii) 84 | if err != nil { 85 | return err 86 | } 87 | 88 | var dst IsolatorValue 89 | con, ok := isolatorMap[ii.Name] 90 | if ok { 91 | dst = con() 92 | err = dst.UnmarshalJSON(*ii.ValueRaw) 93 | if err != nil { 94 | return err 95 | } 96 | err = dst.AssertValid() 97 | if err != nil { 98 | return err 99 | } 100 | } 101 | 102 | i.value = dst 103 | i.ValueRaw = ii.ValueRaw 104 | i.Name = ii.Name 105 | 106 | return nil 107 | } 108 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/isolator_linux_specific.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "errors" 20 | ) 21 | 22 | const ( 23 | LinuxCapabilitiesRetainSetName = "os/linux/capabilities-retain-set" 24 | LinuxCapabilitiesRevokeSetName = "os/linux/capabilities-remove-set" 25 | ) 26 | 27 | var LinuxIsolatorNames = make(map[ACIdentifier]struct{}) 28 | 29 | func init() { 30 | AddIsolatorName(LinuxCapabilitiesRetainSetName, LinuxIsolatorNames) 31 | AddIsolatorName(LinuxCapabilitiesRevokeSetName, LinuxIsolatorNames) 32 | 33 | AddIsolatorValueConstructor(LinuxCapabilitiesRetainSetName, NewLinuxCapabilitiesRetainSet) 34 | AddIsolatorValueConstructor(LinuxCapabilitiesRevokeSetName, NewLinuxCapabilitiesRevokeSet) 35 | } 36 | 37 | type LinuxCapabilitiesSet interface { 38 | Set() []LinuxCapability 39 | AssertValid() error 40 | } 41 | 42 | type LinuxCapability string 43 | type linuxCapabilitiesSetValue struct { 44 | Set []LinuxCapability `json:"set"` 45 | } 46 | 47 | type linuxCapabilitiesSetBase struct { 48 | val linuxCapabilitiesSetValue 49 | } 50 | 51 | func (l linuxCapabilitiesSetBase) AssertValid() error { 52 | if len(l.val.Set) == 0 { 53 | return errors.New("set must be non-empty") 54 | } 55 | return nil 56 | } 57 | 58 | func (l *linuxCapabilitiesSetBase) UnmarshalJSON(b []byte) error { 59 | var v linuxCapabilitiesSetValue 60 | err := json.Unmarshal(b, &v) 61 | if err != nil { 62 | return err 63 | } 64 | 65 | l.val = v 66 | 67 | return err 68 | } 69 | 70 | func (l linuxCapabilitiesSetBase) Set() []LinuxCapability { 71 | return l.val.Set 72 | } 73 | 74 | func NewLinuxCapabilitiesRetainSet() IsolatorValue { 75 | return &LinuxCapabilitiesRetainSet{} 76 | } 77 | 78 | type LinuxCapabilitiesRetainSet struct { 79 | linuxCapabilitiesSetBase 80 | } 81 | 82 | func NewLinuxCapabilitiesRevokeSet() IsolatorValue { 83 | return &LinuxCapabilitiesRevokeSet{} 84 | } 85 | 86 | type LinuxCapabilitiesRevokeSet struct { 87 | linuxCapabilitiesSetBase 88 | } 89 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/isolator_resources.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "errors" 20 | 21 | "github.com/klizhentas/deb2aci/Godeps/_workspace/src/github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource" 22 | ) 23 | 24 | var ( 25 | ErrDefaultTrue = errors.New("default must be false") 26 | ErrDefaultRequired = errors.New("default must be true") 27 | ErrRequestNonEmpty = errors.New("request not supported by this resource, must be empty") 28 | 29 | ResourceIsolatorNames = make(map[ACIdentifier]struct{}) 30 | ) 31 | 32 | const ( 33 | ResourceBlockBandwidthName = "resource/block-bandwidth" 34 | ResourceBlockIOPSName = "resource/block-iops" 35 | ResourceCPUName = "resource/cpu" 36 | ResourceMemoryName = "resource/memory" 37 | ResourceNetworkBandwidthName = "resource/network-bandwidth" 38 | ) 39 | 40 | func init() { 41 | AddIsolatorName(ResourceBlockBandwidthName, ResourceIsolatorNames) 42 | AddIsolatorName(ResourceBlockIOPSName, ResourceIsolatorNames) 43 | AddIsolatorName(ResourceCPUName, ResourceIsolatorNames) 44 | AddIsolatorName(ResourceMemoryName, ResourceIsolatorNames) 45 | AddIsolatorName(ResourceNetworkBandwidthName, ResourceIsolatorNames) 46 | 47 | AddIsolatorValueConstructor(ResourceBlockBandwidthName, NewResourceBlockBandwidth) 48 | AddIsolatorValueConstructor(ResourceBlockIOPSName, NewResourceBlockIOPS) 49 | AddIsolatorValueConstructor(ResourceCPUName, NewResourceCPU) 50 | AddIsolatorValueConstructor(ResourceMemoryName, NewResourceMemory) 51 | AddIsolatorValueConstructor(ResourceNetworkBandwidthName, NewResourceNetworkBandwidth) 52 | } 53 | 54 | func NewResourceBlockBandwidth() IsolatorValue { 55 | return &ResourceBlockBandwidth{} 56 | } 57 | func NewResourceBlockIOPS() IsolatorValue { 58 | return &ResourceBlockIOPS{} 59 | } 60 | func NewResourceCPU() IsolatorValue { 61 | return &ResourceCPU{} 62 | } 63 | func NewResourceNetworkBandwidth() IsolatorValue { 64 | return &ResourceNetworkBandwidth{} 65 | } 66 | func NewResourceMemory() IsolatorValue { 67 | return &ResourceMemory{} 68 | } 69 | 70 | type Resource interface { 71 | Limit() *resource.Quantity 72 | Request() *resource.Quantity 73 | Default() bool 74 | } 75 | 76 | type ResourceBase struct { 77 | val resourceValue 78 | } 79 | 80 | type resourceValue struct { 81 | Default bool `json:"default"` 82 | Request *resource.Quantity `json:"request"` 83 | Limit *resource.Quantity `json:"limit"` 84 | } 85 | 86 | func (r ResourceBase) Limit() *resource.Quantity { 87 | return r.val.Limit 88 | } 89 | func (r ResourceBase) Request() *resource.Quantity { 90 | return r.val.Request 91 | } 92 | func (r ResourceBase) Default() bool { 93 | return r.val.Default 94 | } 95 | 96 | func (r *ResourceBase) UnmarshalJSON(b []byte) error { 97 | return json.Unmarshal(b, &r.val) 98 | } 99 | 100 | func (r ResourceBase) AssertValid() error { 101 | return nil 102 | } 103 | 104 | type ResourceBlockBandwidth struct { 105 | ResourceBase 106 | } 107 | 108 | func (r ResourceBlockBandwidth) AssertValid() error { 109 | if r.Default() != true { 110 | return ErrDefaultRequired 111 | } 112 | if r.Request() != nil { 113 | return ErrRequestNonEmpty 114 | } 115 | return nil 116 | } 117 | 118 | type ResourceBlockIOPS struct { 119 | ResourceBase 120 | } 121 | 122 | func (r ResourceBlockIOPS) AssertValid() error { 123 | if r.Default() != true { 124 | return ErrDefaultRequired 125 | } 126 | if r.Request() != nil { 127 | return ErrRequestNonEmpty 128 | } 129 | return nil 130 | } 131 | 132 | type ResourceCPU struct { 133 | ResourceBase 134 | } 135 | 136 | func (r ResourceCPU) AssertValid() error { 137 | if r.Default() != false { 138 | return ErrDefaultTrue 139 | } 140 | return nil 141 | } 142 | 143 | type ResourceMemory struct { 144 | ResourceBase 145 | } 146 | 147 | func (r ResourceMemory) AssertValid() error { 148 | if r.Default() != false { 149 | return ErrDefaultTrue 150 | } 151 | return nil 152 | } 153 | 154 | type ResourceNetworkBandwidth struct { 155 | ResourceBase 156 | } 157 | 158 | func (r ResourceNetworkBandwidth) AssertValid() error { 159 | if r.Default() != true { 160 | return ErrDefaultRequired 161 | } 162 | if r.Request() != nil { 163 | return ErrRequestNonEmpty 164 | } 165 | return nil 166 | } 167 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/labels.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "fmt" 20 | "sort" 21 | ) 22 | 23 | var ValidOSArch = map[string][]string{ 24 | "linux": {"amd64", "i386", "aarch64", "aarch64_be", "armv6l", "armv7l", "armv7b"}, 25 | "freebsd": {"amd64", "i386", "arm"}, 26 | "darwin": {"x86_64", "i386"}, 27 | } 28 | 29 | type Labels []Label 30 | 31 | type labels Labels 32 | 33 | type Label struct { 34 | Name ACIdentifier `json:"name"` 35 | Value string `json:"value"` 36 | } 37 | 38 | func (l Labels) assertValid() error { 39 | seen := map[ACIdentifier]string{} 40 | for _, lbl := range l { 41 | if lbl.Name == "name" { 42 | return fmt.Errorf(`invalid label name: "name"`) 43 | } 44 | _, ok := seen[lbl.Name] 45 | if ok { 46 | return fmt.Errorf(`duplicate labels of name %q`, lbl.Name) 47 | } 48 | seen[lbl.Name] = lbl.Value 49 | } 50 | if os, ok := seen["os"]; ok { 51 | if validArchs, ok := ValidOSArch[os]; !ok { 52 | // Not a whitelisted OS. TODO: how to warn rather than fail? 53 | validOses := make([]string, 0, len(ValidOSArch)) 54 | for validOs := range ValidOSArch { 55 | validOses = append(validOses, validOs) 56 | } 57 | sort.Strings(validOses) 58 | return fmt.Errorf(`bad os %#v (must be one of: %v)`, os, validOses) 59 | } else { 60 | // Whitelisted OS. We check arch here, as arch makes sense only 61 | // when os is defined. 62 | if arch, ok := seen["arch"]; ok { 63 | found := false 64 | for _, validArch := range validArchs { 65 | if arch == validArch { 66 | found = true 67 | break 68 | } 69 | } 70 | if !found { 71 | return fmt.Errorf(`bad arch %#v for %v (must be one of: %v)`, arch, os, validArchs) 72 | } 73 | } 74 | } 75 | } 76 | return nil 77 | } 78 | 79 | func (l Labels) MarshalJSON() ([]byte, error) { 80 | if err := l.assertValid(); err != nil { 81 | return nil, err 82 | } 83 | return json.Marshal(labels(l)) 84 | } 85 | 86 | func (l *Labels) UnmarshalJSON(data []byte) error { 87 | var jl labels 88 | if err := json.Unmarshal(data, &jl); err != nil { 89 | return err 90 | } 91 | nl := Labels(jl) 92 | if err := nl.assertValid(); err != nil { 93 | return err 94 | } 95 | *l = nl 96 | return nil 97 | } 98 | 99 | // Get retrieves the value of the label by the given name from Labels, if it exists 100 | func (l Labels) Get(name string) (val string, ok bool) { 101 | for _, lbl := range l { 102 | if lbl.Name.String() == name { 103 | return lbl.Value, true 104 | } 105 | } 106 | return "", false 107 | } 108 | 109 | // ToMap creates a map[ACIdentifier]string. 110 | func (l Labels) ToMap() map[ACIdentifier]string { 111 | labelsMap := make(map[ACIdentifier]string) 112 | for _, lbl := range l { 113 | labelsMap[lbl.Name] = lbl.Value 114 | } 115 | return labelsMap 116 | } 117 | 118 | // LabelsFromMap creates Labels from a map[ACIdentifier]string 119 | func LabelsFromMap(labelsMap map[ACIdentifier]string) (Labels, error) { 120 | labels := Labels{} 121 | for n, v := range labelsMap { 122 | labels = append(labels, Label{Name: n, Value: v}) 123 | } 124 | if err := labels.assertValid(); err != nil { 125 | return nil, err 126 | } 127 | return labels, nil 128 | } 129 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/labels_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "strings" 20 | "testing" 21 | ) 22 | 23 | func TestLabels(t *testing.T) { 24 | tests := []struct { 25 | in string 26 | errPrefix string 27 | }{ 28 | { 29 | `[{"name": "os", "value": "linux"}, {"name": "arch", "value": "amd64"}]`, 30 | "", 31 | }, 32 | { 33 | `[{"name": "os", "value": "linux"}, {"name": "arch", "value": "aarch64"}]`, 34 | "", 35 | }, 36 | { 37 | `[{"name": "os", "value": "linux"}, {"name": "arch", "value": "arm64"}]`, 38 | `bad arch "arm64" for linux`, 39 | }, 40 | { 41 | `[{"name": "os", "value": "linux"}, {"name": "arch", "value": "aarch64_be"}]`, 42 | "", 43 | }, 44 | { 45 | `[{"name": "os", "value": "linux"}, {"name": "arch", "value": "arm64_be"}]`, 46 | `bad arch "arm64_be" for linux`, 47 | }, 48 | { 49 | `[{"name": "os", "value": "linux"}, {"name": "arch", "value": "arm"}]`, 50 | `bad arch "arm" for linux`, 51 | }, 52 | { 53 | `[{"name": "os", "value": "linux"}, {"name": "arch", "value": "armv6l"}]`, 54 | "", 55 | }, 56 | { 57 | `[{"name": "os", "value": "linux"}, {"name": "arch", "value": "armv7l"}]`, 58 | "", 59 | }, 60 | { 61 | `[{"name": "os", "value": "linux"}, {"name": "arch", "value": "armv7b"}]`, 62 | "", 63 | }, 64 | { 65 | `[{"name": "os", "value": "freebsd"}, {"name": "arch", "value": "amd64"}]`, 66 | "", 67 | }, 68 | { 69 | `[{"name": "os", "value": "OS/360"}, {"name": "arch", "value": "S/360"}]`, 70 | `bad os "OS/360"`, 71 | }, 72 | { 73 | `[{"name": "os", "value": "freebsd"}, {"name": "arch", "value": "armv7b"}]`, 74 | `bad arch "armv7b" for freebsd`, 75 | }, 76 | { 77 | `[{"name": "name"}]`, 78 | `invalid label name: "name"`, 79 | }, 80 | { 81 | `[{"name": "os", "value": "linux"}, {"name": "os", "value": "freebsd"}]`, 82 | `duplicate labels of name "os"`, 83 | }, 84 | { 85 | `[{"name": "arch", "value": "amd64"}, {"name": "os", "value": "freebsd"}, {"name": "arch", "value": "x86_64"}]`, 86 | `duplicate labels of name "arch"`, 87 | }, 88 | { 89 | `[]`, 90 | "", 91 | }, 92 | } 93 | for i, tt := range tests { 94 | var l Labels 95 | if err := json.Unmarshal([]byte(tt.in), &l); err != nil { 96 | if tt.errPrefix == "" { 97 | t.Errorf("#%d: got err=%v, expected no error", i, err) 98 | } else if !strings.HasPrefix(err.Error(), tt.errPrefix) { 99 | t.Errorf("#%d: got err=%v, expected prefix %#v", i, err, tt.errPrefix) 100 | } 101 | } else { 102 | t.Log(l) 103 | if tt.errPrefix != "" { 104 | t.Errorf("#%d: got no err, expected prefix %#v", i, tt.errPrefix) 105 | } 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/mountpoint.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "errors" 19 | "fmt" 20 | "net/url" 21 | "strconv" 22 | "strings" 23 | ) 24 | 25 | type MountPoint struct { 26 | Name ACName `json:"name"` 27 | Path string `json:"path"` 28 | ReadOnly bool `json:"readOnly,omitempty"` 29 | } 30 | 31 | func (mount MountPoint) assertValid() error { 32 | if mount.Name.Empty() { 33 | return errors.New("name must be set") 34 | } 35 | if len(mount.Path) == 0 { 36 | return errors.New("path must be set") 37 | } 38 | return nil 39 | } 40 | 41 | // MountPointFromString takes a command line mountpoint parameter and returns a mountpoint 42 | // 43 | // It is useful for actool patch-manifest --mounts 44 | // 45 | // Example mountpoint parameters: 46 | // database,path=/tmp,readOnly=true 47 | func MountPointFromString(mp string) (*MountPoint, error) { 48 | var mount MountPoint 49 | 50 | mp = "name=" + mp 51 | v, err := url.ParseQuery(strings.Replace(mp, ",", "&", -1)) 52 | if err != nil { 53 | return nil, err 54 | } 55 | for key, val := range v { 56 | if len(val) > 1 { 57 | return nil, fmt.Errorf("label %s with multiple values %q", key, val) 58 | } 59 | 60 | switch key { 61 | case "name": 62 | acn, err := NewACName(val[0]) 63 | if err != nil { 64 | return nil, err 65 | } 66 | mount.Name = *acn 67 | case "path": 68 | mount.Path = val[0] 69 | case "readOnly": 70 | ro, err := strconv.ParseBool(val[0]) 71 | if err != nil { 72 | return nil, err 73 | } 74 | mount.ReadOnly = ro 75 | default: 76 | return nil, fmt.Errorf("unknown mountpoint parameter %q", key) 77 | } 78 | } 79 | err = mount.assertValid() 80 | if err != nil { 81 | return nil, err 82 | } 83 | 84 | return &mount, nil 85 | } 86 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/mountpoint_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "reflect" 19 | "testing" 20 | ) 21 | 22 | func TestMountPointFromString(t *testing.T) { 23 | tests := []struct { 24 | s string 25 | mount MountPoint 26 | }{ 27 | { 28 | "foobar,path=/tmp", 29 | MountPoint{ 30 | Name: "foobar", 31 | Path: "/tmp", 32 | ReadOnly: false, 33 | }, 34 | }, 35 | { 36 | "foobar,path=/tmp,readOnly=false", 37 | MountPoint{ 38 | Name: "foobar", 39 | Path: "/tmp", 40 | ReadOnly: false, 41 | }, 42 | }, 43 | { 44 | "foobar,path=/tmp,readOnly=true", 45 | MountPoint{ 46 | Name: "foobar", 47 | Path: "/tmp", 48 | ReadOnly: true, 49 | }, 50 | }, 51 | } 52 | for i, tt := range tests { 53 | mount, err := MountPointFromString(tt.s) 54 | if err != nil { 55 | t.Errorf("#%d: got err=%v, want nil", i, err) 56 | } 57 | if !reflect.DeepEqual(*mount, tt.mount) { 58 | t.Errorf("#%d: mount=%v, want %v", i, *mount, tt.mount) 59 | } 60 | } 61 | } 62 | 63 | func TestMountPointFromStringBad(t *testing.T) { 64 | tests := []string{ 65 | "#foobar,path=/tmp", 66 | "foobar,path=/tmp,readOnly=true,asdf=asdf", 67 | "foobar,path=/tmp,readOnly=maybe", 68 | "foobar,path=/tmp,readOnly=", 69 | "foobar,path=", 70 | "foobar", 71 | "", 72 | ",path=/", 73 | } 74 | for i, in := range tests { 75 | l, err := MountPointFromString(in) 76 | if l != nil { 77 | t.Errorf("#%d: got l=%v, want nil", i, l) 78 | } 79 | if err == nil { 80 | t.Errorf("#%d: got err=nil, want non-nil", i) 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/port.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "errors" 20 | "fmt" 21 | "net/url" 22 | "strconv" 23 | "strings" 24 | ) 25 | 26 | type Port struct { 27 | Name ACName `json:"name"` 28 | Protocol string `json:"protocol"` 29 | Port uint `json:"port"` 30 | Count uint `json:"count"` 31 | SocketActivated bool `json:"socketActivated"` 32 | } 33 | 34 | type ExposedPort struct { 35 | Name ACName `json:"name"` 36 | HostPort uint `json:"hostPort"` 37 | } 38 | 39 | type port Port 40 | 41 | func (p *Port) UnmarshalJSON(data []byte) error { 42 | var pp port 43 | if err := json.Unmarshal(data, &pp); err != nil { 44 | return err 45 | } 46 | np := Port(pp) 47 | if err := np.assertValid(); err != nil { 48 | return err 49 | } 50 | if np.Count == 0 { 51 | np.Count = 1 52 | } 53 | *p = np 54 | return nil 55 | } 56 | 57 | func (p Port) MarshalJSON() ([]byte, error) { 58 | if err := p.assertValid(); err != nil { 59 | return nil, err 60 | } 61 | return json.Marshal(port(p)) 62 | } 63 | 64 | func (p Port) assertValid() error { 65 | // Although there are no guarantees, most (if not all) 66 | // transport protocols use 16 bit ports 67 | if p.Port > 65535 || p.Port < 1 { 68 | return errors.New("port must be in 1-65535 range") 69 | } 70 | if p.Port+p.Count > 65536 { 71 | return errors.New("end of port range must be in 1-65535 range") 72 | } 73 | return nil 74 | } 75 | 76 | // PortFromString takes a command line port parameter and returns a port 77 | // 78 | // It is useful for actool patch-manifest --ports 79 | // 80 | // Example port parameters: 81 | // health-check,protocol=udp,port=8000 82 | // query,protocol=tcp,port=8080,count=1,socketActivated=true 83 | func PortFromString(pt string) (*Port, error) { 84 | var port Port 85 | 86 | pt = "name=" + pt 87 | v, err := url.ParseQuery(strings.Replace(pt, ",", "&", -1)) 88 | if err != nil { 89 | return nil, err 90 | } 91 | for key, val := range v { 92 | if len(val) > 1 { 93 | return nil, fmt.Errorf("label %s with multiple values %q", key, val) 94 | } 95 | 96 | switch key { 97 | case "name": 98 | acn, err := NewACName(val[0]) 99 | if err != nil { 100 | return nil, err 101 | } 102 | port.Name = *acn 103 | case "protocol": 104 | port.Protocol = val[0] 105 | case "port": 106 | p, err := strconv.ParseUint(val[0], 10, 16) 107 | if err != nil { 108 | return nil, err 109 | } 110 | port.Port = uint(p) 111 | case "count": 112 | cnt, err := strconv.ParseUint(val[0], 10, 16) 113 | if err != nil { 114 | return nil, err 115 | } 116 | port.Count = uint(cnt) 117 | case "socketActivated": 118 | sa, err := strconv.ParseBool(val[0]) 119 | if err != nil { 120 | return nil, err 121 | } 122 | port.SocketActivated = sa 123 | default: 124 | return nil, fmt.Errorf("unknown port parameter %q", key) 125 | } 126 | } 127 | err = port.assertValid() 128 | if err != nil { 129 | return nil, err 130 | } 131 | 132 | return &port, nil 133 | } 134 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/port_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | func TestGoodPort(t *testing.T) { 22 | p := Port{ 23 | Port: 32456, 24 | Count: 100, 25 | } 26 | if err := p.assertValid(); err != nil { 27 | t.Errorf("good port assertion failed: %v", err) 28 | } 29 | } 30 | 31 | func TestBadPort(t *testing.T) { 32 | p := Port{ 33 | Port: 88888, 34 | } 35 | if p.assertValid() == nil { 36 | t.Errorf("bad port asserted valid") 37 | } 38 | } 39 | 40 | func TestBadRange(t *testing.T) { 41 | p := Port{ 42 | Port: 32456, 43 | Count: 45678, 44 | } 45 | if p.assertValid() == nil { 46 | t.Errorf("bad port range asserted valid") 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/semver.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | 20 | "github.com/klizhentas/deb2aci/Godeps/_workspace/src/github.com/coreos/go-semver/semver" 21 | ) 22 | 23 | var ( 24 | ErrNoZeroSemVer = ACVersionError("SemVer cannot be zero") 25 | ErrBadSemVer = ACVersionError("SemVer is bad") 26 | ) 27 | 28 | // SemVer implements the Unmarshaler interface to define a field that must be 29 | // a semantic version string 30 | // TODO(jonboulle): extend upstream instead of wrapping? 31 | type SemVer semver.Version 32 | 33 | // NewSemVer generates a new SemVer from a string. If the given string does 34 | // not represent a valid SemVer, nil and an error are returned. 35 | func NewSemVer(s string) (*SemVer, error) { 36 | nsv, err := semver.NewVersion(s) 37 | if err != nil { 38 | return nil, ErrBadSemVer 39 | } 40 | v := SemVer(*nsv) 41 | if v.Empty() { 42 | return nil, ErrNoZeroSemVer 43 | } 44 | return &v, nil 45 | } 46 | 47 | func (sv SemVer) String() string { 48 | s := semver.Version(sv) 49 | return s.String() 50 | } 51 | 52 | func (sv SemVer) Empty() bool { 53 | return semver.Version(sv) == semver.Version{} 54 | } 55 | 56 | // UnmarshalJSON implements the json.Unmarshaler interface 57 | func (sv *SemVer) UnmarshalJSON(data []byte) error { 58 | var s string 59 | if err := json.Unmarshal(data, &s); err != nil { 60 | return err 61 | } 62 | v, err := NewSemVer(s) 63 | if err != nil { 64 | return err 65 | } 66 | *sv = *v 67 | return nil 68 | } 69 | 70 | // MarshalJSON implements the json.Marshaler interface 71 | func (sv SemVer) MarshalJSON() ([]byte, error) { 72 | if sv.Empty() { 73 | return nil, ErrNoZeroSemVer 74 | } 75 | return json.Marshal(sv.String()) 76 | } 77 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/semver_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "reflect" 20 | "testing" 21 | 22 | "github.com/klizhentas/deb2aci/Godeps/_workspace/src/github.com/coreos/go-semver/semver" 23 | ) 24 | 25 | func TestMarshalSemver(t *testing.T) { 26 | tests := []struct { 27 | sv SemVer 28 | 29 | wd []byte 30 | }{ 31 | { 32 | SemVer(semver.Version{Major: 1}), 33 | 34 | []byte(`"1.0.0"`), 35 | }, 36 | { 37 | SemVer(semver.Version{Major: 3, Minor: 2, Patch: 1}), 38 | 39 | []byte(`"3.2.1"`), 40 | }, 41 | { 42 | SemVer(semver.Version{Major: 3, Minor: 2, Patch: 1, PreRelease: "foo"}), 43 | 44 | []byte(`"3.2.1-foo"`), 45 | }, 46 | { 47 | SemVer(semver.Version{Major: 1, Minor: 2, Patch: 3, PreRelease: "alpha", Metadata: "git"}), 48 | 49 | []byte(`"1.2.3-alpha+git"`), 50 | }, 51 | } 52 | for i, tt := range tests { 53 | d, err := json.Marshal(tt.sv) 54 | if !reflect.DeepEqual(d, tt.wd) { 55 | t.Errorf("#%d: d=%v, want %v", i, string(d), string(tt.wd)) 56 | } 57 | if err != nil { 58 | t.Errorf("#%d: err=%v, want nil", i, err) 59 | } 60 | } 61 | } 62 | 63 | func TestUnmarshalSemver(t *testing.T) { 64 | tests := []struct { 65 | d []byte 66 | 67 | wsv SemVer 68 | werr bool 69 | }{ 70 | { 71 | []byte(`"1.0.0"`), 72 | 73 | SemVer(semver.Version{Major: 1}), 74 | false, 75 | }, 76 | { 77 | []byte(`"3.2.1"`), 78 | SemVer(semver.Version{Major: 3, Minor: 2, Patch: 1}), 79 | 80 | false, 81 | }, 82 | { 83 | []byte(`"3.2.1-foo"`), 84 | 85 | SemVer(semver.Version{Major: 3, Minor: 2, Patch: 1, PreRelease: "foo"}), 86 | false, 87 | }, 88 | { 89 | []byte(`"1.2.3-alpha+git"`), 90 | 91 | SemVer(semver.Version{Major: 1, Minor: 2, Patch: 3, PreRelease: "alpha", Metadata: "git"}), 92 | false, 93 | }, 94 | { 95 | []byte(`"1"`), 96 | 97 | SemVer{}, 98 | true, 99 | }, 100 | { 101 | []byte(`"1.2.3.4"`), 102 | 103 | SemVer{}, 104 | true, 105 | }, 106 | { 107 | []byte(`1.2.3`), 108 | 109 | SemVer{}, 110 | true, 111 | }, 112 | { 113 | []byte(`"v1.2.3"`), 114 | 115 | SemVer{}, 116 | true, 117 | }, 118 | } 119 | for i, tt := range tests { 120 | var sv SemVer 121 | err := json.Unmarshal(tt.d, &sv) 122 | if !reflect.DeepEqual(sv, tt.wsv) { 123 | t.Errorf("#%d: semver=%#v, want %#v", i, sv, tt.wsv) 124 | } 125 | if gerr := (err != nil); gerr != tt.werr { 126 | t.Errorf("#%d: err==%v, want errstate %t", i, err, tt.werr) 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/url.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "fmt" 20 | "net/url" 21 | ) 22 | 23 | // URL wraps url.URL to marshal/unmarshal to/from JSON strings and enforce 24 | // that the scheme is HTTP/HTTPS only 25 | type URL url.URL 26 | 27 | func NewURL(s string) (*URL, error) { 28 | uu, err := url.Parse(s) 29 | if err != nil { 30 | return nil, fmt.Errorf("bad URL: %v", err) 31 | } 32 | nu := URL(*uu) 33 | if err := nu.assertValidScheme(); err != nil { 34 | return nil, err 35 | } 36 | return &nu, nil 37 | } 38 | 39 | func (u URL) String() string { 40 | uu := url.URL(u) 41 | return uu.String() 42 | } 43 | 44 | func (u URL) assertValidScheme() error { 45 | switch u.Scheme { 46 | case "http", "https": 47 | return nil 48 | default: 49 | return fmt.Errorf("bad URL scheme, must be http/https") 50 | } 51 | } 52 | 53 | func (u *URL) UnmarshalJSON(data []byte) error { 54 | var s string 55 | if err := json.Unmarshal(data, &s); err != nil { 56 | return err 57 | } 58 | nu, err := NewURL(s) 59 | if err != nil { 60 | return err 61 | } 62 | *u = *nu 63 | return nil 64 | } 65 | 66 | func (u URL) MarshalJSON() ([]byte, error) { 67 | if err := u.assertValidScheme(); err != nil { 68 | return nil, err 69 | } 70 | return json.Marshal(u.String()) 71 | } 72 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/url_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "net/url" 20 | "reflect" 21 | "testing" 22 | ) 23 | 24 | func mustParseURL(t *testing.T, s string) url.URL { 25 | u, err := url.Parse(s) 26 | if err != nil { 27 | t.Fatalf("error parsing URL: %v", err) 28 | } 29 | return *u 30 | } 31 | 32 | func TestMarshalURL(t *testing.T) { 33 | tests := []struct { 34 | u url.URL 35 | 36 | w string 37 | }{ 38 | { 39 | mustParseURL(t, "http://foo.com"), 40 | 41 | `"http://foo.com"`, 42 | }, 43 | { 44 | mustParseURL(t, "http://foo.com/huh/what?is=this"), 45 | 46 | `"http://foo.com/huh/what?is=this"`, 47 | }, 48 | { 49 | mustParseURL(t, "https://example.com/bar"), 50 | 51 | `"https://example.com/bar"`, 52 | }, 53 | } 54 | for i, tt := range tests { 55 | u := URL(tt.u) 56 | b, err := json.Marshal(u) 57 | if g := string(b); g != tt.w { 58 | t.Errorf("#%d: got %q, want %q", i, g, tt.w) 59 | } 60 | if err != nil { 61 | t.Errorf("#%d: err=%v, want nil", i, err) 62 | } 63 | 64 | } 65 | } 66 | 67 | func TestMarshalURLBad(t *testing.T) { 68 | tests := []url.URL{ 69 | mustParseURL(t, "ftp://foo.com"), 70 | mustParseURL(t, "unix:///hello"), 71 | } 72 | for i, tt := range tests { 73 | u := URL(tt) 74 | b, err := json.Marshal(u) 75 | if b != nil { 76 | t.Errorf("#%d: got %v, want nil", i, b) 77 | } 78 | if err == nil { 79 | t.Errorf("#%d: got unexpected err=nil", i) 80 | } 81 | } 82 | } 83 | 84 | func TestUnmarshalURL(t *testing.T) { 85 | tests := []struct { 86 | in string 87 | 88 | w URL 89 | }{ 90 | { 91 | `"http://foo.com"`, 92 | 93 | URL(mustParseURL(t, "http://foo.com")), 94 | }, 95 | { 96 | `"http://yis.com/hello?goodbye=yes"`, 97 | 98 | URL(mustParseURL(t, "http://yis.com/hello?goodbye=yes")), 99 | }, 100 | { 101 | `"https://ohai.net"`, 102 | 103 | URL(mustParseURL(t, "https://ohai.net")), 104 | }, 105 | } 106 | for i, tt := range tests { 107 | var g URL 108 | err := json.Unmarshal([]byte(tt.in), &g) 109 | if err != nil { 110 | t.Errorf("#%d: want err=nil, got %v", i, err) 111 | } 112 | if !reflect.DeepEqual(g, tt.w) { 113 | t.Errorf("#%d: got url=%v, want %v", i, g, tt.w) 114 | } 115 | } 116 | } 117 | 118 | func TestUnmarshalURLBad(t *testing.T) { 119 | var empty = URL{} 120 | tests := []string{ 121 | "badjson", 122 | "http://google.com", 123 | `"ftp://example.com"`, 124 | `"unix://file.net"`, 125 | `"not a url"`, 126 | } 127 | for i, tt := range tests { 128 | var g URL 129 | err := json.Unmarshal([]byte(tt), &g) 130 | if err == nil { 131 | t.Errorf("#%d: want err, got nil", i) 132 | } 133 | if !reflect.DeepEqual(g, empty) { 134 | t.Errorf("#%d: got %v, want %v", i, g, empty) 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/uuid.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/hex" 19 | "encoding/json" 20 | "errors" 21 | "fmt" 22 | "reflect" 23 | "strings" 24 | ) 25 | 26 | var ( 27 | ErrNoEmptyUUID = errors.New("UUID cannot be empty") 28 | ) 29 | 30 | // UUID encodes an RFC4122-compliant UUID, marshaled to/from a string 31 | // TODO(jonboulle): vendor a package for this? 32 | // TODO(jonboulle): consider more flexibility in input string formats. 33 | // Right now, we only accept: 34 | // "6733C088-A507-4694-AABF-EDBE4FC5266F" 35 | // "6733C088A5074694AABFEDBE4FC5266F" 36 | type UUID [16]byte 37 | 38 | func (u UUID) String() string { 39 | return fmt.Sprintf("%x-%x-%x-%x-%x", u[0:4], u[4:6], u[6:8], u[8:10], u[10:16]) 40 | } 41 | 42 | func (u *UUID) Set(s string) error { 43 | nu, err := NewUUID(s) 44 | if err == nil { 45 | *u = *nu 46 | } 47 | return err 48 | } 49 | 50 | // NewUUID generates a new UUID from the given string. If the string does not 51 | // represent a valid UUID, nil and an error are returned. 52 | func NewUUID(s string) (*UUID, error) { 53 | s = strings.Replace(s, "-", "", -1) 54 | if len(s) != 32 { 55 | return nil, errors.New("bad UUID length != 32") 56 | } 57 | dec, err := hex.DecodeString(s) 58 | if err != nil { 59 | return nil, err 60 | } 61 | var u UUID 62 | for i, b := range dec { 63 | u[i] = b 64 | } 65 | return &u, nil 66 | } 67 | 68 | func (u UUID) Empty() bool { 69 | return reflect.DeepEqual(u, UUID{}) 70 | } 71 | 72 | func (u *UUID) UnmarshalJSON(data []byte) error { 73 | var s string 74 | if err := json.Unmarshal(data, &s); err != nil { 75 | return err 76 | } 77 | uu, err := NewUUID(s) 78 | if uu.Empty() { 79 | return ErrNoEmptyUUID 80 | } 81 | if err == nil { 82 | *u = *uu 83 | } 84 | return err 85 | } 86 | 87 | func (u UUID) MarshalJSON() ([]byte, error) { 88 | if u.Empty() { 89 | return nil, ErrNoEmptyUUID 90 | } 91 | return json.Marshal(u.String()) 92 | } 93 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/uuid_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import "testing" 18 | 19 | func TestNewUUID(t *testing.T) { 20 | tests := []struct { 21 | in string 22 | ws string 23 | }{ 24 | { 25 | "6733C088-A507-4694-AABF-EDBE4FC5266F", 26 | 27 | "6733c088-a507-4694-aabf-edbe4fc5266f", 28 | }, 29 | { 30 | "6733C088A5074694AABFEDBE4FC5266F", 31 | 32 | "6733c088-a507-4694-aabf-edbe4fc5266f", 33 | }, 34 | { 35 | "0aaf0a79-1a39-4d59-abbf-1bebca8209d2", 36 | 37 | "0aaf0a79-1a39-4d59-abbf-1bebca8209d2", 38 | }, 39 | { 40 | "0aaf0a791a394d59abbf1bebca8209d2", 41 | 42 | "0aaf0a79-1a39-4d59-abbf-1bebca8209d2", 43 | }, 44 | } 45 | for i, tt := range tests { 46 | gu, err := NewUUID(tt.in) 47 | if err != nil { 48 | t.Errorf("#%d: err=%v, want %v", i, err, nil) 49 | } 50 | if gs := gu.String(); gs != tt.ws { 51 | t.Errorf("#%d: String()=%v, want %v", i, gs, tt.ws) 52 | } 53 | } 54 | } 55 | 56 | func TestNewUUIDBad(t *testing.T) { 57 | tests := []string{ 58 | "asdf", 59 | "0AAF0A79-1A39-4D59-ABBF-1BEBCA8209D2ABC", 60 | "", 61 | } 62 | for i, tt := range tests { 63 | g, err := NewUUID(tt) 64 | if err == nil { 65 | t.Errorf("#%d: err=nil, want non-nil", i) 66 | } 67 | if g != nil { 68 | t.Errorf("#%d: err=%v, want %v", i, g, nil) 69 | 70 | } 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/volume.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "encoding/json" 19 | "errors" 20 | "fmt" 21 | "net/url" 22 | "path/filepath" 23 | "strconv" 24 | "strings" 25 | ) 26 | 27 | // Volume encapsulates a volume which should be mounted into the filesystem 28 | // of all apps in a PodManifest 29 | type Volume struct { 30 | Name ACName `json:"name"` 31 | Kind string `json:"kind"` 32 | 33 | // currently used only by "host" 34 | // TODO(jonboulle): factor out? 35 | Source string `json:"source,omitempty"` 36 | ReadOnly *bool `json:"readOnly,omitempty"` 37 | } 38 | 39 | type volume Volume 40 | 41 | func (v Volume) assertValid() error { 42 | if v.Name.Empty() { 43 | return errors.New("name must be set") 44 | } 45 | 46 | switch v.Kind { 47 | case "empty": 48 | if v.Source != "" { 49 | return errors.New("source for empty volume must be empty") 50 | } 51 | return nil 52 | case "host": 53 | if v.Source == "" { 54 | return errors.New("source for host volume cannot be empty") 55 | } 56 | if !filepath.IsAbs(v.Source) { 57 | return errors.New("source for host volume must be absolute path") 58 | } 59 | return nil 60 | default: 61 | return errors.New(`unrecognized volume kind: should be one of "empty", "host"`) 62 | } 63 | } 64 | 65 | func (v *Volume) UnmarshalJSON(data []byte) error { 66 | var vv volume 67 | if err := json.Unmarshal(data, &vv); err != nil { 68 | return err 69 | } 70 | nv := Volume(vv) 71 | if err := nv.assertValid(); err != nil { 72 | return err 73 | } 74 | *v = nv 75 | return nil 76 | } 77 | 78 | func (v Volume) MarshalJSON() ([]byte, error) { 79 | if err := v.assertValid(); err != nil { 80 | return nil, err 81 | } 82 | return json.Marshal(volume(v)) 83 | } 84 | 85 | func (v Volume) String() string { 86 | s := fmt.Sprintf("%s,kind=%s,readOnly=%t", v.Name, v.Kind, *v.ReadOnly) 87 | if v.Source != "" { 88 | s = s + fmt.Sprintf("source=%s", v.Source) 89 | } 90 | return s 91 | } 92 | 93 | // VolumeFromString takes a command line volume parameter and returns a volume 94 | // 95 | // Example volume parameters: 96 | // database,kind=host,source=/tmp,readOnly=true 97 | func VolumeFromString(vp string) (*Volume, error) { 98 | var vol Volume 99 | 100 | vp = "name=" + vp 101 | v, err := url.ParseQuery(strings.Replace(vp, ",", "&", -1)) 102 | if err != nil { 103 | return nil, err 104 | } 105 | for key, val := range v { 106 | if len(val) > 1 { 107 | return nil, fmt.Errorf("label %s with multiple values %q", key, val) 108 | } 109 | 110 | switch key { 111 | case "name": 112 | acn, err := NewACName(val[0]) 113 | if err != nil { 114 | return nil, err 115 | } 116 | vol.Name = *acn 117 | case "kind": 118 | vol.Kind = val[0] 119 | case "source": 120 | vol.Source = val[0] 121 | case "readOnly": 122 | ro, err := strconv.ParseBool(val[0]) 123 | if err != nil { 124 | return nil, err 125 | } 126 | vol.ReadOnly = &ro 127 | default: 128 | return nil, fmt.Errorf("unknown volume parameter %q", key) 129 | } 130 | } 131 | err = vol.assertValid() 132 | if err != nil { 133 | return nil, err 134 | } 135 | 136 | return &vol, nil 137 | } 138 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/types/volume_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package types 16 | 17 | import ( 18 | "reflect" 19 | "testing" 20 | ) 21 | 22 | func TestVolumeFromString(t *testing.T) { 23 | trueVar := true 24 | falseVar := false 25 | tests := []struct { 26 | s string 27 | v Volume 28 | }{ 29 | { 30 | "foobar,kind=host,source=/tmp", 31 | Volume{ 32 | Name: "foobar", 33 | Kind: "host", 34 | Source: "/tmp", 35 | ReadOnly: nil, 36 | }, 37 | }, 38 | { 39 | "foobar,kind=host,source=/tmp,readOnly=false", 40 | Volume{ 41 | Name: "foobar", 42 | Kind: "host", 43 | Source: "/tmp", 44 | ReadOnly: &falseVar, 45 | }, 46 | }, 47 | { 48 | "foobar,kind=host,source=/tmp,readOnly=true", 49 | Volume{ 50 | Name: "foobar", 51 | Kind: "host", 52 | Source: "/tmp", 53 | ReadOnly: &trueVar, 54 | }, 55 | }, 56 | { 57 | "foobar,kind=empty", 58 | Volume{ 59 | Name: "foobar", 60 | Kind: "empty", 61 | ReadOnly: nil, 62 | }, 63 | }, 64 | { 65 | "foobar,kind=empty,readOnly=true", 66 | Volume{ 67 | Name: "foobar", 68 | Kind: "empty", 69 | ReadOnly: &trueVar, 70 | }, 71 | }, 72 | } 73 | for i, tt := range tests { 74 | v, err := VolumeFromString(tt.s) 75 | if err != nil { 76 | t.Errorf("#%d: got err=%v, want nil", i, err) 77 | } 78 | if !reflect.DeepEqual(*v, tt.v) { 79 | t.Errorf("#%d: v=%v, want %v", i, *v, tt.v) 80 | } 81 | } 82 | } 83 | 84 | func TestVolumeFromStringBad(t *testing.T) { 85 | tests := []string{ 86 | "#foobar,kind=host,source=/tmp", 87 | "foobar,kind=host,source=/tmp,readOnly=true,asdf=asdf", 88 | "foobar,kind=empty,source=/tmp", 89 | } 90 | for i, in := range tests { 91 | l, err := VolumeFromString(in) 92 | if l != nil { 93 | t.Errorf("#%d: got l=%v, want nil", i, l) 94 | } 95 | if err == nil { 96 | t.Errorf("#%d: got err=nil, want non-nil", i) 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/appc/spec/schema/version.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The appc Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package schema 16 | 17 | import ( 18 | "github.com/klizhentas/deb2aci/Godeps/_workspace/src/github.com/appc/spec/schema/types" 19 | ) 20 | 21 | const ( 22 | // version represents the canonical version of the appc spec and tooling. 23 | // For now, the schema and tooling is coupled with the spec itself, so 24 | // this must be kept in sync with the VERSION file in the root of the repo. 25 | version string = "0.6.1+git" 26 | ) 27 | 28 | var ( 29 | // AppContainerVersion is the SemVer representation of version 30 | AppContainerVersion types.SemVer 31 | ) 32 | 33 | func init() { 34 | v, err := types.NewSemVer(version) 35 | if err != nil { 36 | panic(err) 37 | } 38 | AppContainerVersion = *v 39 | } 40 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/coreos/go-semver/semver/semver.go: -------------------------------------------------------------------------------- 1 | package semver 2 | 3 | import ( 4 | "bytes" 5 | "errors" 6 | "fmt" 7 | "strconv" 8 | "strings" 9 | ) 10 | 11 | type Version struct { 12 | Major int64 13 | Minor int64 14 | Patch int64 15 | PreRelease PreRelease 16 | Metadata string 17 | } 18 | 19 | type PreRelease string 20 | 21 | func splitOff(input *string, delim string) (val string) { 22 | parts := strings.SplitN(*input, delim, 2) 23 | 24 | if len(parts) == 2 { 25 | *input = parts[0] 26 | val = parts[1] 27 | } 28 | 29 | return val 30 | } 31 | 32 | func NewVersion(version string) (*Version, error) { 33 | v := Version{} 34 | 35 | dotParts := strings.SplitN(version, ".", 3) 36 | 37 | if len(dotParts) != 3 { 38 | return nil, errors.New(fmt.Sprintf("%s is not in dotted-tri format", version)) 39 | } 40 | 41 | v.Metadata = splitOff(&dotParts[2], "+") 42 | v.PreRelease = PreRelease(splitOff(&dotParts[2], "-")) 43 | 44 | parsed := make([]int64, 3, 3) 45 | 46 | for i, v := range dotParts[:3] { 47 | val, err := strconv.ParseInt(v, 10, 64) 48 | parsed[i] = val 49 | if err != nil { 50 | return nil, err 51 | } 52 | } 53 | 54 | v.Major = parsed[0] 55 | v.Minor = parsed[1] 56 | v.Patch = parsed[2] 57 | 58 | return &v, nil 59 | } 60 | 61 | func Must(v *Version, err error) *Version { 62 | if err != nil { 63 | panic(err) 64 | } 65 | return v 66 | } 67 | 68 | func (v *Version) String() string { 69 | var buffer bytes.Buffer 70 | 71 | base := fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Patch) 72 | buffer.WriteString(base) 73 | 74 | if v.PreRelease != "" { 75 | buffer.WriteString(fmt.Sprintf("-%s", v.PreRelease)) 76 | } 77 | 78 | if v.Metadata != "" { 79 | buffer.WriteString(fmt.Sprintf("+%s", v.Metadata)) 80 | } 81 | 82 | return buffer.String() 83 | } 84 | 85 | func (v *Version) LessThan(versionB Version) bool { 86 | versionA := *v 87 | cmp := recursiveCompare(versionA.Slice(), versionB.Slice()) 88 | 89 | if cmp == 0 { 90 | cmp = preReleaseCompare(versionA, versionB) 91 | } 92 | 93 | if cmp == -1 { 94 | return true 95 | } 96 | 97 | return false 98 | } 99 | 100 | /* Slice converts the comparable parts of the semver into a slice of strings */ 101 | func (v *Version) Slice() []int64 { 102 | return []int64{v.Major, v.Minor, v.Patch} 103 | } 104 | 105 | func (p *PreRelease) Slice() []string { 106 | preRelease := string(*p) 107 | return strings.Split(preRelease, ".") 108 | } 109 | 110 | func preReleaseCompare(versionA Version, versionB Version) int { 111 | a := versionA.PreRelease 112 | b := versionB.PreRelease 113 | 114 | /* Handle the case where if two versions are otherwise equal it is the 115 | * one without a PreRelease that is greater */ 116 | if len(a) == 0 && (len(b) > 0) { 117 | return 1 118 | } else if len(b) == 0 && (len(a) > 0) { 119 | return -1 120 | } 121 | 122 | // If there is a prelease, check and compare each part. 123 | return recursivePreReleaseCompare(a.Slice(), b.Slice()) 124 | } 125 | 126 | func recursiveCompare(versionA []int64, versionB []int64) int { 127 | if len(versionA) == 0 { 128 | return 0 129 | } 130 | 131 | a := versionA[0] 132 | b := versionB[0] 133 | 134 | if a > b { 135 | return 1 136 | } else if a < b { 137 | return -1 138 | } 139 | 140 | return recursiveCompare(versionA[1:], versionB[1:]) 141 | } 142 | 143 | func recursivePreReleaseCompare(versionA []string, versionB []string) int { 144 | // Handle slice length disparity. 145 | if len(versionA) == 0 { 146 | // Nothing to compare too, so we return 0 147 | return 0 148 | } else if len(versionB) == 0 { 149 | // We're longer than versionB so return 1. 150 | return 1 151 | } 152 | 153 | a := versionA[0] 154 | b := versionB[0] 155 | 156 | aInt := false; bInt := false 157 | 158 | aI, err := strconv.Atoi(versionA[0]) 159 | if err == nil { 160 | aInt = true 161 | } 162 | 163 | bI, err := strconv.Atoi(versionB[0]) 164 | if err == nil { 165 | bInt = true 166 | } 167 | 168 | // Handle Integer Comparison 169 | if aInt && bInt { 170 | if aI > bI { 171 | return 1 172 | } else if aI < bI { 173 | return -1 174 | } 175 | } 176 | 177 | // Handle String Comparison 178 | if a > b { 179 | return 1 180 | } else if a < b { 181 | return -1 182 | } 183 | 184 | return recursivePreReleaseCompare(versionA[1:], versionB[1:]) 185 | } 186 | 187 | // BumpMajor increments the Major field by 1 and resets all other fields to their default values 188 | func (v *Version) BumpMajor() { 189 | v.Major += 1 190 | v.Minor = 0 191 | v.Patch = 0 192 | v.PreRelease = PreRelease("") 193 | v.Metadata = "" 194 | } 195 | 196 | // BumpMinor increments the Minor field by 1 and resets all other fields to their default values 197 | func (v *Version) BumpMinor() { 198 | v.Minor += 1 199 | v.Patch = 0 200 | v.PreRelease = PreRelease("") 201 | v.Metadata = "" 202 | } 203 | 204 | // BumpPatch increments the Patch field by 1 and resets all other fields to their default values 205 | func (v *Version) BumpPatch() { 206 | v.Patch += 1 207 | v.PreRelease = PreRelease("") 208 | v.Metadata = "" 209 | } 210 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/coreos/go-semver/semver/sort.go: -------------------------------------------------------------------------------- 1 | package semver 2 | 3 | import ( 4 | "sort" 5 | ) 6 | 7 | type Versions []*Version 8 | 9 | func (s Versions) Len() int { 10 | return len(s) 11 | } 12 | 13 | func (s Versions) Swap(i, j int) { 14 | s[i], s[j] = s[j], s[i] 15 | } 16 | 17 | func (s Versions) Less(i, j int) bool { 18 | return s[i].LessThan(*s[j]) 19 | } 20 | 21 | // Sort sorts the given slice of Version 22 | func Sort(versions []*Version) { 23 | sort.Sort(Versions(versions)) 24 | } 25 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | 5 | go: 6 | - 1.3 7 | - 1.4 8 | - tip 9 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Alex Ogier. All rights reserved. 2 | Copyright (c) 2012 The Go Authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/bool.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | // optional interface to indicate boolean flags that can be 9 | // supplied without "=value" text 10 | type boolFlag interface { 11 | Value 12 | IsBoolFlag() bool 13 | } 14 | 15 | // -- bool Value 16 | type boolValue bool 17 | 18 | func newBoolValue(val bool, p *bool) *boolValue { 19 | *p = val 20 | return (*boolValue)(p) 21 | } 22 | 23 | func (b *boolValue) Set(s string) error { 24 | v, err := strconv.ParseBool(s) 25 | *b = boolValue(v) 26 | return err 27 | } 28 | 29 | func (b *boolValue) Type() string { 30 | return "bool" 31 | } 32 | 33 | func (b *boolValue) String() string { return fmt.Sprintf("%v", *b) } 34 | 35 | func (b *boolValue) IsBoolFlag() bool { return true } 36 | 37 | func boolConv(sval string) (interface{}, error) { 38 | return strconv.ParseBool(sval) 39 | } 40 | 41 | // GetBool return the bool value of a flag with the given name 42 | func (f *FlagSet) GetBool(name string) (bool, error) { 43 | val, err := f.getFlagType(name, "bool", boolConv) 44 | if err != nil { 45 | return false, err 46 | } 47 | return val.(bool), nil 48 | } 49 | 50 | // BoolVar defines a bool flag with specified name, default value, and usage string. 51 | // The argument p points to a bool variable in which to store the value of the flag. 52 | func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) { 53 | f.BoolVarP(p, name, "", value, usage) 54 | } 55 | 56 | // Like BoolVar, but accepts a shorthand letter that can be used after a single dash. 57 | func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string) { 58 | flag := f.VarPF(newBoolValue(value, p), name, shorthand, usage) 59 | flag.NoOptDefVal = "true" 60 | } 61 | 62 | // BoolVar defines a bool flag with specified name, default value, and usage string. 63 | // The argument p points to a bool variable in which to store the value of the flag. 64 | func BoolVar(p *bool, name string, value bool, usage string) { 65 | BoolVarP(p, name, "", value, usage) 66 | } 67 | 68 | // Like BoolVar, but accepts a shorthand letter that can be used after a single dash. 69 | func BoolVarP(p *bool, name, shorthand string, value bool, usage string) { 70 | flag := CommandLine.VarPF(newBoolValue(value, p), name, shorthand, usage) 71 | flag.NoOptDefVal = "true" 72 | } 73 | 74 | // Bool defines a bool flag with specified name, default value, and usage string. 75 | // The return value is the address of a bool variable that stores the value of the flag. 76 | func (f *FlagSet) Bool(name string, value bool, usage string) *bool { 77 | return f.BoolP(name, "", value, usage) 78 | } 79 | 80 | // Like Bool, but accepts a shorthand letter that can be used after a single dash. 81 | func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool { 82 | p := new(bool) 83 | f.BoolVarP(p, name, shorthand, value, usage) 84 | return p 85 | } 86 | 87 | // Bool defines a bool flag with specified name, default value, and usage string. 88 | // The return value is the address of a bool variable that stores the value of the flag. 89 | func Bool(name string, value bool, usage string) *bool { 90 | return BoolP(name, "", value, usage) 91 | } 92 | 93 | // Like Bool, but accepts a shorthand letter that can be used after a single dash. 94 | func BoolP(name, shorthand string, value bool, usage string) *bool { 95 | b := CommandLine.BoolP(name, shorthand, value, usage) 96 | return b 97 | } 98 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/duration.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | // -- time.Duration Value 8 | type durationValue time.Duration 9 | 10 | func newDurationValue(val time.Duration, p *time.Duration) *durationValue { 11 | *p = val 12 | return (*durationValue)(p) 13 | } 14 | 15 | func (d *durationValue) Set(s string) error { 16 | v, err := time.ParseDuration(s) 17 | *d = durationValue(v) 18 | return err 19 | } 20 | 21 | func (d *durationValue) Type() string { 22 | return "duration" 23 | } 24 | 25 | func (d *durationValue) String() string { return (*time.Duration)(d).String() } 26 | 27 | func durationConv(sval string) (interface{}, error) { 28 | return time.ParseDuration(sval) 29 | } 30 | 31 | // GetDuration return the duration value of a flag with the given name 32 | func (f *FlagSet) GetDuration(name string) (time.Duration, error) { 33 | val, err := f.getFlagType(name, "duration", durationConv) 34 | if err != nil { 35 | return 0, err 36 | } 37 | return val.(time.Duration), nil 38 | } 39 | 40 | // DurationVar defines a time.Duration flag with specified name, default value, and usage string. 41 | // The argument p points to a time.Duration variable in which to store the value of the flag. 42 | func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string) { 43 | f.VarP(newDurationValue(value, p), name, "", usage) 44 | } 45 | 46 | // Like DurationVar, but accepts a shorthand letter that can be used after a single dash. 47 | func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) { 48 | f.VarP(newDurationValue(value, p), name, shorthand, usage) 49 | } 50 | 51 | // DurationVar defines a time.Duration flag with specified name, default value, and usage string. 52 | // The argument p points to a time.Duration variable in which to store the value of the flag. 53 | func DurationVar(p *time.Duration, name string, value time.Duration, usage string) { 54 | CommandLine.VarP(newDurationValue(value, p), name, "", usage) 55 | } 56 | 57 | // Like DurationVar, but accepts a shorthand letter that can be used after a single dash. 58 | func DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) { 59 | CommandLine.VarP(newDurationValue(value, p), name, shorthand, usage) 60 | } 61 | 62 | // Duration defines a time.Duration flag with specified name, default value, and usage string. 63 | // The return value is the address of a time.Duration variable that stores the value of the flag. 64 | func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration { 65 | p := new(time.Duration) 66 | f.DurationVarP(p, name, "", value, usage) 67 | return p 68 | } 69 | 70 | // Like Duration, but accepts a shorthand letter that can be used after a single dash. 71 | func (f *FlagSet) DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration { 72 | p := new(time.Duration) 73 | f.DurationVarP(p, name, shorthand, value, usage) 74 | return p 75 | } 76 | 77 | // Duration defines a time.Duration flag with specified name, default value, and usage string. 78 | // The return value is the address of a time.Duration variable that stores the value of the flag. 79 | func Duration(name string, value time.Duration, usage string) *time.Duration { 80 | return CommandLine.DurationP(name, "", value, usage) 81 | } 82 | 83 | // Like Duration, but accepts a shorthand letter that can be used after a single dash. 84 | func DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration { 85 | return CommandLine.DurationP(name, shorthand, value, usage) 86 | } 87 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // These examples demonstrate more intricate uses of the flag package. 6 | package pflag_test 7 | 8 | import ( 9 | "errors" 10 | "fmt" 11 | "strings" 12 | "time" 13 | 14 | flag "github.com/klizhentas/deb2aci/Godeps/_workspace/src/github.com/spf13/pflag" 15 | ) 16 | 17 | // Example 1: A single string flag called "species" with default value "gopher". 18 | var species = flag.String("species", "gopher", "the species we are studying") 19 | 20 | // Example 2: A flag with a shorthand letter. 21 | var gopherType = flag.StringP("gopher_type", "g", "pocket", "the variety of gopher") 22 | 23 | // Example 3: A user-defined flag type, a slice of durations. 24 | type interval []time.Duration 25 | 26 | // String is the method to format the flag's value, part of the flag.Value interface. 27 | // The String method's output will be used in diagnostics. 28 | func (i *interval) String() string { 29 | return fmt.Sprint(*i) 30 | } 31 | 32 | func (i *interval) Type() string { 33 | return "interval" 34 | } 35 | 36 | // Set is the method to set the flag value, part of the flag.Value interface. 37 | // Set's argument is a string to be parsed to set the flag. 38 | // It's a comma-separated list, so we split it. 39 | func (i *interval) Set(value string) error { 40 | // If we wanted to allow the flag to be set multiple times, 41 | // accumulating values, we would delete this if statement. 42 | // That would permit usages such as 43 | // -deltaT 10s -deltaT 15s 44 | // and other combinations. 45 | if len(*i) > 0 { 46 | return errors.New("interval flag already set") 47 | } 48 | for _, dt := range strings.Split(value, ",") { 49 | duration, err := time.ParseDuration(dt) 50 | if err != nil { 51 | return err 52 | } 53 | *i = append(*i, duration) 54 | } 55 | return nil 56 | } 57 | 58 | // Define a flag to accumulate durations. Because it has a special type, 59 | // we need to use the Var function and therefore create the flag during 60 | // init. 61 | 62 | var intervalFlag interval 63 | 64 | func init() { 65 | // Tie the command-line flag to the intervalFlag variable and 66 | // set a usage message. 67 | flag.Var(&intervalFlag, "deltaT", "comma-separated list of intervals to use between events") 68 | } 69 | 70 | func Example() { 71 | // All the interesting pieces are with the variables declared above, but 72 | // to enable the flag package to see the flags defined there, one must 73 | // execute, typically at the start of main (not init!): 74 | // flag.Parse() 75 | // We don't run it here because this is not a main function and 76 | // the testing suite has already parsed the flags. 77 | } 78 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/export_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pflag 6 | 7 | import ( 8 | "io/ioutil" 9 | "os" 10 | ) 11 | 12 | // Additional routines compiled into the package only during testing. 13 | 14 | // ResetForTesting clears all flag state and sets the usage function as directed. 15 | // After calling ResetForTesting, parse errors in flag handling will not 16 | // exit the program. 17 | func ResetForTesting(usage func()) { 18 | CommandLine = &FlagSet{ 19 | name: os.Args[0], 20 | errorHandling: ContinueOnError, 21 | output: ioutil.Discard, 22 | } 23 | Usage = usage 24 | } 25 | 26 | // GetCommandLine returns the default FlagSet. 27 | func GetCommandLine() *FlagSet { 28 | return CommandLine 29 | } 30 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/float32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | // -- float32 Value 9 | type float32Value float32 10 | 11 | func newFloat32Value(val float32, p *float32) *float32Value { 12 | *p = val 13 | return (*float32Value)(p) 14 | } 15 | 16 | func (f *float32Value) Set(s string) error { 17 | v, err := strconv.ParseFloat(s, 32) 18 | *f = float32Value(v) 19 | return err 20 | } 21 | 22 | func (f *float32Value) Type() string { 23 | return "float32" 24 | } 25 | 26 | func (f *float32Value) String() string { return fmt.Sprintf("%v", *f) } 27 | 28 | func float32Conv(sval string) (interface{}, error) { 29 | v, err := strconv.ParseFloat(sval, 32) 30 | if err != nil { 31 | return 0, err 32 | } 33 | return float32(v), nil 34 | } 35 | 36 | // GetFloat32 return the float32 value of a flag with the given name 37 | func (f *FlagSet) GetFloat32(name string) (float32, error) { 38 | val, err := f.getFlagType(name, "float32", float32Conv) 39 | if err != nil { 40 | return 0, err 41 | } 42 | return val.(float32), nil 43 | } 44 | 45 | // Float32Var defines a float32 flag with specified name, default value, and usage string. 46 | // The argument p points to a float32 variable in which to store the value of the flag. 47 | func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string) { 48 | f.VarP(newFloat32Value(value, p), name, "", usage) 49 | } 50 | 51 | // Like Float32Var, but accepts a shorthand letter that can be used after a single dash. 52 | func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string) { 53 | f.VarP(newFloat32Value(value, p), name, shorthand, usage) 54 | } 55 | 56 | // Float32Var defines a float32 flag with specified name, default value, and usage string. 57 | // The argument p points to a float32 variable in which to store the value of the flag. 58 | func Float32Var(p *float32, name string, value float32, usage string) { 59 | CommandLine.VarP(newFloat32Value(value, p), name, "", usage) 60 | } 61 | 62 | // Like Float32Var, but accepts a shorthand letter that can be used after a single dash. 63 | func Float32VarP(p *float32, name, shorthand string, value float32, usage string) { 64 | CommandLine.VarP(newFloat32Value(value, p), name, shorthand, usage) 65 | } 66 | 67 | // Float32 defines a float32 flag with specified name, default value, and usage string. 68 | // The return value is the address of a float32 variable that stores the value of the flag. 69 | func (f *FlagSet) Float32(name string, value float32, usage string) *float32 { 70 | p := new(float32) 71 | f.Float32VarP(p, name, "", value, usage) 72 | return p 73 | } 74 | 75 | // Like Float32, but accepts a shorthand letter that can be used after a single dash. 76 | func (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32 { 77 | p := new(float32) 78 | f.Float32VarP(p, name, shorthand, value, usage) 79 | return p 80 | } 81 | 82 | // Float32 defines a float32 flag with specified name, default value, and usage string. 83 | // The return value is the address of a float32 variable that stores the value of the flag. 84 | func Float32(name string, value float32, usage string) *float32 { 85 | return CommandLine.Float32P(name, "", value, usage) 86 | } 87 | 88 | // Like Float32, but accepts a shorthand letter that can be used after a single dash. 89 | func Float32P(name, shorthand string, value float32, usage string) *float32 { 90 | return CommandLine.Float32P(name, shorthand, value, usage) 91 | } 92 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/float64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | // -- float64 Value 9 | type float64Value float64 10 | 11 | func newFloat64Value(val float64, p *float64) *float64Value { 12 | *p = val 13 | return (*float64Value)(p) 14 | } 15 | 16 | func (f *float64Value) Set(s string) error { 17 | v, err := strconv.ParseFloat(s, 64) 18 | *f = float64Value(v) 19 | return err 20 | } 21 | 22 | func (f *float64Value) Type() string { 23 | return "float64" 24 | } 25 | 26 | func (f *float64Value) String() string { return fmt.Sprintf("%v", *f) } 27 | 28 | func float64Conv(sval string) (interface{}, error) { 29 | return strconv.ParseFloat(sval, 64) 30 | } 31 | 32 | // GetFloat64 return the float64 value of a flag with the given name 33 | func (f *FlagSet) GetFloat64(name string) (float64, error) { 34 | val, err := f.getFlagType(name, "float64", float64Conv) 35 | if err != nil { 36 | return 0, err 37 | } 38 | return val.(float64), nil 39 | } 40 | 41 | // Float64Var defines a float64 flag with specified name, default value, and usage string. 42 | // The argument p points to a float64 variable in which to store the value of the flag. 43 | func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) { 44 | f.VarP(newFloat64Value(value, p), name, "", usage) 45 | } 46 | 47 | // Like Float64Var, but accepts a shorthand letter that can be used after a single dash. 48 | func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string) { 49 | f.VarP(newFloat64Value(value, p), name, shorthand, usage) 50 | } 51 | 52 | // Float64Var defines a float64 flag with specified name, default value, and usage string. 53 | // The argument p points to a float64 variable in which to store the value of the flag. 54 | func Float64Var(p *float64, name string, value float64, usage string) { 55 | CommandLine.VarP(newFloat64Value(value, p), name, "", usage) 56 | } 57 | 58 | // Like Float64Var, but accepts a shorthand letter that can be used after a single dash. 59 | func Float64VarP(p *float64, name, shorthand string, value float64, usage string) { 60 | CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage) 61 | } 62 | 63 | // Float64 defines a float64 flag with specified name, default value, and usage string. 64 | // The return value is the address of a float64 variable that stores the value of the flag. 65 | func (f *FlagSet) Float64(name string, value float64, usage string) *float64 { 66 | p := new(float64) 67 | f.Float64VarP(p, name, "", value, usage) 68 | return p 69 | } 70 | 71 | // Like Float64, but accepts a shorthand letter that can be used after a single dash. 72 | func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64 { 73 | p := new(float64) 74 | f.Float64VarP(p, name, shorthand, value, usage) 75 | return p 76 | } 77 | 78 | // Float64 defines a float64 flag with specified name, default value, and usage string. 79 | // The return value is the address of a float64 variable that stores the value of the flag. 80 | func Float64(name string, value float64, usage string) *float64 { 81 | return CommandLine.Float64P(name, "", value, usage) 82 | } 83 | 84 | // Like Float64, but accepts a shorthand letter that can be used after a single dash. 85 | func Float64P(name, shorthand string, value float64, usage string) *float64 { 86 | return CommandLine.Float64P(name, shorthand, value, usage) 87 | } 88 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/int.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | // -- int Value 9 | type intValue int 10 | 11 | func newIntValue(val int, p *int) *intValue { 12 | *p = val 13 | return (*intValue)(p) 14 | } 15 | 16 | func (i *intValue) Set(s string) error { 17 | v, err := strconv.ParseInt(s, 0, 64) 18 | *i = intValue(v) 19 | return err 20 | } 21 | 22 | func (i *intValue) Type() string { 23 | return "int" 24 | } 25 | 26 | func (i *intValue) String() string { return fmt.Sprintf("%v", *i) } 27 | 28 | func intConv(sval string) (interface{}, error) { 29 | return strconv.Atoi(sval) 30 | } 31 | 32 | // GetInt return the int value of a flag with the given name 33 | func (f *FlagSet) GetInt(name string) (int, error) { 34 | val, err := f.getFlagType(name, "int", intConv) 35 | if err != nil { 36 | return 0, err 37 | } 38 | return val.(int), nil 39 | } 40 | 41 | // IntVar defines an int flag with specified name, default value, and usage string. 42 | // The argument p points to an int variable in which to store the value of the flag. 43 | func (f *FlagSet) IntVar(p *int, name string, value int, usage string) { 44 | f.VarP(newIntValue(value, p), name, "", usage) 45 | } 46 | 47 | // Like IntVar, but accepts a shorthand letter that can be used after a single dash. 48 | func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string) { 49 | f.VarP(newIntValue(value, p), name, shorthand, usage) 50 | } 51 | 52 | // IntVar defines an int flag with specified name, default value, and usage string. 53 | // The argument p points to an int variable in which to store the value of the flag. 54 | func IntVar(p *int, name string, value int, usage string) { 55 | CommandLine.VarP(newIntValue(value, p), name, "", usage) 56 | } 57 | 58 | // Like IntVar, but accepts a shorthand letter that can be used after a single dash. 59 | func IntVarP(p *int, name, shorthand string, value int, usage string) { 60 | CommandLine.VarP(newIntValue(value, p), name, shorthand, usage) 61 | } 62 | 63 | // Int defines an int flag with specified name, default value, and usage string. 64 | // The return value is the address of an int variable that stores the value of the flag. 65 | func (f *FlagSet) Int(name string, value int, usage string) *int { 66 | p := new(int) 67 | f.IntVarP(p, name, "", value, usage) 68 | return p 69 | } 70 | 71 | // Like Int, but accepts a shorthand letter that can be used after a single dash. 72 | func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int { 73 | p := new(int) 74 | f.IntVarP(p, name, shorthand, value, usage) 75 | return p 76 | } 77 | 78 | // Int defines an int flag with specified name, default value, and usage string. 79 | // The return value is the address of an int variable that stores the value of the flag. 80 | func Int(name string, value int, usage string) *int { 81 | return CommandLine.IntP(name, "", value, usage) 82 | } 83 | 84 | // Like Int, but accepts a shorthand letter that can be used after a single dash. 85 | func IntP(name, shorthand string, value int, usage string) *int { 86 | return CommandLine.IntP(name, shorthand, value, usage) 87 | } 88 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/int32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | // -- int32 Value 9 | type int32Value int32 10 | 11 | func newInt32Value(val int32, p *int32) *int32Value { 12 | *p = val 13 | return (*int32Value)(p) 14 | } 15 | 16 | func (i *int32Value) Set(s string) error { 17 | v, err := strconv.ParseInt(s, 0, 32) 18 | *i = int32Value(v) 19 | return err 20 | } 21 | 22 | func (i *int32Value) Type() string { 23 | return "int32" 24 | } 25 | 26 | func (i *int32Value) String() string { return fmt.Sprintf("%v", *i) } 27 | 28 | func int32Conv(sval string) (interface{}, error) { 29 | v, err := strconv.ParseInt(sval, 0, 32) 30 | if err != nil { 31 | return 0, err 32 | } 33 | return int32(v), nil 34 | } 35 | 36 | // GetInt32 return the int32 value of a flag with the given name 37 | func (f *FlagSet) GetInt32(name string) (int32, error) { 38 | val, err := f.getFlagType(name, "int32", int32Conv) 39 | if err != nil { 40 | return 0, err 41 | } 42 | return val.(int32), nil 43 | } 44 | 45 | // Int32Var defines an int32 flag with specified name, default value, and usage string. 46 | // The argument p points to an int32 variable in which to store the value of the flag. 47 | func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string) { 48 | f.VarP(newInt32Value(value, p), name, "", usage) 49 | } 50 | 51 | // Like Int32Var, but accepts a shorthand letter that can be used after a single dash. 52 | func (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage string) { 53 | f.VarP(newInt32Value(value, p), name, shorthand, usage) 54 | } 55 | 56 | // Int32Var defines an int32 flag with specified name, default value, and usage string. 57 | // The argument p points to an int32 variable in which to store the value of the flag. 58 | func Int32Var(p *int32, name string, value int32, usage string) { 59 | CommandLine.VarP(newInt32Value(value, p), name, "", usage) 60 | } 61 | 62 | // Like Int32Var, but accepts a shorthand letter that can be used after a single dash. 63 | func Int32VarP(p *int32, name, shorthand string, value int32, usage string) { 64 | CommandLine.VarP(newInt32Value(value, p), name, shorthand, usage) 65 | } 66 | 67 | // Int32 defines an int32 flag with specified name, default value, and usage string. 68 | // The return value is the address of an int32 variable that stores the value of the flag. 69 | func (f *FlagSet) Int32(name string, value int32, usage string) *int32 { 70 | p := new(int32) 71 | f.Int32VarP(p, name, "", value, usage) 72 | return p 73 | } 74 | 75 | // Like Int32, but accepts a shorthand letter that can be used after a single dash. 76 | func (f *FlagSet) Int32P(name, shorthand string, value int32, usage string) *int32 { 77 | p := new(int32) 78 | f.Int32VarP(p, name, shorthand, value, usage) 79 | return p 80 | } 81 | 82 | // Int32 defines an int32 flag with specified name, default value, and usage string. 83 | // The return value is the address of an int32 variable that stores the value of the flag. 84 | func Int32(name string, value int32, usage string) *int32 { 85 | return CommandLine.Int32P(name, "", value, usage) 86 | } 87 | 88 | // Like Int32, but accepts a shorthand letter that can be used after a single dash. 89 | func Int32P(name, shorthand string, value int32, usage string) *int32 { 90 | return CommandLine.Int32P(name, shorthand, value, usage) 91 | } 92 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/int64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | // -- int64 Value 9 | type int64Value int64 10 | 11 | func newInt64Value(val int64, p *int64) *int64Value { 12 | *p = val 13 | return (*int64Value)(p) 14 | } 15 | 16 | func (i *int64Value) Set(s string) error { 17 | v, err := strconv.ParseInt(s, 0, 64) 18 | *i = int64Value(v) 19 | return err 20 | } 21 | 22 | func (i *int64Value) Type() string { 23 | return "int64" 24 | } 25 | 26 | func (i *int64Value) String() string { return fmt.Sprintf("%v", *i) } 27 | 28 | func int64Conv(sval string) (interface{}, error) { 29 | return strconv.ParseInt(sval, 0, 64) 30 | } 31 | 32 | // GetInt64 return the int64 value of a flag with the given name 33 | func (f *FlagSet) GetInt64(name string) (int64, error) { 34 | val, err := f.getFlagType(name, "int64", int64Conv) 35 | if err != nil { 36 | return 0, err 37 | } 38 | return val.(int64), nil 39 | } 40 | 41 | // Int64Var defines an int64 flag with specified name, default value, and usage string. 42 | // The argument p points to an int64 variable in which to store the value of the flag. 43 | func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) { 44 | f.VarP(newInt64Value(value, p), name, "", usage) 45 | } 46 | 47 | // Like Int64Var, but accepts a shorthand letter that can be used after a single dash. 48 | func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string) { 49 | f.VarP(newInt64Value(value, p), name, shorthand, usage) 50 | } 51 | 52 | // Int64Var defines an int64 flag with specified name, default value, and usage string. 53 | // The argument p points to an int64 variable in which to store the value of the flag. 54 | func Int64Var(p *int64, name string, value int64, usage string) { 55 | CommandLine.VarP(newInt64Value(value, p), name, "", usage) 56 | } 57 | 58 | // Like Int64Var, but accepts a shorthand letter that can be used after a single dash. 59 | func Int64VarP(p *int64, name, shorthand string, value int64, usage string) { 60 | CommandLine.VarP(newInt64Value(value, p), name, shorthand, usage) 61 | } 62 | 63 | // Int64 defines an int64 flag with specified name, default value, and usage string. 64 | // The return value is the address of an int64 variable that stores the value of the flag. 65 | func (f *FlagSet) Int64(name string, value int64, usage string) *int64 { 66 | p := new(int64) 67 | f.Int64VarP(p, name, "", value, usage) 68 | return p 69 | } 70 | 71 | // Like Int64, but accepts a shorthand letter that can be used after a single dash. 72 | func (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64 { 73 | p := new(int64) 74 | f.Int64VarP(p, name, shorthand, value, usage) 75 | return p 76 | } 77 | 78 | // Int64 defines an int64 flag with specified name, default value, and usage string. 79 | // The return value is the address of an int64 variable that stores the value of the flag. 80 | func Int64(name string, value int64, usage string) *int64 { 81 | return CommandLine.Int64P(name, "", value, usage) 82 | } 83 | 84 | // Like Int64, but accepts a shorthand letter that can be used after a single dash. 85 | func Int64P(name, shorthand string, value int64, usage string) *int64 { 86 | return CommandLine.Int64P(name, shorthand, value, usage) 87 | } 88 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/int8.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | // -- int8 Value 9 | type int8Value int8 10 | 11 | func newInt8Value(val int8, p *int8) *int8Value { 12 | *p = val 13 | return (*int8Value)(p) 14 | } 15 | 16 | func (i *int8Value) Set(s string) error { 17 | v, err := strconv.ParseInt(s, 0, 8) 18 | *i = int8Value(v) 19 | return err 20 | } 21 | 22 | func (i *int8Value) Type() string { 23 | return "int8" 24 | } 25 | 26 | func (i *int8Value) String() string { return fmt.Sprintf("%v", *i) } 27 | 28 | func int8Conv(sval string) (interface{}, error) { 29 | v, err := strconv.ParseInt(sval, 0, 8) 30 | if err != nil { 31 | return 0, err 32 | } 33 | return int8(v), nil 34 | } 35 | 36 | // GetInt8 return the int8 value of a flag with the given name 37 | func (f *FlagSet) GetInt8(name string) (int8, error) { 38 | val, err := f.getFlagType(name, "int8", int8Conv) 39 | if err != nil { 40 | return 0, err 41 | } 42 | return val.(int8), nil 43 | } 44 | 45 | // Int8Var defines an int8 flag with specified name, default value, and usage string. 46 | // The argument p points to an int8 variable in which to store the value of the flag. 47 | func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string) { 48 | f.VarP(newInt8Value(value, p), name, "", usage) 49 | } 50 | 51 | // Like Int8Var, but accepts a shorthand letter that can be used after a single dash. 52 | func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string) { 53 | f.VarP(newInt8Value(value, p), name, shorthand, usage) 54 | } 55 | 56 | // Int8Var defines an int8 flag with specified name, default value, and usage string. 57 | // The argument p points to an int8 variable in which to store the value of the flag. 58 | func Int8Var(p *int8, name string, value int8, usage string) { 59 | CommandLine.VarP(newInt8Value(value, p), name, "", usage) 60 | } 61 | 62 | // Like Int8Var, but accepts a shorthand letter that can be used after a single dash. 63 | func Int8VarP(p *int8, name, shorthand string, value int8, usage string) { 64 | CommandLine.VarP(newInt8Value(value, p), name, shorthand, usage) 65 | } 66 | 67 | // Int8 defines an int8 flag with specified name, default value, and usage string. 68 | // The return value is the address of an int8 variable that stores the value of the flag. 69 | func (f *FlagSet) Int8(name string, value int8, usage string) *int8 { 70 | p := new(int8) 71 | f.Int8VarP(p, name, "", value, usage) 72 | return p 73 | } 74 | 75 | // Like Int8, but accepts a shorthand letter that can be used after a single dash. 76 | func (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8 { 77 | p := new(int8) 78 | f.Int8VarP(p, name, shorthand, value, usage) 79 | return p 80 | } 81 | 82 | // Int8 defines an int8 flag with specified name, default value, and usage string. 83 | // The return value is the address of an int8 variable that stores the value of the flag. 84 | func Int8(name string, value int8, usage string) *int8 { 85 | return CommandLine.Int8P(name, "", value, usage) 86 | } 87 | 88 | // Like Int8, but accepts a shorthand letter that can be used after a single dash. 89 | func Int8P(name, shorthand string, value int8, usage string) *int8 { 90 | return CommandLine.Int8P(name, shorthand, value, usage) 91 | } 92 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/int_slice.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | "strings" 7 | ) 8 | 9 | // -- intSlice Value 10 | type intSliceValue []int 11 | 12 | func newIntSliceValue(val []int, p *[]int) *intSliceValue { 13 | *p = val 14 | return (*intSliceValue)(p) 15 | } 16 | 17 | func (s *intSliceValue) Set(val string) error { 18 | ss := strings.Split(val, ",") 19 | out := make([]int, len(ss)) 20 | for i, d := range ss { 21 | var err error 22 | out[i], err = strconv.Atoi(d) 23 | if err != nil { 24 | return err 25 | } 26 | 27 | } 28 | *s = intSliceValue(out) 29 | return nil 30 | } 31 | 32 | func (s *intSliceValue) Type() string { 33 | return "intSlice" 34 | } 35 | 36 | func (s *intSliceValue) String() string { 37 | out := make([]string, len(*s)) 38 | for i, d := range *s { 39 | out[i] = fmt.Sprintf("%d", d) 40 | } 41 | return strings.Join(out, ",") 42 | } 43 | 44 | func intSliceConv(val string) (interface{}, error) { 45 | ss := strings.Split(val, ",") 46 | out := make([]int, len(ss)) 47 | for i, d := range ss { 48 | var err error 49 | out[i], err = strconv.Atoi(d) 50 | if err != nil { 51 | return nil, err 52 | } 53 | 54 | } 55 | return out, nil 56 | } 57 | 58 | // GetIntSlice return the []int value of a flag with the given name 59 | func (f *FlagSet) GetIntSlice(name string) ([]int, error) { 60 | val, err := f.getFlagType(name, "intSlice", intSliceConv) 61 | if err != nil { 62 | return []int{}, err 63 | } 64 | return val.([]int), nil 65 | } 66 | 67 | // IntSliceVar defines a intSlice flag with specified name, default value, and usage string. 68 | // The argument p points to a []int variable in which to store the value of the flag. 69 | func (f *FlagSet) IntSliceVar(p *[]int, name string, value []int, usage string) { 70 | f.VarP(newIntSliceValue(value, p), name, "", usage) 71 | } 72 | 73 | // Like IntSliceVar, but accepts a shorthand letter that can be used after a single dash. 74 | func (f *FlagSet) IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string) { 75 | f.VarP(newIntSliceValue(value, p), name, shorthand, usage) 76 | } 77 | 78 | // IntSliceVar defines a int[] flag with specified name, default value, and usage string. 79 | // The argument p points to a int[] variable in which to store the value of the flag. 80 | func IntSliceVar(p *[]int, name string, value []int, usage string) { 81 | CommandLine.VarP(newIntSliceValue(value, p), name, "", usage) 82 | } 83 | 84 | // Like IntSliceVar, but accepts a shorthand letter that can be used after a single dash. 85 | func IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string) { 86 | CommandLine.VarP(newIntSliceValue(value, p), name, shorthand, usage) 87 | } 88 | 89 | // IntSlice defines a []int flag with specified name, default value, and usage string. 90 | // The return value is the address of a []int variable that stores the value of the flag. 91 | func (f *FlagSet) IntSlice(name string, value []int, usage string) *[]int { 92 | p := make([]int, 0) 93 | f.IntSliceVarP(&p, name, "", value, usage) 94 | return &p 95 | } 96 | 97 | // Like IntSlice, but accepts a shorthand letter that can be used after a single dash. 98 | func (f *FlagSet) IntSliceP(name, shorthand string, value []int, usage string) *[]int { 99 | p := make([]int, 0) 100 | f.IntSliceVarP(&p, name, shorthand, value, usage) 101 | return &p 102 | } 103 | 104 | // IntSlice defines a []int flag with specified name, default value, and usage string. 105 | // The return value is the address of a []int variable that stores the value of the flag. 106 | func IntSlice(name string, value []int, usage string) *[]int { 107 | return CommandLine.IntSliceP(name, "", value, usage) 108 | } 109 | 110 | // Like IntSlice, but accepts a shorthand letter that can be used after a single dash. 111 | func IntSliceP(name, shorthand string, value []int, usage string) *[]int { 112 | return CommandLine.IntSliceP(name, shorthand, value, usage) 113 | } 114 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/int_slice_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pflag 6 | 7 | import ( 8 | "fmt" 9 | "strconv" 10 | "strings" 11 | "testing" 12 | ) 13 | 14 | func setUpISFlagSet(isp *[]int) *FlagSet { 15 | f := NewFlagSet("test", ContinueOnError) 16 | f.IntSliceVar(isp, "is", []int{}, "Command seperated list!") 17 | return f 18 | } 19 | 20 | func TestIS(t *testing.T) { 21 | var is []int 22 | f := setUpISFlagSet(&is) 23 | 24 | vals := []string{"1", "2", "4", "3"} 25 | arg := fmt.Sprintf("--is=%s", strings.Join(vals, ",")) 26 | err := f.Parse([]string{arg}) 27 | if err != nil { 28 | t.Fatal("expected no error; got", err) 29 | } 30 | for i, v := range is { 31 | d, err := strconv.Atoi(vals[i]) 32 | if err != nil { 33 | t.Fatalf("got error: %v", err) 34 | } 35 | if d != v { 36 | t.Fatalf("expected is[%d] to be %s but got: %d", i, vals[i], v) 37 | } 38 | } 39 | getIS, err := f.GetIntSlice("is") 40 | for i, v := range getIS { 41 | d, err := strconv.Atoi(vals[i]) 42 | if err != nil { 43 | t.Fatalf("got error: %v", err) 44 | } 45 | if d != v { 46 | t.Fatalf("expected is[%d] to be %s but got: %d from GetIntSlice", i, vals[i], v) 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/ip.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | ) 7 | 8 | // -- net.IP value 9 | type ipValue net.IP 10 | 11 | func newIPValue(val net.IP, p *net.IP) *ipValue { 12 | *p = val 13 | return (*ipValue)(p) 14 | } 15 | 16 | func (i *ipValue) String() string { return net.IP(*i).String() } 17 | func (i *ipValue) Set(s string) error { 18 | ip := net.ParseIP(s) 19 | if ip == nil { 20 | return fmt.Errorf("failed to parse IP: %q", s) 21 | } 22 | *i = ipValue(ip) 23 | return nil 24 | } 25 | 26 | func (i *ipValue) Type() string { 27 | return "ip" 28 | } 29 | 30 | func ipConv(sval string) (interface{}, error) { 31 | ip := net.ParseIP(sval) 32 | if ip != nil { 33 | return ip, nil 34 | } 35 | return nil, fmt.Errorf("invalid string being converted to IP address: %s", sval) 36 | } 37 | 38 | // GetIP return the net.IP value of a flag with the given name 39 | func (f *FlagSet) GetIP(name string) (net.IP, error) { 40 | val, err := f.getFlagType(name, "ip", ipConv) 41 | if err != nil { 42 | return nil, err 43 | } 44 | return val.(net.IP), nil 45 | } 46 | 47 | // IPVar defines an net.IP flag with specified name, default value, and usage string. 48 | // The argument p points to an net.IP variable in which to store the value of the flag. 49 | func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string) { 50 | f.VarP(newIPValue(value, p), name, "", usage) 51 | } 52 | 53 | // Like IPVar, but accepts a shorthand letter that can be used after a single dash. 54 | func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { 55 | f.VarP(newIPValue(value, p), name, shorthand, usage) 56 | } 57 | 58 | // IPVar defines an net.IP flag with specified name, default value, and usage string. 59 | // The argument p points to an net.IP variable in which to store the value of the flag. 60 | func IPVar(p *net.IP, name string, value net.IP, usage string) { 61 | CommandLine.VarP(newIPValue(value, p), name, "", usage) 62 | } 63 | 64 | // Like IPVar, but accepts a shorthand letter that can be used after a single dash. 65 | func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { 66 | CommandLine.VarP(newIPValue(value, p), name, shorthand, usage) 67 | } 68 | 69 | // IP defines an net.IP flag with specified name, default value, and usage string. 70 | // The return value is the address of an net.IP variable that stores the value of the flag. 71 | func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP { 72 | p := new(net.IP) 73 | f.IPVarP(p, name, "", value, usage) 74 | return p 75 | } 76 | 77 | // Like IP, but accepts a shorthand letter that can be used after a single dash. 78 | func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP { 79 | p := new(net.IP) 80 | f.IPVarP(p, name, shorthand, value, usage) 81 | return p 82 | } 83 | 84 | // IP defines an net.IP flag with specified name, default value, and usage string. 85 | // The return value is the address of an net.IP variable that stores the value of the flag. 86 | func IP(name string, value net.IP, usage string) *net.IP { 87 | return CommandLine.IPP(name, "", value, usage) 88 | } 89 | 90 | // Like IP, but accepts a shorthand letter that can be used after a single dash. 91 | func IPP(name, shorthand string, value net.IP, usage string) *net.IP { 92 | return CommandLine.IPP(name, shorthand, value, usage) 93 | } 94 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/ipmask.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strconv" 7 | ) 8 | 9 | // -- net.IPMask value 10 | type ipMaskValue net.IPMask 11 | 12 | func newIPMaskValue(val net.IPMask, p *net.IPMask) *ipMaskValue { 13 | *p = val 14 | return (*ipMaskValue)(p) 15 | } 16 | 17 | func (i *ipMaskValue) String() string { return net.IPMask(*i).String() } 18 | func (i *ipMaskValue) Set(s string) error { 19 | ip := ParseIPv4Mask(s) 20 | if ip == nil { 21 | return fmt.Errorf("failed to parse IP mask: %q", s) 22 | } 23 | *i = ipMaskValue(ip) 24 | return nil 25 | } 26 | 27 | func (i *ipMaskValue) Type() string { 28 | return "ipMask" 29 | } 30 | 31 | // Parse IPv4 netmask written in IP form (e.g. 255.255.255.0). 32 | // This function should really belong to the net package. 33 | func ParseIPv4Mask(s string) net.IPMask { 34 | mask := net.ParseIP(s) 35 | if mask == nil { 36 | if len(s) != 8 { 37 | return nil 38 | } 39 | // net.IPMask.String() actually outputs things like ffffff00 40 | // so write a horrible parser for that as well :-( 41 | m := []int{} 42 | for i := 0; i < 4; i++ { 43 | b := "0x" + s[2*i:2*i+2] 44 | d, err := strconv.ParseInt(b, 0, 0) 45 | if err != nil { 46 | return nil 47 | } 48 | m = append(m, int(d)) 49 | } 50 | s := fmt.Sprintf("%d.%d.%d.%d", m[0], m[1], m[2], m[3]) 51 | mask = net.ParseIP(s) 52 | if mask == nil { 53 | return nil 54 | } 55 | } 56 | return net.IPv4Mask(mask[12], mask[13], mask[14], mask[15]) 57 | } 58 | 59 | func parseIPv4Mask(sval string) (interface{}, error) { 60 | mask := ParseIPv4Mask(sval) 61 | if mask == nil { 62 | return nil, fmt.Errorf("unable to parse %s as net.IPMask", sval) 63 | } 64 | return mask, nil 65 | } 66 | 67 | // GetIPv4Mask return the net.IPv4Mask value of a flag with the given name 68 | func (f *FlagSet) GetIPv4Mask(name string) (net.IPMask, error) { 69 | val, err := f.getFlagType(name, "ipMask", parseIPv4Mask) 70 | if err != nil { 71 | return nil, err 72 | } 73 | return val.(net.IPMask), nil 74 | } 75 | 76 | // IPMaskVar defines an net.IPMask flag with specified name, default value, and usage string. 77 | // The argument p points to an net.IPMask variable in which to store the value of the flag. 78 | func (f *FlagSet) IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string) { 79 | f.VarP(newIPMaskValue(value, p), name, "", usage) 80 | } 81 | 82 | // Like IPMaskVar, but accepts a shorthand letter that can be used after a single dash. 83 | func (f *FlagSet) IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string) { 84 | f.VarP(newIPMaskValue(value, p), name, shorthand, usage) 85 | } 86 | 87 | // IPMaskVar defines an net.IPMask flag with specified name, default value, and usage string. 88 | // The argument p points to an net.IPMask variable in which to store the value of the flag. 89 | func IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string) { 90 | CommandLine.VarP(newIPMaskValue(value, p), name, "", usage) 91 | } 92 | 93 | // Like IPMaskVar, but accepts a shorthand letter that can be used after a single dash. 94 | func IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string) { 95 | CommandLine.VarP(newIPMaskValue(value, p), name, shorthand, usage) 96 | } 97 | 98 | // IPMask defines an net.IPMask flag with specified name, default value, and usage string. 99 | // The return value is the address of an net.IPMask variable that stores the value of the flag. 100 | func (f *FlagSet) IPMask(name string, value net.IPMask, usage string) *net.IPMask { 101 | p := new(net.IPMask) 102 | f.IPMaskVarP(p, name, "", value, usage) 103 | return p 104 | } 105 | 106 | // Like IPMask, but accepts a shorthand letter that can be used after a single dash. 107 | func (f *FlagSet) IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask { 108 | p := new(net.IPMask) 109 | f.IPMaskVarP(p, name, shorthand, value, usage) 110 | return p 111 | } 112 | 113 | // IPMask defines an net.IPMask flag with specified name, default value, and usage string. 114 | // The return value is the address of an net.IPMask variable that stores the value of the flag. 115 | func IPMask(name string, value net.IPMask, usage string) *net.IPMask { 116 | return CommandLine.IPMaskP(name, "", value, usage) 117 | } 118 | 119 | // Like IP, but accepts a shorthand letter that can be used after a single dash. 120 | func IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask { 121 | return CommandLine.IPMaskP(name, shorthand, value, usage) 122 | } 123 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/string.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "fmt" 4 | 5 | // -- string Value 6 | type stringValue string 7 | 8 | func newStringValue(val string, p *string) *stringValue { 9 | *p = val 10 | return (*stringValue)(p) 11 | } 12 | 13 | func (s *stringValue) Set(val string) error { 14 | *s = stringValue(val) 15 | return nil 16 | } 17 | func (s *stringValue) Type() string { 18 | return "string" 19 | } 20 | 21 | func (s *stringValue) String() string { return fmt.Sprintf("%s", *s) } 22 | 23 | func stringConv(sval string) (interface{}, error) { 24 | return sval, nil 25 | } 26 | 27 | // GetString return the string value of a flag with the given name 28 | func (f *FlagSet) GetString(name string) (string, error) { 29 | val, err := f.getFlagType(name, "string", stringConv) 30 | if err != nil { 31 | return "", err 32 | } 33 | return val.(string), nil 34 | } 35 | 36 | // StringVar defines a string flag with specified name, default value, and usage string. 37 | // The argument p points to a string variable in which to store the value of the flag. 38 | func (f *FlagSet) StringVar(p *string, name string, value string, usage string) { 39 | f.VarP(newStringValue(value, p), name, "", usage) 40 | } 41 | 42 | // Like StringVar, but accepts a shorthand letter that can be used after a single dash. 43 | func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string) { 44 | f.VarP(newStringValue(value, p), name, shorthand, usage) 45 | } 46 | 47 | // StringVar defines a string flag with specified name, default value, and usage string. 48 | // The argument p points to a string variable in which to store the value of the flag. 49 | func StringVar(p *string, name string, value string, usage string) { 50 | CommandLine.VarP(newStringValue(value, p), name, "", usage) 51 | } 52 | 53 | // Like StringVar, but accepts a shorthand letter that can be used after a single dash. 54 | func StringVarP(p *string, name, shorthand string, value string, usage string) { 55 | CommandLine.VarP(newStringValue(value, p), name, shorthand, usage) 56 | } 57 | 58 | // String defines a string flag with specified name, default value, and usage string. 59 | // The return value is the address of a string variable that stores the value of the flag. 60 | func (f *FlagSet) String(name string, value string, usage string) *string { 61 | p := new(string) 62 | f.StringVarP(p, name, "", value, usage) 63 | return p 64 | } 65 | 66 | // Like String, but accepts a shorthand letter that can be used after a single dash. 67 | func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string { 68 | p := new(string) 69 | f.StringVarP(p, name, shorthand, value, usage) 70 | return p 71 | } 72 | 73 | // String defines a string flag with specified name, default value, and usage string. 74 | // The return value is the address of a string variable that stores the value of the flag. 75 | func String(name string, value string, usage string) *string { 76 | return CommandLine.StringP(name, "", value, usage) 77 | } 78 | 79 | // Like String, but accepts a shorthand letter that can be used after a single dash. 80 | func StringP(name, shorthand string, value string, usage string) *string { 81 | return CommandLine.StringP(name, shorthand, value, usage) 82 | } 83 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/string_slice.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | // -- stringSlice Value 8 | type stringSliceValue []string 9 | 10 | func newStringSliceValue(val []string, p *[]string) *stringSliceValue { 11 | *p = val 12 | return (*stringSliceValue)(p) 13 | } 14 | 15 | func (s *stringSliceValue) Set(val string) error { 16 | v := strings.Split(val, ",") 17 | *s = stringSliceValue(v) 18 | return nil 19 | } 20 | func (s *stringSliceValue) Type() string { 21 | return "stringSlice" 22 | } 23 | 24 | func (s *stringSliceValue) String() string { return strings.Join(*s, ",") } 25 | 26 | func stringSliceConv(sval string) (interface{}, error) { 27 | v := strings.Split(sval, ",") 28 | return v, nil 29 | } 30 | 31 | // GetStringSlice return the []string value of a flag with the given name 32 | func (f *FlagSet) GetStringSlice(name string) ([]string, error) { 33 | val, err := f.getFlagType(name, "stringSlice", stringSliceConv) 34 | if err != nil { 35 | return []string{}, err 36 | } 37 | return val.([]string), nil 38 | } 39 | 40 | // StringSliceVar defines a string flag with specified name, default value, and usage string. 41 | // The argument p points to a []string variable in which to store the value of the flag. 42 | func (f *FlagSet) StringSliceVar(p *[]string, name string, value []string, usage string) { 43 | f.VarP(newStringSliceValue(value, p), name, "", usage) 44 | } 45 | 46 | // Like StringSliceVar, but accepts a shorthand letter that can be used after a single dash. 47 | func (f *FlagSet) StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string) { 48 | f.VarP(newStringSliceValue(value, p), name, shorthand, usage) 49 | } 50 | 51 | // StringSliceVar defines a string flag with specified name, default value, and usage string. 52 | // The argument p points to a []string variable in which to store the value of the flag. 53 | func StringSliceVar(p *[]string, name string, value []string, usage string) { 54 | CommandLine.VarP(newStringSliceValue(value, p), name, "", usage) 55 | } 56 | 57 | // Like StringSliceVar, but accepts a shorthand letter that can be used after a single dash. 58 | func StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string) { 59 | CommandLine.VarP(newStringSliceValue(value, p), name, shorthand, usage) 60 | } 61 | 62 | // StringSlice defines a string flag with specified name, default value, and usage string. 63 | // The return value is the address of a []string variable that stores the value of the flag. 64 | func (f *FlagSet) StringSlice(name string, value []string, usage string) *[]string { 65 | p := make([]string, 0) 66 | f.StringSliceVarP(&p, name, "", value, usage) 67 | return &p 68 | } 69 | 70 | // Like StringSlice, but accepts a shorthand letter that can be used after a single dash. 71 | func (f *FlagSet) StringSliceP(name, shorthand string, value []string, usage string) *[]string { 72 | p := make([]string, 0) 73 | f.StringSliceVarP(&p, name, shorthand, value, usage) 74 | return &p 75 | } 76 | 77 | // StringSlice defines a string flag with specified name, default value, and usage string. 78 | // The return value is the address of a []string variable that stores the value of the flag. 79 | func StringSlice(name string, value []string, usage string) *[]string { 80 | return CommandLine.StringSliceP(name, "", value, usage) 81 | } 82 | 83 | // Like StringSlice, but accepts a shorthand letter that can be used after a single dash. 84 | func StringSliceP(name, shorthand string, value []string, usage string) *[]string { 85 | return CommandLine.StringSliceP(name, shorthand, value, usage) 86 | } 87 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/string_slice_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pflag 6 | 7 | import ( 8 | "fmt" 9 | "strings" 10 | "testing" 11 | ) 12 | 13 | func setUpSSFlagSet(ssp *[]string) *FlagSet { 14 | f := NewFlagSet("test", ContinueOnError) 15 | f.StringSliceVar(ssp, "ss", []string{}, "Command seperated list!") 16 | return f 17 | } 18 | 19 | func TestSS(t *testing.T) { 20 | var ss []string 21 | f := setUpSSFlagSet(&ss) 22 | 23 | vals := []string{"one", "two", "4", "3"} 24 | arg := fmt.Sprintf("--ss=%s", strings.Join(vals, ",")) 25 | err := f.Parse([]string{arg}) 26 | if err != nil { 27 | t.Fatal("expected no error; got", err) 28 | } 29 | for i, v := range ss { 30 | if vals[i] != v { 31 | t.Fatal("expected ss[%d] to be %s but got: %s", i, vals[i], v) 32 | } 33 | } 34 | 35 | getSS, err := f.GetStringSlice("ss") 36 | if err != nil { 37 | t.Fatal("got an error from GetStringSlice(): %v", err) 38 | } 39 | for i, v := range getSS { 40 | if vals[i] != v { 41 | t.Fatal("expected ss[%d] to be %s from GetStringSlice but got: %s", i, vals[i], v) 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/uint.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | // -- uint Value 9 | type uintValue uint 10 | 11 | func newUintValue(val uint, p *uint) *uintValue { 12 | *p = val 13 | return (*uintValue)(p) 14 | } 15 | 16 | func (i *uintValue) Set(s string) error { 17 | v, err := strconv.ParseUint(s, 0, 64) 18 | *i = uintValue(v) 19 | return err 20 | } 21 | 22 | func (i *uintValue) Type() string { 23 | return "uint" 24 | } 25 | 26 | func (i *uintValue) String() string { return fmt.Sprintf("%v", *i) } 27 | 28 | func uintConv(sval string) (interface{}, error) { 29 | v, err := strconv.ParseUint(sval, 0, 0) 30 | if err != nil { 31 | return 0, err 32 | } 33 | return uint(v), nil 34 | } 35 | 36 | // GetUint return the uint value of a flag with the given name 37 | func (f *FlagSet) GetUint(name string) (uint, error) { 38 | val, err := f.getFlagType(name, "uint", uintConv) 39 | if err != nil { 40 | return 0, err 41 | } 42 | return val.(uint), nil 43 | } 44 | 45 | // UintVar defines a uint flag with specified name, default value, and usage string. 46 | // The argument p points to a uint variable in which to store the value of the flag. 47 | func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string) { 48 | f.VarP(newUintValue(value, p), name, "", usage) 49 | } 50 | 51 | // Like UintVar, but accepts a shorthand letter that can be used after a single dash. 52 | func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string) { 53 | f.VarP(newUintValue(value, p), name, shorthand, usage) 54 | } 55 | 56 | // UintVar defines a uint flag with specified name, default value, and usage string. 57 | // The argument p points to a uint variable in which to store the value of the flag. 58 | func UintVar(p *uint, name string, value uint, usage string) { 59 | CommandLine.VarP(newUintValue(value, p), name, "", usage) 60 | } 61 | 62 | // Like UintVar, but accepts a shorthand letter that can be used after a single dash. 63 | func UintVarP(p *uint, name, shorthand string, value uint, usage string) { 64 | CommandLine.VarP(newUintValue(value, p), name, shorthand, usage) 65 | } 66 | 67 | // Uint defines a uint flag with specified name, default value, and usage string. 68 | // The return value is the address of a uint variable that stores the value of the flag. 69 | func (f *FlagSet) Uint(name string, value uint, usage string) *uint { 70 | p := new(uint) 71 | f.UintVarP(p, name, "", value, usage) 72 | return p 73 | } 74 | 75 | // Like Uint, but accepts a shorthand letter that can be used after a single dash. 76 | func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint { 77 | p := new(uint) 78 | f.UintVarP(p, name, shorthand, value, usage) 79 | return p 80 | } 81 | 82 | // Uint defines a uint flag with specified name, default value, and usage string. 83 | // The return value is the address of a uint variable that stores the value of the flag. 84 | func Uint(name string, value uint, usage string) *uint { 85 | return CommandLine.UintP(name, "", value, usage) 86 | } 87 | 88 | // Like Uint, but accepts a shorthand letter that can be used after a single dash. 89 | func UintP(name, shorthand string, value uint, usage string) *uint { 90 | return CommandLine.UintP(name, shorthand, value, usage) 91 | } 92 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/uint16.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | // -- uint16 value 9 | type uint16Value uint16 10 | 11 | func newUint16Value(val uint16, p *uint16) *uint16Value { 12 | *p = val 13 | return (*uint16Value)(p) 14 | } 15 | func (i *uint16Value) String() string { return fmt.Sprintf("%d", *i) } 16 | func (i *uint16Value) Set(s string) error { 17 | v, err := strconv.ParseUint(s, 0, 16) 18 | *i = uint16Value(v) 19 | return err 20 | } 21 | 22 | func (i *uint16Value) Type() string { 23 | return "uint16" 24 | } 25 | 26 | func uint16Conv(sval string) (interface{}, error) { 27 | v, err := strconv.ParseUint(sval, 0, 16) 28 | if err != nil { 29 | return 0, err 30 | } 31 | return uint16(v), nil 32 | } 33 | 34 | // GetUint16 return the uint16 value of a flag with the given name 35 | func (f *FlagSet) GetUint16(name string) (uint16, error) { 36 | val, err := f.getFlagType(name, "uint16", uint16Conv) 37 | if err != nil { 38 | return 0, err 39 | } 40 | return val.(uint16), nil 41 | } 42 | 43 | // Uint16Var defines a uint flag with specified name, default value, and usage string. 44 | // The argument p points to a uint variable in which to store the value of the flag. 45 | func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string) { 46 | f.VarP(newUint16Value(value, p), name, "", usage) 47 | } 48 | 49 | // Like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 50 | func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { 51 | f.VarP(newUint16Value(value, p), name, shorthand, usage) 52 | } 53 | 54 | // Uint16Var defines a uint flag with specified name, default value, and usage string. 55 | // The argument p points to a uint variable in which to store the value of the flag. 56 | func Uint16Var(p *uint16, name string, value uint16, usage string) { 57 | CommandLine.VarP(newUint16Value(value, p), name, "", usage) 58 | } 59 | 60 | // Like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 61 | func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { 62 | CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage) 63 | } 64 | 65 | // Uint16 defines a uint flag with specified name, default value, and usage string. 66 | // The return value is the address of a uint variable that stores the value of the flag. 67 | func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 { 68 | p := new(uint16) 69 | f.Uint16VarP(p, name, "", value, usage) 70 | return p 71 | } 72 | 73 | // Like Uint16, but accepts a shorthand letter that can be used after a single dash. 74 | func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16 { 75 | p := new(uint16) 76 | f.Uint16VarP(p, name, shorthand, value, usage) 77 | return p 78 | } 79 | 80 | // Uint16 defines a uint flag with specified name, default value, and usage string. 81 | // The return value is the address of a uint variable that stores the value of the flag. 82 | func Uint16(name string, value uint16, usage string) *uint16 { 83 | return CommandLine.Uint16P(name, "", value, usage) 84 | } 85 | 86 | // Like Uint16, but accepts a shorthand letter that can be used after a single dash. 87 | func Uint16P(name, shorthand string, value uint16, usage string) *uint16 { 88 | return CommandLine.Uint16P(name, shorthand, value, usage) 89 | } 90 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/uint32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | // -- uint16 value 9 | type uint32Value uint32 10 | 11 | func newUint32Value(val uint32, p *uint32) *uint32Value { 12 | *p = val 13 | return (*uint32Value)(p) 14 | } 15 | func (i *uint32Value) String() string { return fmt.Sprintf("%d", *i) } 16 | func (i *uint32Value) Set(s string) error { 17 | v, err := strconv.ParseUint(s, 0, 32) 18 | *i = uint32Value(v) 19 | return err 20 | } 21 | 22 | func (i *uint32Value) Type() string { 23 | return "uint32" 24 | } 25 | 26 | func uint32Conv(sval string) (interface{}, error) { 27 | v, err := strconv.ParseUint(sval, 0, 32) 28 | if err != nil { 29 | return 0, err 30 | } 31 | return uint32(v), nil 32 | } 33 | 34 | // GetUint32 return the uint32 value of a flag with the given name 35 | func (f *FlagSet) GetUint32(name string) (uint32, error) { 36 | val, err := f.getFlagType(name, "uint32", uint32Conv) 37 | if err != nil { 38 | return 0, err 39 | } 40 | return val.(uint32), nil 41 | } 42 | 43 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string. 44 | // The argument p points to a uint32 variable in which to store the value of the flag. 45 | func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string) { 46 | f.VarP(newUint32Value(value, p), name, "", usage) 47 | } 48 | 49 | // Like Uint32Var, but accepts a shorthand letter that can be used after a single dash. 50 | func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { 51 | f.VarP(newUint32Value(value, p), name, shorthand, usage) 52 | } 53 | 54 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string. 55 | // The argument p points to a uint32 variable in which to store the value of the flag. 56 | func Uint32Var(p *uint32, name string, value uint32, usage string) { 57 | CommandLine.VarP(newUint32Value(value, p), name, "", usage) 58 | } 59 | 60 | // Like Uint32Var, but accepts a shorthand letter that can be used after a single dash. 61 | func Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { 62 | CommandLine.VarP(newUint32Value(value, p), name, shorthand, usage) 63 | } 64 | 65 | // Uint32 defines a uint32 flag with specified name, default value, and usage string. 66 | // The return value is the address of a uint32 variable that stores the value of the flag. 67 | func (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32 { 68 | p := new(uint32) 69 | f.Uint32VarP(p, name, "", value, usage) 70 | return p 71 | } 72 | 73 | // Like Uint32, but accepts a shorthand letter that can be used after a single dash. 74 | func (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32 { 75 | p := new(uint32) 76 | f.Uint32VarP(p, name, shorthand, value, usage) 77 | return p 78 | } 79 | 80 | // Uint32 defines a uint32 flag with specified name, default value, and usage string. 81 | // The return value is the address of a uint32 variable that stores the value of the flag. 82 | func Uint32(name string, value uint32, usage string) *uint32 { 83 | return CommandLine.Uint32P(name, "", value, usage) 84 | } 85 | 86 | // Like Uint32, but accepts a shorthand letter that can be used after a single dash. 87 | func Uint32P(name, shorthand string, value uint32, usage string) *uint32 { 88 | return CommandLine.Uint32P(name, shorthand, value, usage) 89 | } 90 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/uint64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | // -- uint64 Value 9 | type uint64Value uint64 10 | 11 | func newUint64Value(val uint64, p *uint64) *uint64Value { 12 | *p = val 13 | return (*uint64Value)(p) 14 | } 15 | 16 | func (i *uint64Value) Set(s string) error { 17 | v, err := strconv.ParseUint(s, 0, 64) 18 | *i = uint64Value(v) 19 | return err 20 | } 21 | 22 | func (i *uint64Value) Type() string { 23 | return "uint64" 24 | } 25 | 26 | func (i *uint64Value) String() string { return fmt.Sprintf("%v", *i) } 27 | 28 | func uint64Conv(sval string) (interface{}, error) { 29 | v, err := strconv.ParseUint(sval, 0, 64) 30 | if err != nil { 31 | return 0, err 32 | } 33 | return uint64(v), nil 34 | } 35 | 36 | // GetUint64 return the uint64 value of a flag with the given name 37 | func (f *FlagSet) GetUint64(name string) (uint64, error) { 38 | val, err := f.getFlagType(name, "uint64", uint64Conv) 39 | if err != nil { 40 | return 0, err 41 | } 42 | return val.(uint64), nil 43 | } 44 | 45 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string. 46 | // The argument p points to a uint64 variable in which to store the value of the flag. 47 | func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string) { 48 | f.VarP(newUint64Value(value, p), name, "", usage) 49 | } 50 | 51 | // Like Uint64Var, but accepts a shorthand letter that can be used after a single dash. 52 | func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { 53 | f.VarP(newUint64Value(value, p), name, shorthand, usage) 54 | } 55 | 56 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string. 57 | // The argument p points to a uint64 variable in which to store the value of the flag. 58 | func Uint64Var(p *uint64, name string, value uint64, usage string) { 59 | CommandLine.VarP(newUint64Value(value, p), name, "", usage) 60 | } 61 | 62 | // Like Uint64Var, but accepts a shorthand letter that can be used after a single dash. 63 | func Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { 64 | CommandLine.VarP(newUint64Value(value, p), name, shorthand, usage) 65 | } 66 | 67 | // Uint64 defines a uint64 flag with specified name, default value, and usage string. 68 | // The return value is the address of a uint64 variable that stores the value of the flag. 69 | func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64 { 70 | p := new(uint64) 71 | f.Uint64VarP(p, name, "", value, usage) 72 | return p 73 | } 74 | 75 | // Like Uint64, but accepts a shorthand letter that can be used after a single dash. 76 | func (f *FlagSet) Uint64P(name, shorthand string, value uint64, usage string) *uint64 { 77 | p := new(uint64) 78 | f.Uint64VarP(p, name, shorthand, value, usage) 79 | return p 80 | } 81 | 82 | // Uint64 defines a uint64 flag with specified name, default value, and usage string. 83 | // The return value is the address of a uint64 variable that stores the value of the flag. 84 | func Uint64(name string, value uint64, usage string) *uint64 { 85 | return CommandLine.Uint64P(name, "", value, usage) 86 | } 87 | 88 | // Like Uint64, but accepts a shorthand letter that can be used after a single dash. 89 | func Uint64P(name, shorthand string, value uint64, usage string) *uint64 { 90 | return CommandLine.Uint64P(name, shorthand, value, usage) 91 | } 92 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/spf13/pflag/uint8.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | // -- uint8 Value 9 | type uint8Value uint8 10 | 11 | func newUint8Value(val uint8, p *uint8) *uint8Value { 12 | *p = val 13 | return (*uint8Value)(p) 14 | } 15 | 16 | func (i *uint8Value) Set(s string) error { 17 | v, err := strconv.ParseUint(s, 0, 8) 18 | *i = uint8Value(v) 19 | return err 20 | } 21 | 22 | func (i *uint8Value) Type() string { 23 | return "uint8" 24 | } 25 | 26 | func (i *uint8Value) String() string { return fmt.Sprintf("%v", *i) } 27 | 28 | func uint8Conv(sval string) (interface{}, error) { 29 | v, err := strconv.ParseUint(sval, 0, 8) 30 | if err != nil { 31 | return 0, err 32 | } 33 | return uint8(v), nil 34 | } 35 | 36 | // GetUint8 return the uint8 value of a flag with the given name 37 | func (f *FlagSet) GetUint8(name string) (uint8, error) { 38 | val, err := f.getFlagType(name, "uint8", uint8Conv) 39 | if err != nil { 40 | return 0, err 41 | } 42 | return val.(uint8), nil 43 | } 44 | 45 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string. 46 | // The argument p points to a uint8 variable in which to store the value of the flag. 47 | func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string) { 48 | f.VarP(newUint8Value(value, p), name, "", usage) 49 | } 50 | 51 | // Like Uint8Var, but accepts a shorthand letter that can be used after a single dash. 52 | func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { 53 | f.VarP(newUint8Value(value, p), name, shorthand, usage) 54 | } 55 | 56 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string. 57 | // The argument p points to a uint8 variable in which to store the value of the flag. 58 | func Uint8Var(p *uint8, name string, value uint8, usage string) { 59 | CommandLine.VarP(newUint8Value(value, p), name, "", usage) 60 | } 61 | 62 | // Like Uint8Var, but accepts a shorthand letter that can be used after a single dash. 63 | func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { 64 | CommandLine.VarP(newUint8Value(value, p), name, shorthand, usage) 65 | } 66 | 67 | // Uint8 defines a uint8 flag with specified name, default value, and usage string. 68 | // The return value is the address of a uint8 variable that stores the value of the flag. 69 | func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8 { 70 | p := new(uint8) 71 | f.Uint8VarP(p, name, "", value, usage) 72 | return p 73 | } 74 | 75 | // Like Uint8, but accepts a shorthand letter that can be used after a single dash. 76 | func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8 { 77 | p := new(uint8) 78 | f.Uint8VarP(p, name, shorthand, value, usage) 79 | return p 80 | } 81 | 82 | // Uint8 defines a uint8 flag with specified name, default value, and usage string. 83 | // The return value is the address of a uint8 variable that stores the value of the flag. 84 | func Uint8(name string, value uint8, usage string) *uint8 { 85 | return CommandLine.Uint8P(name, "", value, usage) 86 | } 87 | 88 | // Like Uint8, but accepts a shorthand letter that can be used after a single dash. 89 | func Uint8P(name, shorthand string, value uint8, usage string) *uint8 { 90 | return CommandLine.Uint8P(name, shorthand, value, usage) 91 | } 92 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/speter.net/go/exp/math/dec/inf/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Péter Surányi. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | ---------------------------------------------------------------------- 27 | Portions of inf.Dec's source code have been derived from Go and are 28 | covered by the following license: 29 | ---------------------------------------------------------------------- 30 | 31 | Copyright (c) 2009 The Go Authors. All rights reserved. 32 | 33 | Redistribution and use in source and binary forms, with or without 34 | modification, are permitted provided that the following conditions are 35 | met: 36 | 37 | * Redistributions of source code must retain the above copyright 38 | notice, this list of conditions and the following disclaimer. 39 | * Redistributions in binary form must reproduce the above 40 | copyright notice, this list of conditions and the following disclaimer 41 | in the documentation and/or other materials provided with the 42 | distribution. 43 | * Neither the name of Google Inc. nor the names of its 44 | contributors may be used to endorse or promote products derived from 45 | this software without specific prior written permission. 46 | 47 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 48 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 49 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 50 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 51 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 52 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 53 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 54 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 55 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 56 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 57 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/speter.net/go/exp/math/dec/inf/benchmark_test.go: -------------------------------------------------------------------------------- 1 | package inf 2 | 3 | import ( 4 | "fmt" 5 | "math/big" 6 | "math/rand" 7 | "sync" 8 | "testing" 9 | ) 10 | 11 | const maxcap = 1024 * 1024 12 | const bits = 256 13 | const maxscale = 32 14 | 15 | var once sync.Once 16 | 17 | var decInput [][2]Dec 18 | var intInput [][2]big.Int 19 | 20 | var initBench = func() { 21 | decInput = make([][2]Dec, maxcap) 22 | intInput = make([][2]big.Int, maxcap) 23 | max := new(big.Int).Lsh(big.NewInt(1), bits) 24 | r := rand.New(rand.NewSource(0)) 25 | for i := 0; i < cap(decInput); i++ { 26 | decInput[i][0].SetUnscaledBig(new(big.Int).Rand(r, max)). 27 | SetScale(Scale(r.Int31n(int32(2*maxscale-1)) - int32(maxscale))) 28 | decInput[i][1].SetUnscaledBig(new(big.Int).Rand(r, max)). 29 | SetScale(Scale(r.Int31n(int32(2*maxscale-1)) - int32(maxscale))) 30 | } 31 | for i := 0; i < cap(intInput); i++ { 32 | intInput[i][0].Rand(r, max) 33 | intInput[i][1].Rand(r, max) 34 | } 35 | } 36 | 37 | func doBenchmarkDec1(b *testing.B, f func(z *Dec)) { 38 | once.Do(initBench) 39 | b.ResetTimer() 40 | b.StartTimer() 41 | for i := 0; i < b.N; i++ { 42 | f(&decInput[i%maxcap][0]) 43 | } 44 | } 45 | 46 | func doBenchmarkDec2(b *testing.B, f func(x, y *Dec)) { 47 | once.Do(initBench) 48 | b.ResetTimer() 49 | b.StartTimer() 50 | for i := 0; i < b.N; i++ { 51 | f(&decInput[i%maxcap][0], &decInput[i%maxcap][1]) 52 | } 53 | } 54 | 55 | func doBenchmarkInt1(b *testing.B, f func(z *big.Int)) { 56 | once.Do(initBench) 57 | b.ResetTimer() 58 | b.StartTimer() 59 | for i := 0; i < b.N; i++ { 60 | f(&intInput[i%maxcap][0]) 61 | } 62 | } 63 | 64 | func doBenchmarkInt2(b *testing.B, f func(x, y *big.Int)) { 65 | once.Do(initBench) 66 | b.ResetTimer() 67 | b.StartTimer() 68 | for i := 0; i < b.N; i++ { 69 | f(&intInput[i%maxcap][0], &intInput[i%maxcap][1]) 70 | } 71 | } 72 | 73 | func Benchmark_Dec_String(b *testing.B) { 74 | doBenchmarkDec1(b, func(x *Dec) { 75 | x.String() 76 | }) 77 | } 78 | 79 | func Benchmark_Dec_StringScan(b *testing.B) { 80 | doBenchmarkDec1(b, func(x *Dec) { 81 | s := x.String() 82 | d := new(Dec) 83 | fmt.Sscan(s, d) 84 | }) 85 | } 86 | 87 | func Benchmark_Dec_GobEncode(b *testing.B) { 88 | doBenchmarkDec1(b, func(x *Dec) { 89 | x.GobEncode() 90 | }) 91 | } 92 | 93 | func Benchmark_Dec_GobEnDecode(b *testing.B) { 94 | doBenchmarkDec1(b, func(x *Dec) { 95 | g, _ := x.GobEncode() 96 | new(Dec).GobDecode(g) 97 | }) 98 | } 99 | 100 | func Benchmark_Dec_Add(b *testing.B) { 101 | doBenchmarkDec2(b, func(x, y *Dec) { 102 | ys := y.Scale() 103 | y.SetScale(x.Scale()) 104 | _ = new(Dec).Add(x, y) 105 | y.SetScale(ys) 106 | }) 107 | } 108 | 109 | func Benchmark_Dec_AddMixed(b *testing.B) { 110 | doBenchmarkDec2(b, func(x, y *Dec) { 111 | _ = new(Dec).Add(x, y) 112 | }) 113 | } 114 | 115 | func Benchmark_Dec_Sub(b *testing.B) { 116 | doBenchmarkDec2(b, func(x, y *Dec) { 117 | ys := y.Scale() 118 | y.SetScale(x.Scale()) 119 | _ = new(Dec).Sub(x, y) 120 | y.SetScale(ys) 121 | }) 122 | } 123 | 124 | func Benchmark_Dec_SubMixed(b *testing.B) { 125 | doBenchmarkDec2(b, func(x, y *Dec) { 126 | _ = new(Dec).Sub(x, y) 127 | }) 128 | } 129 | 130 | func Benchmark_Dec_Mul(b *testing.B) { 131 | doBenchmarkDec2(b, func(x, y *Dec) { 132 | _ = new(Dec).Mul(x, y) 133 | }) 134 | } 135 | 136 | func Benchmark_Dec_Mul_QuoExact(b *testing.B) { 137 | doBenchmarkDec2(b, func(x, y *Dec) { 138 | v := new(Dec).Mul(x, y) 139 | _ = new(Dec).QuoExact(v, y) 140 | }) 141 | } 142 | 143 | func Benchmark_Dec_QuoRound_Fixed_Down(b *testing.B) { 144 | doBenchmarkDec2(b, func(x, y *Dec) { 145 | _ = new(Dec).QuoRound(x, y, 0, RoundDown) 146 | }) 147 | } 148 | 149 | func Benchmark_Dec_QuoRound_Fixed_HalfUp(b *testing.B) { 150 | doBenchmarkDec2(b, func(x, y *Dec) { 151 | _ = new(Dec).QuoRound(x, y, 0, RoundHalfUp) 152 | }) 153 | } 154 | 155 | func Benchmark_Int_String(b *testing.B) { 156 | doBenchmarkInt1(b, func(x *big.Int) { 157 | x.String() 158 | }) 159 | } 160 | 161 | func Benchmark_Int_StringScan(b *testing.B) { 162 | doBenchmarkInt1(b, func(x *big.Int) { 163 | s := x.String() 164 | d := new(big.Int) 165 | fmt.Sscan(s, d) 166 | }) 167 | } 168 | 169 | func Benchmark_Int_GobEncode(b *testing.B) { 170 | doBenchmarkInt1(b, func(x *big.Int) { 171 | x.GobEncode() 172 | }) 173 | } 174 | 175 | func Benchmark_Int_GobEnDecode(b *testing.B) { 176 | doBenchmarkInt1(b, func(x *big.Int) { 177 | g, _ := x.GobEncode() 178 | new(big.Int).GobDecode(g) 179 | }) 180 | } 181 | 182 | func Benchmark_Int_Add(b *testing.B) { 183 | doBenchmarkInt2(b, func(x, y *big.Int) { 184 | _ = new(big.Int).Add(x, y) 185 | }) 186 | } 187 | 188 | func Benchmark_Int_Sub(b *testing.B) { 189 | doBenchmarkInt2(b, func(x, y *big.Int) { 190 | _ = new(big.Int).Sub(x, y) 191 | }) 192 | } 193 | 194 | func Benchmark_Int_Mul(b *testing.B) { 195 | doBenchmarkInt2(b, func(x, y *big.Int) { 196 | _ = new(big.Int).Mul(x, y) 197 | }) 198 | } 199 | 200 | func Benchmark_Int_Quo(b *testing.B) { 201 | doBenchmarkInt2(b, func(x, y *big.Int) { 202 | _ = new(big.Int).Quo(x, y) 203 | }) 204 | } 205 | 206 | func Benchmark_Int_QuoRem(b *testing.B) { 207 | doBenchmarkInt2(b, func(x, y *big.Int) { 208 | _, _ = new(big.Int).QuoRem(x, y, new(big.Int)) 209 | }) 210 | } 211 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/speter.net/go/exp/math/dec/inf/dec_go1_2_test.go: -------------------------------------------------------------------------------- 1 | // +build go1.2 2 | 3 | package inf 4 | 5 | import ( 6 | "encoding" 7 | "encoding/json" 8 | "testing" 9 | ) 10 | 11 | var _ encoding.TextMarshaler = new(Dec) 12 | var _ encoding.TextUnmarshaler = new(Dec) 13 | 14 | type Obj struct { 15 | Val *Dec 16 | } 17 | 18 | func TestDecJsonMarshalUnmarshal(t *testing.T) { 19 | o := Obj{Val: NewDec(123, 2)} 20 | js, err := json.Marshal(o) 21 | if err != nil { 22 | t.Fatalf("json.Marshal(%v): got %v, want ok", o, err) 23 | } 24 | o2 := &Obj{} 25 | err = json.Unmarshal(js, o2) 26 | if err != nil { 27 | t.Fatalf("json.Unmarshal(%#q): got %v, want ok", js, err) 28 | } 29 | if o.Val.Scale() != o2.Val.Scale() || 30 | o.Val.UnscaledBig().Cmp(o2.Val.UnscaledBig()) != 0 { 31 | t.Fatalf("json.Unmarshal(json.Marshal(%v)): want %v, got %v", o, o, o2) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/speter.net/go/exp/math/dec/inf/dec_internal_test.go: -------------------------------------------------------------------------------- 1 | package inf 2 | 3 | import ( 4 | "math/big" 5 | "testing" 6 | ) 7 | 8 | var decQuoRemZZZ = []struct { 9 | z, x, y *Dec 10 | r *big.Rat 11 | srA, srB int 12 | }{ 13 | // basic examples 14 | {NewDec(1, 0), NewDec(2, 0), NewDec(2, 0), big.NewRat(0, 1), 0, 1}, 15 | {NewDec(15, 1), NewDec(3, 0), NewDec(2, 0), big.NewRat(0, 1), 0, 1}, 16 | {NewDec(1, 1), NewDec(1, 0), NewDec(10, 0), big.NewRat(0, 1), 0, 1}, 17 | {NewDec(0, 0), NewDec(2, 0), NewDec(3, 0), big.NewRat(2, 3), 1, 1}, 18 | {NewDec(0, 0), NewDec(2, 0), NewDec(6, 0), big.NewRat(1, 3), 1, 1}, 19 | {NewDec(1, 1), NewDec(2, 0), NewDec(12, 0), big.NewRat(2, 3), 1, 1}, 20 | 21 | // examples from the Go Language Specification 22 | {NewDec(1, 0), NewDec(5, 0), NewDec(3, 0), big.NewRat(2, 3), 1, 1}, 23 | {NewDec(-1, 0), NewDec(-5, 0), NewDec(3, 0), big.NewRat(-2, 3), -1, 1}, 24 | {NewDec(-1, 0), NewDec(5, 0), NewDec(-3, 0), big.NewRat(-2, 3), 1, -1}, 25 | {NewDec(1, 0), NewDec(-5, 0), NewDec(-3, 0), big.NewRat(2, 3), -1, -1}, 26 | } 27 | 28 | func TestDecQuoRem(t *testing.T) { 29 | for i, a := range decQuoRemZZZ { 30 | z, rA, rB := new(Dec), new(big.Int), new(big.Int) 31 | s := scaleQuoExact{}.Scale(a.x, a.y) 32 | z.quoRem(a.x, a.y, s, true, rA, rB) 33 | if a.z.Cmp(z) != 0 || a.r.Cmp(new(big.Rat).SetFrac(rA, rB)) != 0 { 34 | t.Errorf("#%d QuoRemZZZ got %v, %v, %v; expected %v, %v", i, z, rA, rB, a.z, a.r) 35 | } 36 | if a.srA != rA.Sign() || a.srB != rB.Sign() { 37 | t.Errorf("#%d QuoRemZZZ wrong signs, got %v, %v; expected %v, %v", i, rA.Sign(), rB.Sign(), a.srA, a.srB) 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/speter.net/go/exp/math/dec/inf/example_test.go: -------------------------------------------------------------------------------- 1 | package inf_test 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | ) 7 | 8 | import "github.com/klizhentas/deb2aci/Godeps/_workspace/src/speter.net/go/exp/math/dec/inf" 9 | 10 | func ExampleDec_SetString() { 11 | d := new(inf.Dec) 12 | d.SetString("012345.67890") // decimal; leading 0 ignored; trailing 0 kept 13 | fmt.Println(d) 14 | // Output: 12345.67890 15 | } 16 | 17 | func ExampleDec_Scan() { 18 | // The Scan function is rarely used directly; 19 | // the fmt package recognizes it as an implementation of fmt.Scanner. 20 | d := new(inf.Dec) 21 | _, err := fmt.Sscan("184467440.73709551617", d) 22 | if err != nil { 23 | log.Println("error scanning value:", err) 24 | } else { 25 | fmt.Println(d) 26 | } 27 | // Output: 184467440.73709551617 28 | } 29 | 30 | func ExampleDec_QuoRound_scale2RoundDown() { 31 | // 10 / 3 is an infinite decimal; it has no exact Dec representation 32 | x, y := inf.NewDec(10, 0), inf.NewDec(3, 0) 33 | // use 2 digits beyond the decimal point, round towards 0 34 | z := new(inf.Dec).QuoRound(x, y, 2, inf.RoundDown) 35 | fmt.Println(z) 36 | // Output: 3.33 37 | } 38 | 39 | func ExampleDec_QuoRound_scale2RoundCeil() { 40 | // -42 / 400 is an finite decimal with 3 digits beyond the decimal point 41 | x, y := inf.NewDec(-42, 0), inf.NewDec(400, 0) 42 | // use 2 digits beyond decimal point, round towards positive infinity 43 | z := new(inf.Dec).QuoRound(x, y, 2, inf.RoundCeil) 44 | fmt.Println(z) 45 | // Output: -0.10 46 | } 47 | 48 | func ExampleDec_QuoExact_ok() { 49 | // 1 / 25 is a finite decimal; it has exact Dec representation 50 | x, y := inf.NewDec(1, 0), inf.NewDec(25, 0) 51 | z := new(inf.Dec).QuoExact(x, y) 52 | fmt.Println(z) 53 | // Output: 0.04 54 | } 55 | 56 | func ExampleDec_QuoExact_fail() { 57 | // 1 / 3 is an infinite decimal; it has no exact Dec representation 58 | x, y := inf.NewDec(1, 0), inf.NewDec(3, 0) 59 | z := new(inf.Dec).QuoExact(x, y) 60 | fmt.Println(z) 61 | // Output: 62 | } 63 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/speter.net/go/exp/math/dec/inf/rounder.go: -------------------------------------------------------------------------------- 1 | package inf 2 | 3 | import ( 4 | "math/big" 5 | ) 6 | 7 | // Rounder represents a method for rounding the (possibly infinite decimal) 8 | // result of a division to a finite Dec. It is used by Dec.Round() and 9 | // Dec.Quo(). 10 | // 11 | // See the Example for results of using each Rounder with some sample values. 12 | // 13 | type Rounder rounder 14 | 15 | // See http://speleotrove.com/decimal/damodel.html#refround for more detailed 16 | // definitions of these rounding modes. 17 | var ( 18 | RoundDown Rounder // towards 0 19 | RoundUp Rounder // away from 0 20 | RoundFloor Rounder // towards -infinity 21 | RoundCeil Rounder // towards +infinity 22 | RoundHalfDown Rounder // to nearest; towards 0 if same distance 23 | RoundHalfUp Rounder // to nearest; away from 0 if same distance 24 | RoundHalfEven Rounder // to nearest; even last digit if same distance 25 | ) 26 | 27 | // RoundExact is to be used in the case when rounding is not necessary. 28 | // When used with Quo or Round, it returns the result verbatim when it can be 29 | // expressed exactly with the given precision, and it returns nil otherwise. 30 | // QuoExact is a shorthand for using Quo with RoundExact. 31 | var RoundExact Rounder 32 | 33 | type rounder interface { 34 | 35 | // When UseRemainder() returns true, the Round() method is passed the 36 | // remainder of the division, expressed as the numerator and denominator of 37 | // a rational. 38 | UseRemainder() bool 39 | 40 | // Round sets the rounded value of a quotient to z, and returns z. 41 | // quo is rounded down (truncated towards zero) to the scale obtained from 42 | // the Scaler in Quo(). 43 | // 44 | // When the remainder is not used, remNum and remDen are nil. 45 | // When used, the remainder is normalized between -1 and 1; that is: 46 | // 47 | // -|remDen| < remNum < |remDen| 48 | // 49 | // remDen has the same sign as y, and remNum is zero or has the same sign 50 | // as x. 51 | Round(z, quo *Dec, remNum, remDen *big.Int) *Dec 52 | } 53 | 54 | type rndr struct { 55 | useRem bool 56 | round func(z, quo *Dec, remNum, remDen *big.Int) *Dec 57 | } 58 | 59 | func (r rndr) UseRemainder() bool { 60 | return r.useRem 61 | } 62 | 63 | func (r rndr) Round(z, quo *Dec, remNum, remDen *big.Int) *Dec { 64 | return r.round(z, quo, remNum, remDen) 65 | } 66 | 67 | var intSign = []*big.Int{big.NewInt(-1), big.NewInt(0), big.NewInt(1)} 68 | 69 | func roundHalf(f func(c int, odd uint) (roundUp bool)) func(z, q *Dec, rA, rB *big.Int) *Dec { 70 | return func(z, q *Dec, rA, rB *big.Int) *Dec { 71 | z.Set(q) 72 | brA, brB := rA.BitLen(), rB.BitLen() 73 | if brA < brB-1 { 74 | // brA < brB-1 => |rA| < |rB/2| 75 | return z 76 | } 77 | roundUp := false 78 | srA, srB := rA.Sign(), rB.Sign() 79 | s := srA * srB 80 | if brA == brB-1 { 81 | rA2 := new(big.Int).Lsh(rA, 1) 82 | if s < 0 { 83 | rA2.Neg(rA2) 84 | } 85 | roundUp = f(rA2.Cmp(rB)*srB, z.UnscaledBig().Bit(0)) 86 | } else { 87 | // brA > brB-1 => |rA| > |rB/2| 88 | roundUp = true 89 | } 90 | if roundUp { 91 | z.UnscaledBig().Add(z.UnscaledBig(), intSign[s+1]) 92 | } 93 | return z 94 | } 95 | } 96 | 97 | func init() { 98 | RoundExact = rndr{true, 99 | func(z, q *Dec, rA, rB *big.Int) *Dec { 100 | if rA.Sign() != 0 { 101 | return nil 102 | } 103 | return z.Set(q) 104 | }} 105 | RoundDown = rndr{false, 106 | func(z, q *Dec, rA, rB *big.Int) *Dec { 107 | return z.Set(q) 108 | }} 109 | RoundUp = rndr{true, 110 | func(z, q *Dec, rA, rB *big.Int) *Dec { 111 | z.Set(q) 112 | if rA.Sign() != 0 { 113 | z.UnscaledBig().Add(z.UnscaledBig(), intSign[rA.Sign()*rB.Sign()+1]) 114 | } 115 | return z 116 | }} 117 | RoundFloor = rndr{true, 118 | func(z, q *Dec, rA, rB *big.Int) *Dec { 119 | z.Set(q) 120 | if rA.Sign()*rB.Sign() < 0 { 121 | z.UnscaledBig().Add(z.UnscaledBig(), intSign[0]) 122 | } 123 | return z 124 | }} 125 | RoundCeil = rndr{true, 126 | func(z, q *Dec, rA, rB *big.Int) *Dec { 127 | z.Set(q) 128 | if rA.Sign()*rB.Sign() > 0 { 129 | z.UnscaledBig().Add(z.UnscaledBig(), intSign[2]) 130 | } 131 | return z 132 | }} 133 | RoundHalfDown = rndr{true, roundHalf( 134 | func(c int, odd uint) bool { 135 | return c > 0 136 | })} 137 | RoundHalfUp = rndr{true, roundHalf( 138 | func(c int, odd uint) bool { 139 | return c >= 0 140 | })} 141 | RoundHalfEven = rndr{true, roundHalf( 142 | func(c int, odd uint) bool { 143 | return c > 0 || c == 0 && odd == 1 144 | })} 145 | } 146 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/speter.net/go/exp/math/dec/inf/rounder_example_test.go: -------------------------------------------------------------------------------- 1 | package inf_test 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "text/tabwriter" 7 | 8 | "github.com/klizhentas/deb2aci/Godeps/_workspace/src/speter.net/go/exp/math/dec/inf" 9 | ) 10 | 11 | // This example displays the results of Dec.Round with each of the Rounders. 12 | // 13 | func ExampleRounder() { 14 | var vals = []struct { 15 | x string 16 | s inf.Scale 17 | }{ 18 | {"-0.18", 1}, {"-0.15", 1}, {"-0.12", 1}, {"-0.10", 1}, 19 | {"-0.08", 1}, {"-0.05", 1}, {"-0.02", 1}, {"0.00", 1}, 20 | {"0.02", 1}, {"0.05", 1}, {"0.08", 1}, {"0.10", 1}, 21 | {"0.12", 1}, {"0.15", 1}, {"0.18", 1}, 22 | } 23 | 24 | var rounders = []struct { 25 | name string 26 | rounder inf.Rounder 27 | }{ 28 | {"RoundDown", inf.RoundDown}, {"RoundUp", inf.RoundUp}, 29 | {"RoundCeil", inf.RoundCeil}, {"RoundFloor", inf.RoundFloor}, 30 | {"RoundHalfDown", inf.RoundHalfDown}, {"RoundHalfUp", inf.RoundHalfUp}, 31 | {"RoundHalfEven", inf.RoundHalfEven}, {"RoundExact", inf.RoundExact}, 32 | } 33 | 34 | fmt.Println("The results of new(inf.Dec).Round(x, s, inf.RoundXXX):\n") 35 | w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.AlignRight) 36 | fmt.Fprint(w, "x\ts\t|\t") 37 | for _, r := range rounders { 38 | fmt.Fprintf(w, "%s\t", r.name[5:]) 39 | } 40 | fmt.Fprintln(w) 41 | for _, v := range vals { 42 | fmt.Fprintf(w, "%s\t%d\t|\t", v.x, v.s) 43 | for _, r := range rounders { 44 | x, _ := new(inf.Dec).SetString(v.x) 45 | z := new(inf.Dec).Round(x, v.s, r.rounder) 46 | fmt.Fprintf(w, "%d\t", z) 47 | } 48 | fmt.Fprintln(w) 49 | } 50 | w.Flush() 51 | 52 | // Output: 53 | // The results of new(inf.Dec).Round(x, s, inf.RoundXXX): 54 | // 55 | // x s | Down Up Ceil Floor HalfDown HalfUp HalfEven Exact 56 | // -0.18 1 | -0.1 -0.2 -0.1 -0.2 -0.2 -0.2 -0.2 57 | // -0.15 1 | -0.1 -0.2 -0.1 -0.2 -0.1 -0.2 -0.2 58 | // -0.12 1 | -0.1 -0.2 -0.1 -0.2 -0.1 -0.1 -0.1 59 | // -0.10 1 | -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 60 | // -0.08 1 | 0.0 -0.1 0.0 -0.1 -0.1 -0.1 -0.1 61 | // -0.05 1 | 0.0 -0.1 0.0 -0.1 0.0 -0.1 0.0 62 | // -0.02 1 | 0.0 -0.1 0.0 -0.1 0.0 0.0 0.0 63 | // 0.00 1 | 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 64 | // 0.02 1 | 0.0 0.1 0.1 0.0 0.0 0.0 0.0 65 | // 0.05 1 | 0.0 0.1 0.1 0.0 0.0 0.1 0.0 66 | // 0.08 1 | 0.0 0.1 0.1 0.0 0.1 0.1 0.1 67 | // 0.10 1 | 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 68 | // 0.12 1 | 0.1 0.2 0.2 0.1 0.1 0.1 0.1 69 | // 0.15 1 | 0.1 0.2 0.2 0.1 0.1 0.2 0.2 70 | // 0.18 1 | 0.1 0.2 0.2 0.1 0.2 0.2 0.2 71 | 72 | } 73 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/speter.net/go/exp/math/dec/inf/rounder_test.go: -------------------------------------------------------------------------------- 1 | package inf_test 2 | 3 | import ( 4 | "math/big" 5 | "testing" 6 | 7 | "github.com/klizhentas/deb2aci/Godeps/_workspace/src/speter.net/go/exp/math/dec/inf" 8 | ) 9 | 10 | var decRounderInputs = [...]struct { 11 | quo *inf.Dec 12 | rA, rB *big.Int 13 | }{ 14 | // examples from go language spec 15 | {inf.NewDec(1, 0), big.NewInt(2), big.NewInt(3)}, // 5 / 3 16 | {inf.NewDec(-1, 0), big.NewInt(-2), big.NewInt(3)}, // -5 / 3 17 | {inf.NewDec(-1, 0), big.NewInt(2), big.NewInt(-3)}, // 5 / -3 18 | {inf.NewDec(1, 0), big.NewInt(-2), big.NewInt(-3)}, // -5 / -3 19 | // examples from godoc 20 | {inf.NewDec(-1, 1), big.NewInt(-8), big.NewInt(10)}, 21 | {inf.NewDec(-1, 1), big.NewInt(-5), big.NewInt(10)}, 22 | {inf.NewDec(-1, 1), big.NewInt(-2), big.NewInt(10)}, 23 | {inf.NewDec(0, 1), big.NewInt(-8), big.NewInt(10)}, 24 | {inf.NewDec(0, 1), big.NewInt(-5), big.NewInt(10)}, 25 | {inf.NewDec(0, 1), big.NewInt(-2), big.NewInt(10)}, 26 | {inf.NewDec(0, 1), big.NewInt(0), big.NewInt(1)}, 27 | {inf.NewDec(0, 1), big.NewInt(2), big.NewInt(10)}, 28 | {inf.NewDec(0, 1), big.NewInt(5), big.NewInt(10)}, 29 | {inf.NewDec(0, 1), big.NewInt(8), big.NewInt(10)}, 30 | {inf.NewDec(1, 1), big.NewInt(2), big.NewInt(10)}, 31 | {inf.NewDec(1, 1), big.NewInt(5), big.NewInt(10)}, 32 | {inf.NewDec(1, 1), big.NewInt(8), big.NewInt(10)}, 33 | } 34 | 35 | var decRounderResults = [...]struct { 36 | rounder inf.Rounder 37 | results [len(decRounderInputs)]*inf.Dec 38 | }{ 39 | {inf.RoundExact, [...]*inf.Dec{nil, nil, nil, nil, 40 | nil, nil, nil, nil, nil, nil, 41 | inf.NewDec(0, 1), nil, nil, nil, nil, nil, nil}}, 42 | {inf.RoundDown, [...]*inf.Dec{ 43 | inf.NewDec(1, 0), inf.NewDec(-1, 0), inf.NewDec(-1, 0), inf.NewDec(1, 0), 44 | inf.NewDec(-1, 1), inf.NewDec(-1, 1), inf.NewDec(-1, 1), 45 | inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(0, 1), 46 | inf.NewDec(0, 1), 47 | inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(0, 1), 48 | inf.NewDec(1, 1), inf.NewDec(1, 1), inf.NewDec(1, 1)}}, 49 | {inf.RoundUp, [...]*inf.Dec{ 50 | inf.NewDec(2, 0), inf.NewDec(-2, 0), inf.NewDec(-2, 0), inf.NewDec(2, 0), 51 | inf.NewDec(-2, 1), inf.NewDec(-2, 1), inf.NewDec(-2, 1), 52 | inf.NewDec(-1, 1), inf.NewDec(-1, 1), inf.NewDec(-1, 1), 53 | inf.NewDec(0, 1), 54 | inf.NewDec(1, 1), inf.NewDec(1, 1), inf.NewDec(1, 1), 55 | inf.NewDec(2, 1), inf.NewDec(2, 1), inf.NewDec(2, 1)}}, 56 | {inf.RoundHalfDown, [...]*inf.Dec{ 57 | inf.NewDec(2, 0), inf.NewDec(-2, 0), inf.NewDec(-2, 0), inf.NewDec(2, 0), 58 | inf.NewDec(-2, 1), inf.NewDec(-1, 1), inf.NewDec(-1, 1), 59 | inf.NewDec(-1, 1), inf.NewDec(0, 1), inf.NewDec(0, 1), 60 | inf.NewDec(0, 1), 61 | inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(1, 1), 62 | inf.NewDec(1, 1), inf.NewDec(1, 1), inf.NewDec(2, 1)}}, 63 | {inf.RoundHalfUp, [...]*inf.Dec{ 64 | inf.NewDec(2, 0), inf.NewDec(-2, 0), inf.NewDec(-2, 0), inf.NewDec(2, 0), 65 | inf.NewDec(-2, 1), inf.NewDec(-2, 1), inf.NewDec(-1, 1), 66 | inf.NewDec(-1, 1), inf.NewDec(-1, 1), inf.NewDec(0, 1), 67 | inf.NewDec(0, 1), 68 | inf.NewDec(0, 1), inf.NewDec(1, 1), inf.NewDec(1, 1), 69 | inf.NewDec(1, 1), inf.NewDec(2, 1), inf.NewDec(2, 1)}}, 70 | {inf.RoundHalfEven, [...]*inf.Dec{ 71 | inf.NewDec(2, 0), inf.NewDec(-2, 0), inf.NewDec(-2, 0), inf.NewDec(2, 0), 72 | inf.NewDec(-2, 1), inf.NewDec(-2, 1), inf.NewDec(-1, 1), 73 | inf.NewDec(-1, 1), inf.NewDec(0, 1), inf.NewDec(0, 1), 74 | inf.NewDec(0, 1), 75 | inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(1, 1), 76 | inf.NewDec(1, 1), inf.NewDec(2, 1), inf.NewDec(2, 1)}}, 77 | {inf.RoundFloor, [...]*inf.Dec{ 78 | inf.NewDec(1, 0), inf.NewDec(-2, 0), inf.NewDec(-2, 0), inf.NewDec(1, 0), 79 | inf.NewDec(-2, 1), inf.NewDec(-2, 1), inf.NewDec(-2, 1), 80 | inf.NewDec(-1, 1), inf.NewDec(-1, 1), inf.NewDec(-1, 1), 81 | inf.NewDec(0, 1), 82 | inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(0, 1), 83 | inf.NewDec(1, 1), inf.NewDec(1, 1), inf.NewDec(1, 1)}}, 84 | {inf.RoundCeil, [...]*inf.Dec{ 85 | inf.NewDec(2, 0), inf.NewDec(-1, 0), inf.NewDec(-1, 0), inf.NewDec(2, 0), 86 | inf.NewDec(-1, 1), inf.NewDec(-1, 1), inf.NewDec(-1, 1), 87 | inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(0, 1), 88 | inf.NewDec(0, 1), 89 | inf.NewDec(1, 1), inf.NewDec(1, 1), inf.NewDec(1, 1), 90 | inf.NewDec(2, 1), inf.NewDec(2, 1), inf.NewDec(2, 1)}}, 91 | } 92 | 93 | func TestDecRounders(t *testing.T) { 94 | for i, a := range decRounderResults { 95 | for j, input := range decRounderInputs { 96 | q := new(inf.Dec).Set(input.quo) 97 | rA, rB := new(big.Int).Set(input.rA), new(big.Int).Set(input.rB) 98 | res := a.rounder.Round(new(inf.Dec), q, rA, rB) 99 | if a.results[j] == nil && res == nil { 100 | continue 101 | } 102 | if (a.results[j] == nil && res != nil) || 103 | (a.results[j] != nil && res == nil) || 104 | a.results[j].Cmp(res) != 0 { 105 | t.Errorf("#%d,%d Rounder got %v; expected %v", i, j, res, a.results[j]) 106 | } 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all 2 | 3 | all: 4 | go install . 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # deb2aci 2 | 3 | Deb2aci works like aptitude, but instead it downloads the deb packages with all their dependencies 4 | and installs them into the ACI image. 5 | 6 | It remembers each dependency in annotation to the resulting image manifest. 7 | 8 | ``` 9 | # outputs nginx.aci 10 | deb2aci -pkg nginx -manifest nginx.manifest -image nginx.aci 11 | ``` 12 | 13 | The image manifest will keep track of what packages are part of it: 14 | 15 | ``` 16 | [ 17 | { 18 | "name":"debian.org/deb/lsb-base", 19 | "value":"all/4.1+Debian11ubuntu8" 20 | }, 21 | { 22 | "name":"debian.org/deb/libjbig0", 23 | "value":"amd64/2.1-3.1" 24 | }, 25 | ... 26 | ] 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /deb2aci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/klizhentas/deb2aci/b80e8d909be1dbe52251f13057de939a19f42882/deb2aci --------------------------------------------------------------------------------