From 0e484d25c3e7afc1ad72fda55da881b5bb019b0c Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Fri, 1 Nov 2024 09:49:38 +0100 Subject: [PATCH] Permit arbitrary whitespace between fields in config file --- config.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/config.go b/config.go index ab29d16..afff143 100644 --- 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" ...` @@ -94,7 +94,8 @@ func LoadConfig(path string) (*Config, error) { err = parseConfigLink(&cfg, xs[1:]) case "cmd": usage = `"cmd" ` - 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 } -- 2.45.2