0

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

Posted by nanxiao on 五月 18, 2016 in Delve代码分析笔记 |

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:

 

标签:, ,

发表评论

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

Copyright © 2013-2017 我的站点 All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.5, from BuyNowShop.com.