upgrade shutdown command to the new commands lib

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
This commit is contained in:
Steven Allen 2018-07-31 12:45:14 -07:00
parent 4bca53e0c9
commit 8bcf6f48d9
2 changed files with 6 additions and 9 deletions

View File

@ -138,7 +138,7 @@ var rootSubcommands = map[string]*cmds.Command{
"update": lgc.NewCommand(ExternalBinary()),
"urlstore": urlStoreCmd,
"version": lgc.NewCommand(VersionCmd),
"shutdown": lgc.NewCommand(daemonShutdownCmd),
"shutdown": daemonShutdownCmd,
}
// RootRO is the readonly version of Root

View File

@ -3,31 +3,28 @@ package commands
import (
"fmt"
cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
"gx/ipfs/QmdE4gMduCKCGAcczM2F5ioYDfdeKuPix138wrES1YSr7f/go-ipfs-cmdkit"
cmds "github.com/ipfs/go-ipfs/commands"
)
var daemonShutdownCmd = &cmds.Command{
Helptext: cmdkit.HelpText{
Tagline: "Shut down the ipfs daemon",
},
Run: func(req cmds.Request, res cmds.Response) {
nd, err := req.InvocContext().GetNode()
Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) {
nd, err := GetNode(env)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
re.SetError(err, cmdkit.ErrNormal)
return
}
if nd.LocalMode() {
res.SetError(fmt.Errorf("daemon not running"), cmdkit.ErrClient)
re.SetError(fmt.Errorf("daemon not running"), cmdkit.ErrClient)
return
}
if err := nd.Process().Close(); err != nil {
log.Error("error while shutting down ipfs daemon:", err)
}
res.SetOutput(nil)
},
}