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

Merge pull request #5022 from Bren2010/review/cmd/ipfs

Remove leftover bits of code.
This commit is contained in:
Whyrusleeping
2018-05-28 06:14:44 +01:00
committed by GitHub
4 changed files with 10 additions and 43 deletions

View File

@ -301,10 +301,6 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
} }
routingOption, _ := req.Options[routingOptionKwd].(string) routingOption, _ := req.Options[routingOptionKwd].(string)
if err != nil {
re.SetError(err, cmdkit.ErrNormal)
return
}
if routingOption == routingOptionDefaultKwd { if routingOption == routingOptionDefaultKwd {
cfg, err := repo.Config() cfg, err := repo.Config()
if err != nil { if err != nil {

View File

@ -26,7 +26,6 @@ var localCommands = map[string]*cmds.Command{
"init": initCmd, "init": initCmd,
"commands": commandsClientCmd, "commands": commandsClientCmd,
} }
var localMap = make(map[*cmds.Command]bool)
func init() { func init() {
// setting here instead of in literal to prevent initialization loop // setting here instead of in literal to prevent initialization loop
@ -38,10 +37,6 @@ func init() {
Root.Subcommands[k] = v Root.Subcommands[k] = v
} }
} }
for _, v := range localCommands {
localMap[v] = true
}
} }
// NB: when necessary, properties are described using negatives in order to // NB: when necessary, properties are described using negatives in order to

View File

@ -92,6 +92,7 @@ func mainRet() int {
os.Args[0] = "ipfs" os.Args[0] = "ipfs"
buildEnv := func(ctx context.Context, req *cmds.Request) (cmds.Environment, error) { buildEnv := func(ctx context.Context, req *cmds.Request) (cmds.Environment, error) {
checkDebug(req)
repoPath, err := getRepoPath(req) repoPath, err := getRepoPath(req)
if err != nil { if err != nil {
return nil, err return nil, err
@ -151,12 +152,7 @@ func checkDebug(req *cmds.Request) {
} }
func makeExecutor(req *cmds.Request, env interface{}) (cmds.Executor, error) { func makeExecutor(req *cmds.Request, env interface{}) (cmds.Executor, error) {
checkDebug(req) details := commandDetails(req.Path)
details, err := commandDetails(req.Path, Root)
if err != nil {
return nil, err
}
client, err := commandShouldRunOnDaemon(*details, req, env.(*oldcmds.Context)) client, err := commandShouldRunOnDaemon(*details, req, env.(*oldcmds.Context))
if err != nil { if err != nil {
return nil, err return nil, err
@ -200,25 +196,16 @@ func checkPermissions(path string) (bool, error) {
return true, nil return true, nil
} }
// commandDetails returns a command's details for the command given by |path| // commandDetails returns a command's details for the command given by |path|.
// within the |root| command tree. func commandDetails(path []string) *cmdDetails {
//
// Returns an error if the command is not found in the Command tree.
func commandDetails(path []string, root *cmds.Command) (*cmdDetails, error) {
var details cmdDetails var details cmdDetails
// find the last command in path that has a cmdDetailsMap entry // find the last command in path that has a cmdDetailsMap entry
cmd := root for i := range path {
for _, cmp := range path { if cmdDetails, found := cmdDetailsMap[strings.Join(path[:i+1], "/")]; found {
cmd = cmd.Subcommands[cmp]
if cmd == nil {
return nil, fmt.Errorf("subcommand %s should be in root", cmp)
}
if cmdDetails, found := cmdDetailsMap[strings.Join(path, "/")]; found {
details = cmdDetails details = cmdDetails
} }
} }
return &details, nil return &details
} }
// commandShouldRunOnDaemon determines, from command details, whether a // commandShouldRunOnDaemon determines, from command details, whether a
@ -318,7 +305,7 @@ func startProfiling() (func(), error) {
stopProfiling := func() { stopProfiling := func() {
pprof.StopCPUProfile() pprof.StopCPUProfile()
defer ofi.Close() // captured by the closure ofi.Close() // captured by the closure
} }
return stopProfiling, nil return stopProfiling, nil
} }

View File

@ -597,12 +597,7 @@ func (n *IpfsNode) teardown() error {
// OnlineMode returns whether or not the IpfsNode is in OnlineMode. // OnlineMode returns whether or not the IpfsNode is in OnlineMode.
func (n *IpfsNode) OnlineMode() bool { func (n *IpfsNode) OnlineMode() bool {
switch n.mode { return n.mode == onlineMode
case onlineMode:
return true
default:
return false
}
} }
// SetLocal will set the IpfsNode to local mode // SetLocal will set the IpfsNode to local mode
@ -619,17 +614,11 @@ func (n *IpfsNode) LocalMode() bool {
// programmer error should not happen // programmer error should not happen
panic("local mode not set") panic("local mode not set")
} }
switch n.mode { return n.mode == localMode
case localMode:
return true
default:
return false
}
} }
// Bootstrap will set and call the IpfsNodes bootstrap function. // Bootstrap will set and call the IpfsNodes bootstrap function.
func (n *IpfsNode) Bootstrap(cfg BootstrapConfig) error { func (n *IpfsNode) Bootstrap(cfg BootstrapConfig) error {
// TODO what should return value be when in offlineMode? // TODO what should return value be when in offlineMode?
if n.Routing == nil { if n.Routing == nil {
return nil return nil