mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-26 23:53:19 +08:00
Merge pull request #4732 from fyrchik/fix/cmds/init
make init command use go-ipfs-cmds
This commit is contained in:
@ -11,13 +11,14 @@ import (
|
||||
"strings"
|
||||
|
||||
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"
|
||||
namesys "github.com/ipfs/go-ipfs/namesys"
|
||||
config "github.com/ipfs/go-ipfs/repo/config"
|
||||
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
|
||||
"gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmfAkMSt9Fwzk48QDJecPcwCUjnf2uG7MLnmCGTp4C6ouL/go-ipfs-cmds"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -59,8 +60,9 @@ environment variable:
|
||||
// name of the file?
|
||||
// TODO cmdkit.StringOption("event-logs", "l", "Location for machine-readable event logs."),
|
||||
},
|
||||
PreRun: func(req cmds.Request) error {
|
||||
daemonLocked, err := fsrepo.LockedByOtherProcess(req.InvocContext().ConfigRoot)
|
||||
PreRun: func(req *cmds.Request, env cmds.Environment) error {
|
||||
cctx := env.(*oldcmds.Context)
|
||||
daemonLocked, err := fsrepo.LockedByOtherProcess(cctx.ConfigRoot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -74,30 +76,19 @@ environment variable:
|
||||
|
||||
return nil
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.Response) {
|
||||
// needs to be called at least once
|
||||
res.SetOutput(nil)
|
||||
|
||||
if req.InvocContext().Online {
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
|
||||
cctx := env.(*oldcmds.Context)
|
||||
if cctx.Online {
|
||||
res.SetError(errors.New("init must be run offline only!"), cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
empty, _, err := req.Option("e").Bool()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
nBitsForKeypair, _, err := req.Option("b").Int()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
empty, _ := req.Options["empty-repo"].(bool)
|
||||
nBitsForKeypair, _ := req.Options["bits"].(int)
|
||||
|
||||
var conf *config.Config
|
||||
|
||||
f := req.Files()
|
||||
f := req.Files
|
||||
if f != nil {
|
||||
confFile, err := f.NextFile()
|
||||
if err != nil {
|
||||
@ -112,18 +103,14 @@ environment variable:
|
||||
}
|
||||
}
|
||||
|
||||
profile, _, err := req.Option("profile").String()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
profile, _ := req.Options["profile"].(string)
|
||||
|
||||
var profiles []string
|
||||
if 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)
|
||||
return
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
|
||||
commands "github.com/ipfs/go-ipfs/core/commands"
|
||||
|
||||
lgc "github.com/ipfs/go-ipfs/commands/legacy"
|
||||
cmds "gx/ipfs/QmfAkMSt9Fwzk48QDJecPcwCUjnf2uG7MLnmCGTp4C6ouL/go-ipfs-cmds"
|
||||
)
|
||||
|
||||
@ -24,7 +23,7 @@ var commandsClientCmd = commands.CommandsCmd(Root)
|
||||
// They can override subcommands in commands.Root by defining a subcommand with the same name.
|
||||
var localCommands = map[string]*cmds.Command{
|
||||
"daemon": daemonCmd,
|
||||
"init": lgc.NewCommand(initCmd),
|
||||
"init": initCmd,
|
||||
"commands": commandsClientCmd,
|
||||
}
|
||||
var localMap = make(map[*cmds.Command]bool)
|
||||
|
Reference in New Issue
Block a user