]> ruderich.org/simon Gitweb - linux-network-namespace-labs/linux-network-namespace-labs.git/commitdiff
Permit arbitrary whitespace between fields in config file
authorSimon Ruderich <simon@ruderich.org>
Fri, 1 Nov 2024 08:49:38 +0000 (09:49 +0100)
committerSimon Ruderich <simon@ruderich.org>
Fri, 1 Nov 2024 08:49:38 +0000 (09:49 +0100)
config.go

index ab29d16a48a5256d20143c7a31123d51f37f3852..afff143aa36760a074ef6c830b7d38cd89578854 100644 (file)
--- a/config.go
+++ b/config.go
@@ -81,7 +81,7 @@ func LoadConfig(path string) (*Config, error) {
 
                var err error
                var usage string
-               xs := strings.Split(l, " ")
+               xs := strings.Fields(l)
                switch xs[0] {
                case "net":
                        usage = `"net" <name> <prefix>...`
@@ -94,7 +94,8 @@ func LoadConfig(path string) (*Config, error) {
                        err = parseConfigLink(&cfg, xs[1:])
                case "cmd":
                        usage = `"cmd" <string-passed-to-sh-c>`
-                       err = parseConfigCmd(&cfg, xs[1:])
+                       x := strings.TrimSpace(strings.TrimPrefix(l, "cmd"))
+                       err = parseConfigCmd(&cfg, x)
                default:
                        usage = `"net" | "node" | "link" | "cmd"`
                        err = fmt.Errorf("unknown option %q", xs[0])
@@ -222,12 +223,12 @@ func parseConfigLink(cfg *Config, args []string) error {
        return nil
 }
 
-func parseConfigCmd(cfg *Config, args []string) error {
-       if len(args) < 1 {
+func parseConfigCmd(cfg *Config, cmd string) error {
+       if len(cmd) == 0 {
                return fmt.Errorf("not enough arguments")
        }
 
-       cfg.Cmds = append(cfg.Cmds, strings.Join(args, " "))
+       cfg.Cmds = append(cfg.Cmds, cmd)
        return nil
 }