Skip to content

Commit

Permalink
conifg-patch: apply review
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 Oct 6, 2017
1 parent 30d8324 commit a956439
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 4 additions & 8 deletions core/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,9 @@ var configProfileApplyCmd = &cmds.Command{
cmds.StringArg("profile", true, false, "The profile to apply to the config."),
},
Run: func(req cmds.Request, res cmds.Response) {
args := req.Arguments()

profile, ok := config.Profiles[args[0]]
profile, ok := config.Profiles[req.Arguments()[0]]
if !ok {
res.SetError(fmt.Errorf("%s in not a profile", args[0]), cmds.ErrNormal)
res.SetError(fmt.Errorf("%s is not a profile", req.Arguments()[0]), cmds.ErrNormal)
return
}

Expand All @@ -326,11 +324,9 @@ Backing up the config before running this command is advised.`,
cmds.StringArg("profile", true, false, "The profile to apply to the config."),
},
Run: func(req cmds.Request, res cmds.Response) {
args := req.Arguments()

profile, ok := config.Profiles[args[0]]
profile, ok := config.Profiles[req.Arguments()[0]]
if !ok {
res.SetError(fmt.Errorf("%s in not a profile", args[0]), cmds.ErrNormal)
res.SetError(fmt.Errorf("%s is not a profile", req.Arguments()[0]), cmds.ErrNormal)
return
}

Expand Down
4 changes: 4 additions & 0 deletions repo/config/profile.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package config

// Transformer is a function which takes configuration and applies some filter to it
type Transformer func(c *Config) error

// Profile applies some set of changes to the configuration
type Profile struct {
Apply Transformer
Unapply Transformer
Expand Down Expand Up @@ -32,11 +34,13 @@ var Profiles = map[string]*Profile{
"/ip4/240.0.0.0/ipcidr/4",
}

c.Addresses.NoAnnounce = append(c.Addresses.NoAnnounce, defaultServerFilters...)
c.Swarm.AddrFilters = append(c.Swarm.AddrFilters, defaultServerFilters...)
c.Discovery.MDNS.Enabled = false
return nil
},
Unapply: func(c *Config) error {
c.Addresses.NoAnnounce = []string{}
c.Swarm.AddrFilters = []string{}
c.Discovery.MDNS.Enabled = true
return nil
Expand Down

0 comments on commit a956439

Please sign in to comment.