Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
5a1a03bd
Commit
5a1a03bd
authored
Mar 21, 2019
by
Jakub Sztandera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add version deps command
License: MIT Signed-off-by:
Jakub Sztandera
<
kubuxu@protonmail.ch
>
parent
7aae6439
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
1 deletion
+55
-1
core/commands/commands_test.go
core/commands/commands_test.go
+2
-0
core/commands/version.go
core/commands/version.go
+53
-1
No files found.
core/commands/commands_test.go
View file @
5a1a03bd
...
...
@@ -38,6 +38,7 @@ func TestROCommands(t *testing.T) {
"/refs"
,
"/resolve"
,
"/version"
,
"/version/deps"
,
}
cmdSet
:=
make
(
map
[
string
]
struct
{})
...
...
@@ -211,6 +212,7 @@ func TestCommands(t *testing.T) {
"/urlstore"
,
"/urlstore/add"
,
"/version"
,
"/version/deps"
,
"/cid"
,
"/cid/format"
,
"/cid/base32"
,
...
...
core/commands/version.go
View file @
5a1a03bd
package
commands
import
(
"errors"
"fmt"
"io"
"runtime"
"runtime/debug"
version
"github.com/ipfs/go-ipfs"
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"
)
...
...
@@ -32,6 +34,9 @@ var VersionCmd = &cmds.Command{
Tagline
:
"Show ipfs version information."
,
ShortDescription
:
"Returns the current version of ipfs and exits."
,
},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"deps"
:
depsVersionCommand
,
},
Options
:
[]
cmdkit
.
Option
{
cmdkit
.
BoolOption
(
versionNumberOptionName
,
"n"
,
"Only show the version number."
),
...
...
@@ -83,3 +88,50 @@ var VersionCmd = &cmds.Command{
},
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"
)
}),
},
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment