1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-27 07:57:30 +08:00

Merge pull request #4732 from fyrchik/fix/cmds/init

make init command use go-ipfs-cmds
This commit is contained in:
Whyrusleeping
2018-03-23 11:56:49 -07:00
committed by GitHub
2 changed files with 14 additions and 28 deletions

View File

@ -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:
// 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:
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:
} }
} }
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
} }

View File

@ -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)
// 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)