Version
包只包含了一个version.go
:
package version
import "fmt"
// Version represents the current version of Delve.
type Version struct {
Major string
Minor string
Patch string
Metadata string
Build string
}
var (
// DelveVersion is the current version of Delve.
DelveVersion = Version{Major: "0", Minor: "11", Patch: "0", Metadata: "alpha"}
)
func (v Version) String() string {
return fmt.Sprintf("Version: %s.%s.%s-%s\nBuild: %s", v.Major, v.Minor, v.Patch, v.Metadata, v.Build)
}
Version
包定义了一个Version
类型的变量:DelveVersion
。而Version
类型的String()
方法就是用来构造执行dlv version
命令时,输出的字符串(cmd/dlv/cmds/commands.go
):
......
// 'version' subcommand.
versionCommand := &cobra.Command{
Use: "version",
Short: "Prints version.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Delve Debugger\n%s\n", version.DelveVersion)
},
}
......
执行dlv version
命令:
# dlv version
Delve Debugger
Version: 0.11.0-alpha
Build:
有疑问加站长微信联系(非本文作者)