提交 5a1a03bd 作者: Jakub Sztandera

feat: add version deps command

License: MIT
Signed-off-by: 's avatarJakub Sztandera <kubuxu@protonmail.ch>
上级 7aae6439
...@@ -38,6 +38,7 @@ func TestROCommands(t *testing.T) { ...@@ -38,6 +38,7 @@ func TestROCommands(t *testing.T) {
"/refs", "/refs",
"/resolve", "/resolve",
"/version", "/version",
"/version/deps",
} }
cmdSet := make(map[string]struct{}) cmdSet := make(map[string]struct{})
...@@ -211,6 +212,7 @@ func TestCommands(t *testing.T) { ...@@ -211,6 +212,7 @@ func TestCommands(t *testing.T) {
"/urlstore", "/urlstore",
"/urlstore/add", "/urlstore/add",
"/version", "/version",
"/version/deps",
"/cid", "/cid",
"/cid/format", "/cid/format",
"/cid/base32", "/cid/base32",
......
package commands package commands
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"runtime" "runtime"
"runtime/debug"
version "github.com/ipfs/go-ipfs" version "github.com/ipfs/go-ipfs"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo" fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
"github.com/ipfs/go-ipfs-cmdkit" cmdkit "github.com/ipfs/go-ipfs-cmdkit"
cmds "github.com/ipfs/go-ipfs-cmds" cmds "github.com/ipfs/go-ipfs-cmds"
) )
...@@ -32,6 +34,9 @@ var VersionCmd = &cmds.Command{ ...@@ -32,6 +34,9 @@ var VersionCmd = &cmds.Command{
Tagline: "Show ipfs version information.", Tagline: "Show ipfs version information.",
ShortDescription: "Returns the current version of ipfs and exits.", ShortDescription: "Returns the current version of ipfs and exits.",
}, },
Subcommands: map[string]*cmds.Command{
"deps": depsVersionCommand,
},
Options: []cmdkit.Option{ Options: []cmdkit.Option{
cmdkit.BoolOption(versionNumberOptionName, "n", "Only show the version number."), cmdkit.BoolOption(versionNumberOptionName, "n", "Only show the version number."),
...@@ -83,3 +88,50 @@ var VersionCmd = &cmds.Command{ ...@@ -83,3 +88,50 @@ var VersionCmd = &cmds.Command{
}, },
Type: VersionOutput{}, Type: VersionOutput{},
} }
type Dependency struct {
Path string
Version string
ReplacedBy string
Sum string
}
var depsVersionCommand = &cmds.Command{
Helptext: cmdkit.HelpText{
Tagline: "Shows information about dependencies used for build",
ShortDescription: `
Print out all dependencies and their versions.`,
},
Type: Dependency{},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
info, ok := debug.ReadBuildInfo()
if !ok {
return errors.New("no embedded dependency information")
}
toDependency := func(mod *debug.Module) (dep Dependency) {
dep.Path = mod.Path
dep.Version = mod.Version
dep.Sum = mod.Sum
if repl := mod.Replace; repl != nil {
dep.ReplacedBy = fmt.Sprintf("%s@%s", repl.Path, repl.Version)
}
return
}
res.Emit(toDependency(&info.Main))
for _, dep := range info.Deps {
res.Emit(toDependency(dep))
}
return nil
},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, dep Dependency) error {
fmt.Fprintf(w, "%s@%s", dep.Path, dep.Version)
if dep.ReplacedBy != "" {
fmt.Fprintf(w, " => %s", dep.ReplacedBy)
}
fmt.Fprintf(w, "\n")
return errors.New("test")
}),
},
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论