[lxc-devel] [lxd/master] init: Change validation functions for consistency
stgraber on Github
lxc-bot at linuxcontainers.org
Fri Sep 16 18:10:25 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160916/8d4d29eb/attachment.bin>
-------------- next part --------------
From 7afa69be324efd06781ff7fbb5f03518934b5b36 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 16 Sep 2016 00:13:03 -0400
Subject: [PATCH] init: Change validation functions for consistency
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/main.go | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/lxd/main.go b/lxd/main.go
index d464cfe..6673b99 100644
--- a/lxd/main.go
+++ b/lxd/main.go
@@ -673,7 +673,7 @@ func cmdInit() error {
}
}
- askString := func(question string, default_ string, validate func(string) string) string {
+ askString := func(question string, default_ string, validate func(string) error) string {
for {
fmt.Printf(question)
input, _ := reader.ReadString('\n')
@@ -683,7 +683,7 @@ func cmdInit() error {
}
if validate != nil {
result := validate(input)
- if result != "" {
+ if result != nil {
fmt.Printf("Invalid input: %s\n\n", result)
continue
}
@@ -818,11 +818,11 @@ func cmdInit() error {
if askBool("Create a new ZFS pool (yes/no) [default=yes]? ", "yes") {
storagePool = askString("Name of the new ZFS pool [default=lxd]: ", "lxd", nil)
if askBool("Would you like to use an existing block device (yes/no) [default=no]? ", "no") {
- deviceExists := func(path string) string {
+ deviceExists := func(path string) error {
if !shared.IsBlockdevPath(path) {
- return fmt.Sprintf("'%s' is not a block device", path)
+ return fmt.Errorf("'%s' is not a block device", path)
}
- return ""
+ return nil
}
storageDevice = askString("Path to the existing block device: ", "", deviceExists)
storageMode = "device"
@@ -872,11 +872,11 @@ they otherwise would.
}
if askBool("Would you like LXD to be available over the network (yes/no) [default=no]? ", "no") {
- isIPAddress := func(s string) string {
+ isIPAddress := func(s string) error {
if s != "all" && net.ParseIP(s) == nil {
- return fmt.Sprintf("'%s' is not an IP address", s)
+ return fmt.Errorf("'%s' is not an IP address", s)
}
- return ""
+ return nil
}
networkAddress = askString("Address to bind LXD to (not including port) [default=all]: ", "all", isIPAddress)
More information about the lxc-devel
mailing list