@cryptotaxi247 / kubo / commits / ed8817961

conifg-patch: apply review

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Sep 22, 2017 at 00:13 UTC ed8817961ec723af89aad5403d968f1be97831b3
2 files changed +8 -8
core/commands/config.go
+4 -8
@@ -313,11 +313,9 @@ var configProfileApplyCmd = &cmds.Command{
313 cmds.StringArg("profile", true, false, "The profile to apply to the config."),
314 },
315 Run: func(req cmds.Request, res cmds.Response) {
316 - args := req.Arguments()
317 -
318 - profile, ok := config.Profiles[args[0]]
316 + profile, ok := config.Profiles[req.Arguments()[0]]
317 if !ok {
320 - res.SetError(fmt.Errorf("%s in not a profile", args[0]), cmds.ErrNormal)
318 + res.SetError(fmt.Errorf("%s is not a profile", req.Arguments()[0]), cmds.ErrNormal)
319 return
320 }
321
@@ -341,11 +339,9 @@ Backing up the config before running this command is advised.`,
339 cmds.StringArg("profile", true, false, "The profile to apply to the config."),
340 },
341 Run: func(req cmds.Request, res cmds.Response) {
344 - args := req.Arguments()
345 -
346 - profile, ok := config.Profiles[args[0]]
342 + profile, ok := config.Profiles[req.Arguments()[0]]
343 if !ok {
348 - res.SetError(fmt.Errorf("%s in not a profile", args[0]), cmds.ErrNormal)
344 + res.SetError(fmt.Errorf("%s is not a profile", req.Arguments()[0]), cmds.ErrNormal)
345 return
346 }
347
repo/config/profile.go
+4
@@ -1,7 +1,9 @@
1 package config
2
3 +// Transformer is a function which takes configuration and applies some filter to it
4 type Transformer func(c *Config) error
5
6 +// Profile applies some set of changes to the configuration
7 type Profile struct {
8 Apply Transformer
9 Unapply Transformer
@@ -32,11 +34,13 @@ var Profiles = map[string]*Profile{
34 "/ip4/240.0.0.0/ipcidr/4",
35 }
36
37 + c.Addresses.NoAnnounce = append(c.Addresses.NoAnnounce, defaultServerFilters...)
38 c.Swarm.AddrFilters = append(c.Swarm.AddrFilters, defaultServerFilters...)
39 c.Discovery.MDNS.Enabled = false
40 return nil
41 },
42 Unapply: func(c *Config) error {
43 + c.Addresses.NoAnnounce = []string{}
44 c.Swarm.AddrFilters = []string{}
45 c.Discovery.MDNS.Enabled = true
46 return nil