From d2ee591fbfc6e0e62e3db5f99d32af595df185bc Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Fri, 9 Jun 2017 10:37:13 +0200 Subject: [PATCH] use 'c' as command receiver for simple commands --- command/info.go | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/command/info.go b/command/info.go index 2524b5caf6..33b469fc90 100644 --- a/command/info.go +++ b/command/info.go @@ -2,9 +2,10 @@ package command import ( "fmt" - "github.com/hashicorp/consul/command/base" "sort" "strings" + + "github.com/hashicorp/consul/command/base" ) // InfoCommand is a Command implementation that queries a running @@ -13,38 +14,38 @@ type InfoCommand struct { base.Command } -func (i *InfoCommand) Help() string { +func (c *InfoCommand) Help() string { helpText := ` Usage: consul info [options] Provides debugging information for operators -` + i.Command.Help() +` + c.Command.Help() return strings.TrimSpace(helpText) } -func (i *InfoCommand) Run(args []string) int { - i.Command.NewFlagSet(i) +func (c *InfoCommand) Run(args []string) int { + c.Command.NewFlagSet(c) - if err := i.Command.Parse(args); err != nil { + if err := c.Command.Parse(args); err != nil { return 1 } - client, err := i.Command.HTTPClient() + client, err := c.Command.HTTPClient() if err != nil { - i.UI.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err)) + c.UI.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err)) return 1 } self, err := client.Agent().Self() if err != nil { - i.UI.Error(fmt.Sprintf("Error querying agent: %s", err)) + c.UI.Error(fmt.Sprintf("Error querying agent: %s", err)) return 1 } stats, ok := self["Stats"] if !ok { - i.UI.Error(fmt.Sprintf("Agent response did not contain 'Stats' key: %v", self)) + c.UI.Error(fmt.Sprintf("Agent response did not contain 'Stats' key: %v", self)) return 1 } @@ -57,12 +58,12 @@ func (i *InfoCommand) Run(args []string) int { // Iterate over each top-level key for _, key := range keys { - i.UI.Output(key + ":") + c.UI.Output(key + ":") // Sort the sub-keys subvals, ok := stats[key].(map[string]interface{}) if !ok { - i.UI.Error(fmt.Sprintf("Got invalid subkey in stats: %v", subvals)) + c.UI.Error(fmt.Sprintf("Got invalid subkey in stats: %v", subvals)) return 1 } subkeys := make([]string, 0, len(subvals)) @@ -74,12 +75,12 @@ func (i *InfoCommand) Run(args []string) int { // Iterate over the subkeys for _, subkey := range subkeys { val := subvals[subkey] - i.UI.Output(fmt.Sprintf("\t%s = %s", subkey, val)) + c.UI.Output(fmt.Sprintf("\t%s = %s", subkey, val)) } } return 0 } -func (i *InfoCommand) Synopsis() string { +func (c *InfoCommand) Synopsis() string { return "Provides debugging information for operators." }