|
@@ -1,6 +1,9 @@
|
|
|
package parser
|
|
|
|
|
|
-import "strings"
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "strings"
|
|
|
+)
|
|
|
|
|
|
// QuoteString walks characters (after trimming), escapes any quotes and
|
|
|
// escapes, then wraps the whole thing in quotes. Very useful for generating
|
|
@@ -66,12 +69,17 @@ func fullDispatch(cmd, args string) (*Node, map[string]bool, error) {
|
|
|
|
|
|
// splitCommand takes a single line of text and parses out the cmd and args,
|
|
|
// which are used for dispatching to more exact parsing functions.
|
|
|
-func splitCommand(line string) (string, string) {
|
|
|
+func splitCommand(line string) (string, string, error) {
|
|
|
cmdline := TOKEN_WHITESPACE.Split(line, 2)
|
|
|
+
|
|
|
+ if len(cmdline) != 2 {
|
|
|
+ return "", "", fmt.Errorf("We do not understand this file. Please ensure it is a valid Dockerfile. Parser error at %q", line)
|
|
|
+ }
|
|
|
+
|
|
|
cmd := strings.ToLower(cmdline[0])
|
|
|
// the cmd should never have whitespace, but it's possible for the args to
|
|
|
// have trailing whitespace.
|
|
|
- return cmd, strings.TrimSpace(cmdline[1])
|
|
|
+ return cmd, strings.TrimSpace(cmdline[1]), nil
|
|
|
}
|
|
|
|
|
|
// covers comments and empty lines. Lines should be trimmed before passing to
|