mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-01 16:05:47 +08:00
adds the option to see the current git commit with ipfs version --commit
License: MIT Signed-off-by: Caio Alonso <caio@caioalonso.com>
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
||||
|
||||
type VersionOutput struct {
|
||||
Version string
|
||||
Commit string
|
||||
}
|
||||
|
||||
var VersionCmd = &cmds.Command{
|
||||
@ -21,24 +22,36 @@ var VersionCmd = &cmds.Command{
|
||||
|
||||
Options: []cmds.Option{
|
||||
cmds.BoolOption("number", "n", "Only show the version number"),
|
||||
cmds.BoolOption("commit", "Show the commit hash"),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.Response) {
|
||||
res.SetOutput(&VersionOutput{
|
||||
Version: config.CurrentVersionNumber,
|
||||
Commit: config.CurrentCommit,
|
||||
})
|
||||
},
|
||||
Marshalers: cmds.MarshalerMap{
|
||||
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
||||
v := res.Output().(*VersionOutput)
|
||||
|
||||
commit, found, err := res.Request().Option("commit").Bool()
|
||||
commitTxt := ""
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if found && commit {
|
||||
commitTxt = "-" + v.Commit
|
||||
}
|
||||
|
||||
number, found, err := res.Request().Option("number").Bool()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if found && number {
|
||||
return strings.NewReader(fmt.Sprintln(v.Version)), nil
|
||||
return strings.NewReader(fmt.Sprintln(v.Version + commitTxt)), nil
|
||||
}
|
||||
return strings.NewReader(fmt.Sprintf("ipfs version %s\n", v.Version)), nil
|
||||
|
||||
return strings.NewReader(fmt.Sprintf("ipfs version %s%s\n", v.Version, commitTxt)), nil
|
||||
},
|
||||
},
|
||||
Type: VersionOutput{},
|
||||
|
Reference in New Issue
Block a user