Skip to content

Commit

Permalink
commands: deprecate --local for --offline
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
  • Loading branch information
magik6k committed Dec 12, 2018
1 parent 87add51 commit 7ddb45f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
3 changes: 1 addition & 2 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
ipnsMountKwd = "mount-ipns"
migrateKwd = "migrate"
mountKwd = "mount"
offlineKwd = "offline"
offlineKwd = "offline" // global option
routingOptionKwd = "routing"
routingOptionSupernodeKwd = "supernode"
routingOptionDHTClientKwd = "dhtclient"
Expand Down Expand Up @@ -161,7 +161,6 @@ Headers.
cmdkit.BoolOption(unencryptTransportKwd, "Disable transport encryption (for debugging protocols)"),
cmdkit.BoolOption(enableGCKwd, "Enable automatic periodic repo garbage collection"),
cmdkit.BoolOption(adjustFDLimitKwd, "Check and raise file descriptor limits if needed").WithDefault(true),
cmdkit.BoolOption(offlineKwd, "Run offline. Do not connect to the rest of the network but provide local API."),
cmdkit.BoolOption(migrateKwd, "If true, assume yes at the migrate prompt. If false, assume no."),
cmdkit.BoolOption(enablePubSubKwd, "Instantiate the ipfs daemon with the experimental pubsub feature enabled."),
cmdkit.BoolOption(enableIPNSPubSubKwd, "Enable IPNS record distribution through pubsub; enables pubsub."),
Expand Down
16 changes: 13 additions & 3 deletions core/commands/cmdenv/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmdenv

import (
"fmt"
"strings"

"github.com/ipfs/go-ipfs/commands"
"github.com/ipfs/go-ipfs/core"
Expand All @@ -10,8 +11,11 @@ import (

config "gx/ipfs/QmYyzmMnhNTtoXx5ttgUaRdHHckYnQWjPL98hgLAR2QLDD/go-ipfs-config"
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log"
)

var log = logging.Logger("core/commands/cmdenv")

// GetNode extracts the node from the environment.
func GetNode(env interface{}) (*core.IpfsNode, error) {
ctx, ok := env.(*commands.Context)
Expand All @@ -29,13 +33,19 @@ func GetApi(env cmds.Environment, req *cmds.Request) (coreiface.CoreAPI, error)
return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env)
}

local, _ := req.Options["local"].(bool)
offline, _ := req.Options["offline"].(bool)
if !offline {
offline, _ = req.Options["local"].(bool)
if offline {
log.Errorf("Command '%s', --local is deprecated, use --offline instead", strings.Join(req.Path, " "))
}
}
api, err := ctx.GetAPI()
if err != nil {
return nil, err
}
if local {
return api.WithOptions(options.Api.Offline(local))
if offline {
return api.WithOptions(options.Api.Offline(offline))
}

return api, nil
Expand Down
12 changes: 7 additions & 5 deletions core/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ var log = logging.Logger("core/commands")
var ErrNotOnline = errors.New("this command must be run in online mode. Try running 'ipfs daemon' first")

const (
ConfigOption = "config"
DebugOption = "debug"
LocalOption = "local"
ApiOption = "api"
ConfigOption = "config"
DebugOption = "debug"
LocalOption = "local" // DEPRECATED: use OfflineOption
OfflineOption = "offline"
ApiOption = "api"
)

var Root = &cmds.Command{
Expand Down Expand Up @@ -92,7 +93,8 @@ The CLI will exit with one of the following values:
cmdkit.BoolOption(DebugOption, "D", "Operate in debug mode."),
cmdkit.BoolOption(cmds.OptLongHelp, "Show the full command help text."),
cmdkit.BoolOption(cmds.OptShortHelp, "Show a short version of the command help text."),
cmdkit.BoolOption(LocalOption, "L", "Run the command locally, instead of using the daemon."),
cmdkit.BoolOption(LocalOption, "L", "Run the command locally, instead of using the daemon. DEPRECATED: use --offline."),
cmdkit.BoolOption(OfflineOption, "O", "Run the command offline."),
cmdkit.StringOption(ApiOption, "Use a specific API instance (defaults to /ip4/127.0.0.1/tcp/5001)"),

// global options, added to every command
Expand Down
2 changes: 1 addition & 1 deletion core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ type IpfsNode struct {

proc goprocess.Process
ctx context.Context
lk sync.RWMutex // only for things that change fields here, like SetupOfflineRouting
lk sync.RWMutex // only for things that change fields here, like SetupOfflineRouting

mode mode
localModeSet bool
Expand Down

0 comments on commit 7ddb45f

Please sign in to comment.