提交 14975fca 作者: fyrchik

make init command use go-ipfs-cmds

License: MIT
Signed-off-by: 's avatarEvgenii Stratonikov <kraunid@gmail.com>
上级 550c6eb5
...@@ -11,13 +11,14 @@ import ( ...@@ -11,13 +11,14 @@ import (
"strings" "strings"
assets "github.com/ipfs/go-ipfs/assets" assets "github.com/ipfs/go-ipfs/assets"
cmds "github.com/ipfs/go-ipfs/commands" oldcmds "github.com/ipfs/go-ipfs/commands"
core "github.com/ipfs/go-ipfs/core" core "github.com/ipfs/go-ipfs/core"
namesys "github.com/ipfs/go-ipfs/namesys" namesys "github.com/ipfs/go-ipfs/namesys"
config "github.com/ipfs/go-ipfs/repo/config" config "github.com/ipfs/go-ipfs/repo/config"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo" fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
"gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit" "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
"gx/ipfs/QmfAkMSt9Fwzk48QDJecPcwCUjnf2uG7MLnmCGTp4C6ouL/go-ipfs-cmds"
) )
const ( const (
...@@ -59,8 +60,9 @@ environment variable: ...@@ -59,8 +60,9 @@ environment variable:
// name of the file? // name of the file?
// TODO cmdkit.StringOption("event-logs", "l", "Location for machine-readable event logs."), // TODO cmdkit.StringOption("event-logs", "l", "Location for machine-readable event logs."),
}, },
PreRun: func(req cmds.Request) error { PreRun: func(req *cmds.Request, env cmds.Environment) error {
daemonLocked, err := fsrepo.LockedByOtherProcess(req.InvocContext().ConfigRoot) cctx := env.(*oldcmds.Context)
daemonLocked, err := fsrepo.LockedByOtherProcess(cctx.ConfigRoot)
if err != nil { if err != nil {
return err return err
} }
...@@ -74,30 +76,19 @@ environment variable: ...@@ -74,30 +76,19 @@ environment variable:
return nil return nil
}, },
Run: func(req cmds.Request, res cmds.Response) { Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
// needs to be called at least once cctx := env.(*oldcmds.Context)
res.SetOutput(nil) if cctx.Online {
if req.InvocContext().Online {
res.SetError(errors.New("init must be run offline only!"), cmdkit.ErrNormal) res.SetError(errors.New("init must be run offline only!"), cmdkit.ErrNormal)
return return
} }
empty, _, err := req.Option("e").Bool() empty, _ := req.Options["empty-repo"].(bool)
if err != nil { nBitsForKeypair, _ := req.Options["bits"].(int)
res.SetError(err, cmdkit.ErrNormal)
return
}
nBitsForKeypair, _, err := req.Option("b").Int()
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
}
var conf *config.Config var conf *config.Config
f := req.Files() f := req.Files
if f != nil { if f != nil {
confFile, err := f.NextFile() confFile, err := f.NextFile()
if err != nil { if err != nil {
...@@ -112,18 +103,14 @@ environment variable: ...@@ -112,18 +103,14 @@ environment variable:
} }
} }
profile, _, err := req.Option("profile").String() profile, _ := req.Options["profile"].(string)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
}
var profiles []string var profiles []string
if profile != "" { if profile != "" {
profiles = strings.Split(profile, ",") profiles = strings.Split(profile, ",")
} }
if err := doInit(os.Stdout, req.InvocContext().ConfigRoot, empty, nBitsForKeypair, profiles, conf); err != nil { if err := doInit(os.Stdout, cctx.ConfigRoot, empty, nBitsForKeypair, profiles, conf); err != nil {
res.SetError(err, cmdkit.ErrNormal) res.SetError(err, cmdkit.ErrNormal)
return return
} }
......
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
commands "github.com/ipfs/go-ipfs/core/commands" commands "github.com/ipfs/go-ipfs/core/commands"
lgc "github.com/ipfs/go-ipfs/commands/legacy"
cmds "gx/ipfs/QmfAkMSt9Fwzk48QDJecPcwCUjnf2uG7MLnmCGTp4C6ouL/go-ipfs-cmds" cmds "gx/ipfs/QmfAkMSt9Fwzk48QDJecPcwCUjnf2uG7MLnmCGTp4C6ouL/go-ipfs-cmds"
) )
...@@ -24,7 +23,7 @@ var commandsClientCmd = commands.CommandsCmd(Root) ...@@ -24,7 +23,7 @@ var commandsClientCmd = commands.CommandsCmd(Root)
// They can override subcommands in commands.Root by defining a subcommand with the same name. // They can override subcommands in commands.Root by defining a subcommand with the same name.
var localCommands = map[string]*cmds.Command{ var localCommands = map[string]*cmds.Command{
"daemon": daemonCmd, "daemon": daemonCmd,
"init": lgc.NewCommand(initCmd), "init": initCmd,
"commands": commandsClientCmd, "commands": commandsClientCmd,
} }
var localMap = make(map[*cmds.Command]bool) var localMap = make(map[*cmds.Command]bool)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论