Skip to content

xflag: preserve positional arguments after -- #24

Description

@mfridman

Reproducer

fs := flag.NewFlagSet("example", flag.ContinueOnError)
enabled := fs.Bool("enabled", false, "")

err := xflag.ParseToEnd(fs, []string{"--", "--enabled"})
fmt.Println(err, *enabled, fs.Args())

Current output:

<nil> true []

Expected output:

<nil> false [--enabled]

-- is the end-of-options delimiter, so everything following it should remain positional even when it looks like a flag.

flag.FlagSet.Parse strips the delimiter, after which ParseToEnd scans the remaining arguments and parses --enabled a second time. Splitting the original arguments at -- before parsing would preserve the delimiter semantics.

This affects direct users of xflag.ParseToEnd; cli.Parse already splits its arguments at -- first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions