Provide a consistent user experience with prefix based lookups.

* Require at least two characters for identifier
* Automatically strip off the last character in case of uneven length
This commit is contained in:
Ivo Verberk
2016-01-21 22:21:35 +01:00
parent de3bc00a00
commit cc4fea99fc
8 changed files with 83 additions and 26 deletions

View File

@@ -110,10 +110,15 @@ func (c *NodeStatusCommand) Run(args []string) int {
nodeID := args[0]
node, _, err := client.Nodes().Info(nodeID, nil)
if err != nil {
if len(nodeID)%2 != 0 {
c.Ui.Error(fmt.Sprintf("Identifier (without hyphens) must be of even length."))
if len(nodeID) == 1 {
c.Ui.Error(fmt.Sprintf("Identifier must contain at least two characters."))
return 1
}
if len(nodeID)%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]
}
// Exact lookup failed, try with prefix based search
nodes, _, err := client.Nodes().PrefixList(nodeID)