From 1a48214ef0156a9f071b0dd0299f1cc982ab0af6 Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 13 Sep 2026 03:26:02 +0200 Subject: [PATCH] Flags may sit on either side of the repository --- cmd/mesh-builder/once.go | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/cmd/mesh-builder/once.go b/cmd/mesh-builder/once.go index b1705b3..8a98042 100644 --- a/cmd/mesh-builder/once.go +++ b/cmd/mesh-builder/once.go @@ -34,13 +34,14 @@ func buildOnce(ctx context.Context, args []string) error { registry := set.String("registry", "", "host:port to publish to. Without it the artifacts stay in this machine's container runtime, which is the genesis case") workspace := set.String("workspace", "", "where to clone and build (default: a temporary directory)") - if err := set.Parse(args); err != nil { + positionals, err := parseAround(set, args) + if err != nil { return err } - if set.NArg() != 1 { + if len(positionals) != 1 { return errors.New("mesh-builder build [--path P] [--ref COMMIT] [--registry HOST:PORT]") } - repository := set.Arg(0) + repository := positionals[0] where := *workspace if where == "" { @@ -64,9 +65,9 @@ func buildOnce(ctx context.Context, args []string) error { } fmt.Fprintln(os.Stderr) - built, err := builder.Build(ctx, builder.Command, publisher, repository, *path, *ref, where) - if err != nil { - return err + built, buildErr := builder.Build(ctx, builder.Command, publisher, repository, *path, *ref, where) + if buildErr != nil { + return buildErr } // To standard output, and everything else to standard error, so the caller can read this @@ -112,3 +113,22 @@ type madeArtifact struct { Kind string `json:"kind"` Reference string `json:"reference"` } + +// parseAround lets flags appear on either side of the repository, because a person writing this by +// hand will put them wherever reads best and the standard parser stops at the first thing that is +// not a flag. The same helper the control plane's commands use, for the same reason. +func parseAround(set *flag.FlagSet, args []string) ([]string, error) { + var positionals []string + rest := args + for { + if err := set.Parse(rest); err != nil { + return nil, err + } + rest = set.Args() + if len(rest) == 0 { + return positionals, nil + } + positionals = append(positionals, rest[0]) + rest = rest[1:] + } +}