Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make init command use go-ipfs-cmds #4732

Merged
merged 1 commit into from
Mar 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 13 additions & 26 deletions cmd/ipfs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand All @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/ipfs/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand Down