• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

softlayer / softlayer-go / 13824212013

13 Mar 2025 12:26AM UTC coverage: 95.953% (-2.2%) from 98.143%
13824212013

Pull #201

github

web-flow
Merge 0268bb9e4 into 80a745b76
Pull Request #201: Bump golang.org/x/net from 0.23.0 to 0.36.0

36825 of 38378 relevant lines covered (95.95%)

7.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/tools/version.go
1
/**
2
 * Copyright 2016 IBM Corp.
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 main
18

19
import (
20
        "bytes"
21
        "fmt"
22
        "go/format"
23
        "html/template"
24
        "os"
25

26
        "flag"
27
        "github.com/softlayer/softlayer-go/sl"
28
)
29

30
const license = `/**
31
 * Copyright 2016-2024 IBM Corp.
32
 *
33
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 
34
 * the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
35
 *
36
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed 
37
 * on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38
 * See the License for the specific language governing permissions and limitations under the License.
39
 */
40
 `
41
const codegenWarning = `// AUTOMATICALLY GENERATED CODE - DO NOT MODIFY`
42

43
var versionfile = fmt.Sprintf(`%s
44

45
%s
46

47
package sl
48

49
import "fmt"
50

51
type VersionInfo struct {
52
        Major  int
53
        Minor  int
54
        Patch  int
55
        Pre    string
56
}
57

58
var Version = VersionInfo {
59
        Major:  {{.Major}},
60
        Minor:  {{.Minor}},
61
        Patch:  {{.Patch}},
62
        Pre:    "{{.Pre}}",
63
}
64

65
func (v VersionInfo) String() string {
66
        result := fmt.Sprintf("v%%d.%%d.%%d", v.Major, v.Minor, v.Patch)
67

68
        if v.Pre != "" {
69
                result += fmt.Sprintf("-%%s", v.Pre)
70
        }
71

72
        return result
73
}
74

75
`, license, codegenWarning)
76

77
const (
78
        bumpUsage   = "specify one of major|minor|patch to bump that specifier"
79
        prerelUsage = "optional prerelease stamp (e.g. alpha, beta, rc.1"
80
)
81

82
func version() {
×
83
        var bump, prerelease string
×
84

×
85
        flagset := flag.NewFlagSet(os.Args[1], flag.ExitOnError)
×
86

×
87
        flagset.StringVar(&bump, "bump", "", bumpUsage)
×
88
        flagset.StringVar(&bump, "b", "", bumpUsage+" (shorthand)")
×
89

×
90
        flagset.StringVar(&prerelease, "prerelease", "", prerelUsage)
×
91
        flagset.StringVar(&prerelease, "p", "", prerelUsage+" (shorthand)")
×
92

×
93
        flagset.Parse(os.Args[2:])
×
94

×
95
        v := sl.Version
×
96

×
97
        switch bump {
×
98
        case "major":
×
99
                v.Major++
×
100
                v.Minor = 0
×
101
                v.Patch = 0
×
102
                v.Pre = prerelease
×
103
        case "minor":
×
104
                v.Minor++
×
105
                v.Patch = 0
×
106
                v.Pre = prerelease
×
107
        case "patch":
×
108
                v.Patch++
×
109
                v.Pre = prerelease
×
110
        case "":
×
111
        default:
×
112
                fmt.Printf("Invalid value for bump: %s", bump)
×
113
                os.Exit(1)
×
114
        }
115

116
        writeVersionFile(v)
×
117

×
118
        fmt.Println(v)
×
119
}
120

121
func writeVersionFile(v sl.VersionInfo) {
×
122
        // Generate source
×
123
        var buf bytes.Buffer
×
124
        t := template.New("version")
×
125
        template.Must(t.Parse(versionfile)).Execute(&buf, v)
×
126

×
127
        //fmt.Println(string(buf.Bytes()))
×
128

×
129
        // format go file
×
130
        pretty, err := format.Source(buf.Bytes())
×
131
        if err != nil {
×
132
                fmt.Println(err)
×
133
                os.Exit(1)
×
134
        }
×
135

136
        // write go file
137
        f, err := os.Create("sl/version.go")
×
138
        if err != nil {
×
139
                fmt.Println(err)
×
140
                os.Exit(1)
×
141
        }
×
142
        defer f.Close()
×
143
        fmt.Fprintf(f, "%s", pretty)
×
144
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc