From 8c1573642d6bb6e69d78dc0a8ad824399b29961d Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 29 Aug 2017 09:43:28 -0700 Subject: [PATCH] status commands handle uuid prefixes with hyphens --- command/alloc_status.go | 2 +- command/eval_status.go | 2 +- command/fs.go | 2 +- command/logs.go | 2 +- command/monitor.go | 2 +- command/node_drain.go | 2 +- command/node_status.go | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/command/alloc_status.go b/command/alloc_status.go index 20987b16d..86ef62d4c 100644 --- a/command/alloc_status.go +++ b/command/alloc_status.go @@ -142,7 +142,7 @@ func (c *AllocStatusCommand) Run(args []string) int { c.Ui.Error(fmt.Sprintf("Identifier must contain at least two characters.")) return 1 } - if len(allocID)%2 == 1 { + if hyphens := strings.Count(allocID, "-"); (len(allocID)-hyphens)%2 == 1 { // Identifiers must be of even length, so we strip off the last byte // to provide a consistent user experience. allocID = allocID[:len(allocID)-1] diff --git a/command/eval_status.go b/command/eval_status.go index 33b3d2cdd..1a687a0a2 100644 --- a/command/eval_status.go +++ b/command/eval_status.go @@ -130,7 +130,7 @@ func (c *EvalStatusCommand) Run(args []string) int { c.Ui.Error(fmt.Sprintf("Identifier must contain at least two characters.")) return 1 } - if len(evalID)%2 == 1 { + if hyphens := strings.Count(evalID, "-"); (len(evalID)-hyphens)%2 == 1 { // Identifiers must be of even length, so we strip off the last byte // to provide a consistent user experience. evalID = evalID[:len(evalID)-1] diff --git a/command/fs.go b/command/fs.go index e9c0df6a4..2b8111d9b 100644 --- a/command/fs.go +++ b/command/fs.go @@ -169,7 +169,7 @@ func (f *FSCommand) Run(args []string) int { f.Ui.Error(fmt.Sprintf("Alloc ID must contain at least two characters.")) return 1 } - if len(allocID)%2 == 1 { + if hyphens := strings.Count(allocID, "-"); (len(allocID)-hyphens)%2 == 1 { // Identifiers must be of even length, so we strip off the last byte // to provide a consistent user experience. allocID = allocID[:len(allocID)-1] diff --git a/command/logs.go b/command/logs.go index 36b5c9740..d2797864d 100644 --- a/command/logs.go +++ b/command/logs.go @@ -144,7 +144,7 @@ func (l *LogsCommand) Run(args []string) int { l.Ui.Error(fmt.Sprintf("Alloc ID must contain at least two characters.")) return 1 } - if len(allocID)%2 == 1 { + if hyphens := strings.Count(allocID, "-"); (len(allocID)-hyphens)%2 == 1 { // Identifiers must be of even length, so we strip off the last byte // to provide a consistent user experience. allocID = allocID[:len(allocID)-1] diff --git a/command/monitor.go b/command/monitor.go index ef0287071..92642d867 100644 --- a/command/monitor.go +++ b/command/monitor.go @@ -194,7 +194,7 @@ func (m *monitor) monitor(evalID string, allowPrefix bool) int { m.ui.Error(fmt.Sprintf("Identifier must contain at least two characters.")) return 1 } - if len(evalID)%2 == 1 { + if hyphens := strings.Count(evalID, "-"); (len(evalID)-hyphens)%2 == 1 { // Identifiers must be of even length, so we strip off the last byte // to provide a consistent user experience. evalID = evalID[:len(evalID)-1] diff --git a/command/node_drain.go b/command/node_drain.go index 6d1e7410b..61ddd5c36 100644 --- a/command/node_drain.go +++ b/command/node_drain.go @@ -117,7 +117,7 @@ func (c *NodeDrainCommand) Run(args []string) int { c.Ui.Error(fmt.Sprintf("Identifier must contain at least two characters.")) return 1 } - if len(nodeID)%2 == 1 { + if hyphens := strings.Count(nodeID, "-"); (len(nodeID)-hyphens)%2 == 1 { // Identifiers must be of even length, so we strip off the last byte // to provide a consistent user experience. nodeID = nodeID[:len(nodeID)-1] diff --git a/command/node_status.go b/command/node_status.go index 34dd1dbec..22cbcef19 100644 --- a/command/node_status.go +++ b/command/node_status.go @@ -231,7 +231,7 @@ func (c *NodeStatusCommand) Run(args []string) int { c.Ui.Error(fmt.Sprintf("Identifier must contain at least two characters.")) return 1 } - if len(nodeID)%2 == 1 { + if hyphens := strings.Count(nodeID, "-"); (len(nodeID)-hyphens)%2 == 1 { // Identifiers must be of even length, so we strip off the last byte // to provide a consistent user experience. nodeID = nodeID[:len(nodeID)-1]