Delve代码分析笔记(2)——version

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:

 

发表评论

邮箱地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.