From 7ddb45fcca4e020058e02f892852db2f51f428e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 12 Dec 2018 13:00:47 +0100 Subject: [PATCH] commands: deprecate --local for --offline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit License: MIT Signed-off-by: Ɓukasz Magiera --- cmd/ipfs/daemon.go | 3 +-- core/commands/cmdenv/env.go | 16 +++++++++++++--- core/commands/root.go | 12 +++++++----- core/core.go | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index 1bf68ab37ff..f003bd9e920 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -40,7 +40,7 @@ const ( ipnsMountKwd = "mount-ipns" migrateKwd = "migrate" mountKwd = "mount" - offlineKwd = "offline" + offlineKwd = "offline" // global option routingOptionKwd = "routing" routingOptionSupernodeKwd = "supernode" routingOptionDHTClientKwd = "dhtclient" @@ -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."), diff --git a/core/commands/cmdenv/env.go b/core/commands/cmdenv/env.go index 57442f483ee..1e6b6b2121b 100644 --- a/core/commands/cmdenv/env.go +++ b/core/commands/cmdenv/env.go @@ -2,6 +2,7 @@ package cmdenv import ( "fmt" + "strings" "github.com/ipfs/go-ipfs/commands" "github.com/ipfs/go-ipfs/core" @@ -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) @@ -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 diff --git a/core/commands/root.go b/core/commands/root.go index 1ce7721e904..75328cb207b 100644 --- a/core/commands/root.go +++ b/core/commands/root.go @@ -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{ @@ -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 diff --git a/core/core.go b/core/core.go index 7f04659f062..cfabad1c81b 100644 --- a/core/core.go +++ b/core/core.go @@ -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