make init command use go-ipfs-cmds
License: MIT Signed-off-by: Evgenii Stratonikov <kraunid@gmail.com>
fyrchik committed
Feb 23, 2018 at 15:21 UTC
14975fca6cd4a5d780d77db10492ebdd24c73bde
2 files changed
+14
-28
cmd/ipfs/init.go
+13
-26
@@ -11,13 +11,14 @@ import (
11
"strings"
12
13
assets "github.com/ipfs/go-ipfs/assets"
14
- cmds "github.com/ipfs/go-ipfs/commands"
14
+ oldcmds "github.com/ipfs/go-ipfs/commands"
15
core "github.com/ipfs/go-ipfs/core"
16
namesys "github.com/ipfs/go-ipfs/namesys"
17
config "github.com/ipfs/go-ipfs/repo/config"
18
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
19
20
"gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
21
+ "gx/ipfs/QmfAkMSt9Fwzk48QDJecPcwCUjnf2uG7MLnmCGTp4C6ouL/go-ipfs-cmds"
22
)
23
24
const (
@@ -59,8 +60,9 @@ environment variable:
60
// name of the file?
61
// TODO cmdkit.StringOption("event-logs", "l", "Location for machine-readable event logs."),
62
},
62
- PreRun: func(req cmds.Request) error {
63
- daemonLocked, err := fsrepo.LockedByOtherProcess(req.InvocContext().ConfigRoot)
63
+ PreRun: func(req *cmds.Request, env cmds.Environment) error {
64
+ cctx := env.(*oldcmds.Context)
65
+ daemonLocked, err := fsrepo.LockedByOtherProcess(cctx.ConfigRoot)
66
if err != nil {
67
return err
68
}
@@ -74,30 +76,19 @@ environment variable:
76
77
return nil
78
},
77
- Run: func(req cmds.Request, res cmds.Response) {
78
- // needs to be called at least once
79
- res.SetOutput(nil)
80
-
81
- if req.InvocContext().Online {
79
+ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
80
+ cctx := env.(*oldcmds.Context)
81
+ if cctx.Online {
82
res.SetError(errors.New("init must be run offline only!"), cmdkit.ErrNormal)
83
return
84
}
85
86
- empty, _, err := req.Option("e").Bool()
87
- if err != nil {
88
- res.SetError(err, cmdkit.ErrNormal)
89
- return
90
- }
91
-
92
- nBitsForKeypair, _, err := req.Option("b").Int()
93
- if err != nil {
94
- res.SetError(err, cmdkit.ErrNormal)
95
- return
96
- }
86
+ empty, _ := req.Options["empty-repo"].(bool)
87
+ nBitsForKeypair, _ := req.Options["bits"].(int)
88
89
var conf *config.Config
90
100
- f := req.Files()
91
+ f := req.Files
92
if f != nil {
93
confFile, err := f.NextFile()
94
if err != nil {
@@ -112,18 +103,14 @@ environment variable:
103
}
104
}
105
115
- profile, _, err := req.Option("profile").String()
116
- if err != nil {
117
- res.SetError(err, cmdkit.ErrNormal)
118
- return
119
- }
106
+ profile, _ := req.Options["profile"].(string)
107
108
var profiles []string
109
if profile != "" {
110
profiles = strings.Split(profile, ",")
111
}
112
126
- if err := doInit(os.Stdout, req.InvocContext().ConfigRoot, empty, nBitsForKeypair, profiles, conf); err != nil {
113
+ if err := doInit(os.Stdout, cctx.ConfigRoot, empty, nBitsForKeypair, profiles, conf); err != nil {
114
res.SetError(err, cmdkit.ErrNormal)
115
return
116
}
cmd/ipfs/ipfs.go
+1
-2
@@ -5,7 +5,6 @@ import (
5
6
commands "github.com/ipfs/go-ipfs/core/commands"
7
8
- lgc "github.com/ipfs/go-ipfs/commands/legacy"
8
cmds "gx/ipfs/QmfAkMSt9Fwzk48QDJecPcwCUjnf2uG7MLnmCGTp4C6ouL/go-ipfs-cmds"
9
)
10
@@ -24,7 +23,7 @@ var commandsClientCmd = commands.CommandsCmd(Root)
23
// They can override subcommands in commands.Root by defining a subcommand with the same name.
24
var localCommands = map[string]*cmds.Command{
25
"daemon": daemonCmd,
27
- "init": lgc.NewCommand(initCmd),
26
+ "init": initCmd,
27
"commands": commandsClientCmd,
28
}
29
var localMap = make(map[*cmds.Command]bool)