From f44f2dcb6d191b4f307129a1cda0a7802d021bde Mon Sep 17 00:00:00 2001 From: Theo Chatzimichos Date: Fri, 8 May 2026 14:42:24 +0200 Subject: [PATCH] fix(config): Fix flag parsing with space-separated value While reviewing/testing #3 I noticed that the space-separated `--config /path/to/config.yaml` ignores the config. Reproducer: ```bash # Create a new config file go run ./cmd/crossplane --config=/tmp/xpcfg.yaml config set features.enableAlpha true # Correctly prints the full content of the config go run ./cmd/crossplane --config=/tmp/xpcfg.yaml config view # (before the fix) prints only "version: 1" ignoring the config go run ./cmd/crossplane --config /tmp/xpcfg.yaml config view ``` The problem is that `strings.TrimPrefix` returns the original string unchanged when the prefix doesn't match, so the `v != ""` check can not distinguish "prefix matched and value extracted" from "prefix not matched". For `--config /path` this makes `configFlag` return "--config" as the path instead of falling through to read the next argument. Switching to `strings.CutPrefix`, which returns an ok bool that makes the distinction clear. Signed-off-by: Theo Chatzimichos --- cmd/crossplane/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/crossplane/main.go b/cmd/crossplane/main.go index d3ee38c..9a4253c 100644 --- a/cmd/crossplane/main.go +++ b/cmd/crossplane/main.go @@ -141,7 +141,7 @@ func configFlag(args []string) (string, error) { continue } - if v := strings.TrimPrefix(a, "--config="); v != "" { + if v, ok := strings.CutPrefix(a, "--config="); ok { return v, nil }