Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
Make adding --dc and --wait-index variables a bit clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisAubuchon committed Jul 24, 2015
1 parent ef885c6 commit 4b0a864
Show file tree
Hide file tree
Showing 39 changed files with 107 additions and 72 deletions.
2 changes: 1 addition & 1 deletion command/acl_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Options:
}

func (c *ACLCloneCommand) Run(args []string) int {
flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.Usage = func() { c.UI.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion command/acl_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *ACLCreateCommand) Run(args []string) int {
var isManagement bool
var aclName string

flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.StringVar(&aclName, "name", "", "")
flags.BoolVar(&isManagement, "management", false, "")
flags.Var((funcVar)(func(s string) error {
Expand Down
2 changes: 1 addition & 1 deletion command/acl_destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Options:
}

func (c *ACLDestroyCommand) Run(args []string) int {
flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.Usage = func() { c.UI.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion command/acl_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Options:
}

func (c *ACLInfoCommand) Run(args []string) int {
flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.Usage = func() { c.UI.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion command/acl_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Options:
}

func (c *ACLListCommand) Run(args []string) int {
flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.Usage = func() { c.UI.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion command/acl_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (c *ACLUpdateCommand) Run(args []string) int {
var isManagement bool
var aclName string

flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.StringVar(&aclName, "name", "", "")
flags.BoolVar(&isManagement, "management", false, "")

Expand Down
2 changes: 1 addition & 1 deletion command/agent_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Options:
}

func (c *AgentChecksCommand) Run(args []string) int {
flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.Usage = func() { c.UI.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion command/agent_force_leave.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Options:
}

func (c *AgentForceLeaveCommand) Run(args []string) int {
flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.Usage = func() { c.UI.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion command/agent_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Options:
}

func (c *AgentJoinCommand) Run(args []string) int {
flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.BoolVar(&c.joinWAN, "wan", false, "")
flags.Usage = func() { c.UI.Output(c.Help()) }

Expand Down
2 changes: 1 addition & 1 deletion command/agent_maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Options:
}

func (c *AgentMaintenanceCommand) Run(args []string) int {
flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.BoolVar(&c.enabled, "enabled", true, "")
flags.StringVar(&c.reason, "reason", "", "")
flags.Usage = func() { c.UI.Output(c.Help()) }
Expand Down
2 changes: 1 addition & 1 deletion command/agent_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Options:
}

func (c *AgentMembersCommand) Run(args []string) int {
flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.BoolVar(&c.wanFlag, "wan", false, "")
flags.Usage = func() { c.UI.Output(c.Help()) }

Expand Down
2 changes: 1 addition & 1 deletion command/agent_self.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Options:
}

func (c *AgentSelfCommand) Run(args []string) int {
flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.Usage = func() { c.UI.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion command/agent_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Options:
}

func (c *AgentServicesCommand) Run(args []string) int {
flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.Usage = func() { c.UI.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion command/check_deregister.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Options:
}

func (c *CheckDeregisterCommand) Run(args []string) int {
flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.Usage = func() { c.UI.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion command/check_fail.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Options:
}

func (c *CheckFailCommand) Run(args []string) int {
flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.StringVar(&c.note, "note", "", "")
flags.Usage = func() { c.UI.Output(c.Help()) }

Expand Down
2 changes: 1 addition & 1 deletion command/check_pass.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Options:
}

func (c *CheckPassCommand) Run(args []string) int {
flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.StringVar(&c.note, "note", "", "")
flags.Usage = func() { c.UI.Output(c.Help()) }

Expand Down
2 changes: 1 addition & 1 deletion command/check_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Options:
}

func (c *CheckRegisterCommand) Run(args []string) int {
flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.StringVar(&c.id, "id", "", "")
flags.StringVar(&c.http, "http", "", "")
flags.StringVar(&c.script, "script", "", "")
Expand Down
2 changes: 1 addition & 1 deletion command/check_warn.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Options:
}

func (c *CheckWarnCommand) Run(args []string) int {
flags := c.Meta.FlagSet(false)
flags := c.Meta.FlagSet()
flags.StringVar(&c.note, "note", "", "")
flags.Usage = func() { c.UI.Output(c.Help()) }

Expand Down
3 changes: 2 additions & 1 deletion command/health_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Options:
}

func (c *HealthChecksCommand) Run(args []string) int {
flags := c.Meta.FlagSet(true)
c.AddDataCenter()
flags := c.Meta.FlagSet()
flags.Usage = func() { c.UI.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion command/health_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Options:
}

func (c *HealthNodeCommand) Run(args []string) int {
flags := c.Meta.FlagSet(true)
c.AddDataCenter()
flags := c.Meta.FlagSet()
flags.Usage = func() { c.UI.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion command/health_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Options:
}

func (c *HealthServiceCommand) Run(args []string) int {
flags := c.Meta.FlagSet(true)
c.AddDataCenter()
flags := c.Meta.FlagSet()
flags.StringVar(&c.tag, "tag", "", "")
flags.BoolVar(&c.passingOnly, "passing", false, "")
flags.Usage = func() { c.UI.Output(c.Help()) }
Expand Down
3 changes: 2 additions & 1 deletion command/health_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Options:
}

func (c *HealthStateCommand) Run(args []string) int {
flags := c.Meta.FlagSet(true)
c.AddDataCenter()
flags := c.Meta.FlagSet()
flags.Usage = func() { c.UI.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
Expand Down
18 changes: 9 additions & 9 deletions command/kv_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

type KVDeleteCommand struct {
Meta
modifyIndex string
doRecurse bool
}

func (c *KVDeleteCommand) Help() string {
Expand All @@ -30,12 +32,10 @@ Options:
}

func (c *KVDeleteCommand) Run (args[]string) int {
var modifyIndex string
var doRecurse bool

flags := c.Meta.FlagSet(true)
flags.StringVar(&modifyIndex, "modifyindex", "", "")
flags.BoolVar(&doRecurse, "recurse", false, "")
c.AddDataCenter()
flags := c.Meta.FlagSet()
flags.StringVar(&c.modifyIndex, "modifyindex", "", "")
flags.BoolVar(&c.doRecurse, "recurse", false, "")
flags.Usage = func() { c.UI.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
Expand All @@ -62,14 +62,14 @@ func (c *KVDeleteCommand) Run (args[]string) int {
writeOpts := c.WriteOptions()

switch {
case doRecurse:
case c.doRecurse:
_, err := client.DeleteTree(path, writeOpts)
if err != nil {
c.UI.Error(err.Error())
return 1
}
case modifyIndex != "":
m, err := strconv.ParseUint(modifyIndex, 0, 64)
case c.modifyIndex != "":
m, err := strconv.ParseUint(c.modifyIndex, 0, 64)
if err != nil {
c.UI.Error(err.Error())
return 1
Expand Down
3 changes: 2 additions & 1 deletion command/kv_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func (c *KVLockCommand) Run(args []string) int {

c.cleanSession = false

flags := c.Meta.FlagSet(true)
c.AddDataCenter()
flags := c.Meta.FlagSet()
flags.StringVar(&c.behavior, "behavior", "release", "")
flags.StringVar(&c.ttl, "ttl", "", "")
flags.DurationVar(&c.lockDelay, "lock-delay", time.Second * 15, "")
Expand Down
29 changes: 15 additions & 14 deletions command/kv_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (

type KVReadCommand struct {
Meta
format OutputFormat
fieldsRaw string
recurse bool
}

func (c *KVReadCommand) Help() string {
Expand Down Expand Up @@ -33,16 +36,14 @@ Options:
}

func (c *KVReadCommand) Run(args []string) int {
var format OutputFormat
var fieldsRaw string
var recurse bool

flags := c.Meta.FlagSet(true)
flags.StringVar(&fieldsRaw, "fields", "value", "")
flags.StringVar(&format.Type, "format", "text", "")
flags.StringVar(&format.Delimiter, "delimiter", " ", "")
flags.BoolVar(&format.Header, "header", false, "")
flags.BoolVar(&recurse, "recurse", false, "")
c.AddDataCenter()

flags := c.Meta.FlagSet()
flags.StringVar(&c.fieldsRaw, "fields", "value", "")
flags.StringVar(&c.format.Type, "format", "text", "")
flags.StringVar(&c.format.Delimiter, "delimiter", " ", "")
flags.BoolVar(&c.format.Header, "header", false, "")
flags.BoolVar(&c.recurse, "recurse", false, "")
flags.Usage = func() { c.UI.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
Expand All @@ -68,9 +69,9 @@ func (c *KVReadCommand) Run(args []string) int {

queryOpts := c.QueryOptions()

kvo := NewKVOutput(c.UI, fieldsRaw)
kvo := NewKVOutput(c.UI, c.fieldsRaw)

if recurse {
if c.recurse {
kvlist, _, err := client.List(path, queryOpts)
if err != nil {
c.UI.Error(err.Error())
Expand All @@ -81,7 +82,7 @@ func (c *KVReadCommand) Run(args []string) int {
return 0
}

kvo.OutputList(&kvlist, format)
kvo.OutputList(&kvlist, c.format)
} else {
kv, _, err := client.Get(path, queryOpts)
if err != nil {
Expand All @@ -93,7 +94,7 @@ func (c *KVReadCommand) Run(args []string) int {
return 0
}

kvo.Output(kv, format)
kvo.Output(kv, c.format)
}

return 0
Expand Down
3 changes: 2 additions & 1 deletion command/kv_unlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Options:
}

func (c *KVUnlockCommand) Run(args []string) int {
flags := c.Meta.FlagSet(true)
c.AddDataCenter()
flags := c.Meta.FlagSet()
flags.StringVar(&c.session, "session", "", "")
flags.BoolVar(&c.noDestroy, "no-destroy", false, "")
flags.Usage = func() { c.UI.Output(c.Help()) }
Expand Down
24 changes: 12 additions & 12 deletions command/kv_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

type KVWriteCommand struct {
Meta
modifyIndex string
dataFlags string
}

func (c *KVWriteCommand) Help() string {
Expand All @@ -31,12 +33,10 @@ Options:
}

func (c *KVWriteCommand) Run(args []string) int {
var modifyIndex string
var dataFlags string

flags := c.Meta.FlagSet(true)
flags.StringVar(&modifyIndex, "cas", "", "")
flags.StringVar(&dataFlags, "flags", "", "")
c.AddDataCenter()
flags := c.Meta.FlagSet()
flags.StringVar(&c.modifyIndex, "cas", "", "")
flags.StringVar(&c.dataFlags, "flags", "", "")
flags.Usage = func() { c.UI.Output(c.Help()) }

if err := flags.Parse(args); err != nil {
Expand Down Expand Up @@ -70,10 +70,10 @@ func (c *KVWriteCommand) Run(args []string) int {

// &flags=
//
if dataFlags != "" {
f, err := strconv.ParseUint(dataFlags, 0, 64)
if c.dataFlags != "" {
f, err := strconv.ParseUint(c.dataFlags, 0, 64)
if err != nil {
c.UI.Error(fmt.Sprintf("Error parsing flags: %v", dataFlags))
c.UI.Error(fmt.Sprintf("Error parsing flags: %v", c.dataFlags))
c.UI.Error("")
return 1
}
Expand All @@ -89,17 +89,17 @@ func (c *KVWriteCommand) Run(args []string) int {

writeOpts := c.WriteOptions()

if modifyIndex == "" {
if c.modifyIndex == "" {
_, err := client.Put(kv, writeOpts)
if err != nil {
c.UI.Error(err.Error())
return 1
}
} else {
// Check-and-Set
i, err := strconv.ParseUint(modifyIndex, 0, 64)
i, err := strconv.ParseUint(c.modifyIndex, 0, 64)
if err != nil {
c.UI.Error(fmt.Sprintf("Error parsing modifyIndex: %v", modifyIndex))
c.UI.Error(fmt.Sprintf("Error parsing modifyIndex: %v", c.modifyIndex))
c.UI.Error("")
return 1
}
Expand Down
Loading

0 comments on commit 4b0a864

Please sign in to comment.