commands: deprecate --local for --offline
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Dec 12, 2018 at 13:00 UTC
2dceb0925886e22894c9a40779360313ed26fd35
3 files changed
+21
-10
cmd/ipfs/daemon.go
+1
-2
@@ -40,7 +40,7 @@ const (
40
ipnsMountKwd = "mount-ipns"
41
migrateKwd = "migrate"
42
mountKwd = "mount"
43
- offlineKwd = "offline"
43
+ offlineKwd = "offline" // global option
44
routingOptionKwd = "routing"
45
routingOptionSupernodeKwd = "supernode"
46
routingOptionDHTClientKwd = "dhtclient"
@@ -161,7 +161,6 @@ Headers.
161
cmdkit.BoolOption(unencryptTransportKwd, "Disable transport encryption (for debugging protocols)"),
162
cmdkit.BoolOption(enableGCKwd, "Enable automatic periodic repo garbage collection"),
163
cmdkit.BoolOption(adjustFDLimitKwd, "Check and raise file descriptor limits if needed").WithDefault(true),
164
- cmdkit.BoolOption(offlineKwd, "Run offline. Do not connect to the rest of the network but provide local API."),
164
cmdkit.BoolOption(migrateKwd, "If true, assume yes at the migrate prompt. If false, assume no."),
165
cmdkit.BoolOption(enablePubSubKwd, "Instantiate the ipfs daemon with the experimental pubsub feature enabled."),
166
cmdkit.BoolOption(enableIPNSPubSubKwd, "Enable IPNS record distribution through pubsub; enables pubsub."),
core/commands/cmdenv/env.go
+13
-3
@@ -2,6 +2,7 @@ package cmdenv
2
3
import (
4
"fmt"
5
+ "strings"
6
7
"github.com/ipfs/go-ipfs/commands"
8
"github.com/ipfs/go-ipfs/core"
@@ -10,8 +11,11 @@ import (
11
12
config "gx/ipfs/QmYyzmMnhNTtoXx5ttgUaRdHHckYnQWjPL98hgLAR2QLDD/go-ipfs-config"
13
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
14
+ logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log"
15
)
16
17
+var log = logging.Logger("core/commands/cmdenv")
18
+
19
// GetNode extracts the node from the environment.
20
func GetNode(env interface{}) (*core.IpfsNode, error) {
21
ctx, ok := env.(*commands.Context)
@@ -29,13 +33,19 @@ func GetApi(env cmds.Environment, req *cmds.Request) (coreiface.CoreAPI, error)
33
return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env)
34
}
35
32
- local, _ := req.Options["local"].(bool)
36
+ offline, _ := req.Options["offline"].(bool)
37
+ if !offline {
38
+ offline, _ = req.Options["local"].(bool)
39
+ if offline {
40
+ log.Errorf("Command '%s', --local is deprecated, use --offline instead", strings.Join(req.Path, " "))
41
+ }
42
+ }
43
api, err := ctx.GetAPI()
44
if err != nil {
45
return nil, err
46
}
37
- if local {
38
- return api.WithOptions(options.Api.Offline(local))
47
+ if offline {
48
+ return api.WithOptions(options.Api.Offline(offline))
49
}
50
51
return api, nil
core/commands/root.go
+7
-5
@@ -18,10 +18,11 @@ var log = logging.Logger("core/commands")
18
var ErrNotOnline = errors.New("this command must be run in online mode. Try running 'ipfs daemon' first")
19
20
const (
21
- ConfigOption = "config"
22
- DebugOption = "debug"
23
- LocalOption = "local"
24
- ApiOption = "api"
21
+ ConfigOption = "config"
22
+ DebugOption = "debug"
23
+ LocalOption = "local" // DEPRECATED: use OfflineOption
24
+ OfflineOption = "offline"
25
+ ApiOption = "api"
26
)
27
28
var Root = &cmds.Command{
@@ -92,7 +93,8 @@ The CLI will exit with one of the following values:
93
cmdkit.BoolOption(DebugOption, "D", "Operate in debug mode."),
94
cmdkit.BoolOption(cmds.OptLongHelp, "Show the full command help text."),
95
cmdkit.BoolOption(cmds.OptShortHelp, "Show a short version of the command help text."),
95
- cmdkit.BoolOption(LocalOption, "L", "Run the command locally, instead of using the daemon."),
96
+ cmdkit.BoolOption(LocalOption, "L", "Run the command locally, instead of using the daemon. DEPRECATED: use --offline."),
97
+ cmdkit.BoolOption(OfflineOption, "O", "Run the command offline."),
98
cmdkit.StringOption(ApiOption, "Use a specific API instance (defaults to /ip4/127.0.0.1/tcp/5001)"),
99
100
// global options, added to every command