Flags may sit on either side of the repository

This commit is contained in:
2026-09-13 03:26:02 +02:00
parent 603be706fc
commit 1a48214ef0
+26 -6
View File
@@ -34,13 +34,14 @@ func buildOnce(ctx context.Context, args []string) error {
registry := set.String("registry", "", 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") "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)") 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 return err
} }
if set.NArg() != 1 { if len(positionals) != 1 {
return errors.New("mesh-builder build <repository> [--path P] [--ref COMMIT] [--registry HOST:PORT]") return errors.New("mesh-builder build <repository> [--path P] [--ref COMMIT] [--registry HOST:PORT]")
} }
repository := set.Arg(0) repository := positionals[0]
where := *workspace where := *workspace
if where == "" { if where == "" {
@@ -64,9 +65,9 @@ func buildOnce(ctx context.Context, args []string) error {
} }
fmt.Fprintln(os.Stderr) fmt.Fprintln(os.Stderr)
built, err := builder.Build(ctx, builder.Command, publisher, repository, *path, *ref, where) built, buildErr := builder.Build(ctx, builder.Command, publisher, repository, *path, *ref, where)
if err != nil { if buildErr != nil {
return err return buildErr
} }
// To standard output, and everything else to standard error, so the caller can read this // 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"` Kind string `json:"kind"`
Reference string `json:"reference"` 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:]
}
}