use helper
This commit is contained in:
parent
8c1573642d
commit
52fa3396e7
|
@ -142,12 +142,8 @@ func (c *AllocStatusCommand) Run(args []string) int {
|
|||
c.Ui.Error(fmt.Sprintf("Identifier must contain at least two characters."))
|
||||
return 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]
|
||||
}
|
||||
|
||||
allocID = sanatizeUUIDPrefix(allocID)
|
||||
allocs, _, err := client.Allocations().PrefixList(allocID)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error querying allocation: %v", err))
|
||||
|
|
|
@ -130,12 +130,8 @@ func (c *EvalStatusCommand) Run(args []string) int {
|
|||
c.Ui.Error(fmt.Sprintf("Identifier must contain at least two characters."))
|
||||
return 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]
|
||||
}
|
||||
|
||||
evalID = sanatizeUUIDPrefix(evalID)
|
||||
evals, _, err := client.Evaluations().PrefixList(evalID)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error querying evaluation: %v", err))
|
||||
|
|
|
@ -169,12 +169,8 @@ func (f *FSCommand) Run(args []string) int {
|
|||
f.Ui.Error(fmt.Sprintf("Alloc ID must contain at least two characters."))
|
||||
return 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]
|
||||
}
|
||||
|
||||
allocID = sanatizeUUIDPrefix(allocID)
|
||||
allocs, _, err := client.Allocations().PrefixList(allocID)
|
||||
if err != nil {
|
||||
f.Ui.Error(fmt.Sprintf("Error querying allocation: %v", err))
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
gg "github.com/hashicorp/go-getter"
|
||||
|
@ -330,3 +331,13 @@ func mergeAutocompleteFlags(flags ...complete.Flags) complete.Flags {
|
|||
}
|
||||
return merged
|
||||
}
|
||||
|
||||
// sanatizeUUIDPrefix is used to sanatize a UUID prefix. The returned result
|
||||
// will be a truncated version of the prefix if the prefix would not be
|
||||
// queriable.
|
||||
func sanatizeUUIDPrefix(prefix string) string {
|
||||
hyphens := strings.Count(prefix, "-")
|
||||
length := len(prefix) - hyphens
|
||||
remainder := length % 2
|
||||
return prefix[:len(prefix)-remainder]
|
||||
}
|
||||
|
|
|
@ -144,12 +144,8 @@ func (l *LogsCommand) Run(args []string) int {
|
|||
l.Ui.Error(fmt.Sprintf("Alloc ID must contain at least two characters."))
|
||||
return 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]
|
||||
}
|
||||
|
||||
allocID = sanatizeUUIDPrefix(allocID)
|
||||
allocs, _, err := client.Allocations().PrefixList(allocID)
|
||||
if err != nil {
|
||||
l.Ui.Error(fmt.Sprintf("Error querying allocation: %v", err))
|
||||
|
|
|
@ -194,12 +194,8 @@ func (m *monitor) monitor(evalID string, allowPrefix bool) int {
|
|||
m.ui.Error(fmt.Sprintf("Identifier must contain at least two characters."))
|
||||
return 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]
|
||||
}
|
||||
|
||||
evalID = sanatizeUUIDPrefix(evalID)
|
||||
evals, _, err := m.client.Evaluations().PrefixList(evalID)
|
||||
if err != nil {
|
||||
m.ui.Error(fmt.Sprintf("Error reading evaluation: %s", err))
|
||||
|
|
|
@ -117,12 +117,8 @@ func (c *NodeDrainCommand) Run(args []string) int {
|
|||
c.Ui.Error(fmt.Sprintf("Identifier must contain at least two characters."))
|
||||
return 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]
|
||||
}
|
||||
|
||||
nodeID = sanatizeUUIDPrefix(nodeID)
|
||||
nodes, _, err := client.Nodes().PrefixList(nodeID)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error toggling drain mode: %s", err))
|
||||
|
|
|
@ -231,12 +231,8 @@ func (c *NodeStatusCommand) Run(args []string) int {
|
|||
c.Ui.Error(fmt.Sprintf("Identifier must contain at least two characters."))
|
||||
return 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]
|
||||
}
|
||||
|
||||
nodeID = sanatizeUUIDPrefix(nodeID)
|
||||
nodes, _, err := client.Nodes().PrefixList(nodeID)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error querying node info: %s", err))
|
||||
|
|
Loading…
Reference in New Issue