Fix sub-commands using passthrough args not splitting on '--'

This commit is contained in:
Brian Picciano 2024-12-30 17:30:22 +01:00
parent 0bec3a6e05
commit e6da6a3453

View File

@ -11,6 +11,7 @@ import (
"isle/jsonutil" "isle/jsonutil"
"isle/toolkit" "isle/toolkit"
"os" "os"
"slices"
"strings" "strings"
"dev.mediocregopher.com/mediocre-go-lib.git/mlog" "dev.mediocregopher.com/mediocre-go-lib.git/mlog"
@ -221,7 +222,14 @@ func (ctx subCmdCtx) withParsedFlags(
os.Exit(2) os.Exit(2)
} }
if err := ctx.flags.Parse(ctx.opts.args); err != nil { parseArgs := ctx.opts.args
if opts.passthroughArgs {
if i := slices.Index(parseArgs, "--"); i >= 0 {
parseArgs, ctx.opts.args = parseArgs[:i], parseArgs[i+1:]
}
}
if err := ctx.flags.Parse(parseArgs); err != nil {
return ctx, err return ctx, err
} }