From 2dceb0925886e22894c9a40779360313ed26fd35 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 +++++++----- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index a1be01c6d..e4c891053 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 8a3a0779c..290239381 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/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/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 ce9fdafa1..08cd1b92e 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