Commit 10bad1f9 authored by Erick Hitter's avatar Erick Hitter
Browse files

Improve errors for invalid paths, as they currently don't indicate what's...

Improve errors for invalid paths, as they currently don't indicate what's wrong, just that something is wrong

Fixes #124
parent f279543b
...@@ -69,8 +69,8 @@ func init() { ...@@ -69,8 +69,8 @@ func init() {
setUpLogger() setUpLogger()
// TODO: Should check for wp-config.php instead? // TODO: Should check for wp-config.php instead?
validatePath(&wpCliPath) validatePath(&wpCliPath, "WP-CLI path")
validatePath(&wpPath) validatePath(&wpPath, "WordPress path")
} }
func main() { func main() {
...@@ -350,20 +350,22 @@ func setUpLogger() { ...@@ -350,20 +350,22 @@ func setUpLogger() {
} }
} }
func validatePath(path *string) { func validatePath(path *string, label string) {
if len(*path) > 1 { if len(*path) > 1 {
var err error var err error
*path, err = filepath.Abs(*path) *path, err = filepath.Abs(*path)
if err != nil { if err != nil {
fmt.Printf("Error: %s", err.Error()) fmt.Printf("Error for %s: %s\n", label, err.Error())
os.Exit(3) os.Exit(3)
} }
if _, err = os.Stat(*path); os.IsNotExist(err) { if _, err = os.Stat(*path); os.IsNotExist(err) {
usage() fmt.Printf("Error for %s: '%s' does not exist\n", label, *path)
os.Exit(3)
} }
} else { } else {
fmt.Printf("Empty path provided for %s\n", label)
usage() usage()
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment