本文整理汇总了Golang中github.com/blang/semver.Version.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Version.String方法的具体用法?Golang Version.String怎么用?Golang Version.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/blang/semver.Version
的用法示例。
在下文中一共展示了Version.String方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: set
func set(v semver.Version) {
err := ioutil.WriteFile(file, []byte(v.String()), os.ModeExclusive)
if err != nil {
fmt.Printf("Unable to write version file: %v", err)
os.Exit(3)
}
fmt.Printf("New version: %s", v)
}
示例2: main
func main() {
if len(os.Args) < 2 {
println("usage: " + os.Args[0] + " <source>")
os.Exit(1)
}
sources := os.Args[1]
var request models.OutRequest
err := json.NewDecoder(os.Stdin).Decode(&request)
if err != nil {
fatal("reading request", err)
}
driver, err := driver.FromSource(request.Source)
if err != nil {
fatal("constructing driver", err)
}
var newVersion semver.Version
if request.Params.File != "" {
versionFile, err := os.Open(filepath.Join(sources, request.Params.File))
if err != nil {
fatal("opening version file", err)
}
defer versionFile.Close()
var versionStr string
_, err = fmt.Fscanf(versionFile, "%s", &versionStr)
if err != nil {
fatal("reading version file", err)
}
newVersion, err = semver.Parse(versionStr)
if err != nil {
fatal("parsing version", err)
}
err = driver.Set(newVersion)
if err != nil {
fatal("setting version", err)
}
} else if request.Params.Bump != "" || request.Params.Pre != "" {
bump := version.BumpFromParams(request.Params.Bump, request.Params.Pre)
newVersion, err = driver.Bump(bump)
if err != nil {
fatal("bumping version", err)
}
} else {
println("no version bump specified")
os.Exit(1)
}
outVersion := models.Version{
Number: newVersion.String(),
}
json.NewEncoder(os.Stdout).Encode(models.OutResponse{
Version: outVersion,
Metadata: models.Metadata{
{"number", outVersion.Number},
},
})
}
示例3:
"": "1.2.3",
"final": "1.2.3",
"patch": "1.2.4",
"minor": "1.3.0",
"major": "2.0.0",
} {
bumpLocal := bump
resultLocal := result
Context(fmt.Sprintf("when bumping %s", bumpLocal), func() {
BeforeEach(func() {
bumpParam = bumpLocal
})
It("bumps to "+resultLocal, func() {
Ω(version.String()).Should(Equal(resultLocal))
})
})
}
Context("when bumping to a prerelease", func() {
BeforeEach(func() {
preParam = "rc"
})
for bump, result := range map[string]string{
"": "1.2.3-rc.1",
"final": "1.2.3-rc.1",
"patch": "1.2.4-rc.1",
"minor": "1.3.0-rc.1",
"major": "2.0.0-rc.1",