Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reordering of args to Command if BoolFlag is after args #103

Closed
stengaard opened this issue Jul 3, 2014 · 1 comment
Closed

Reordering of args to Command if BoolFlag is after args #103

stengaard opened this issue Jul 3, 2014 · 1 comment
Assignees

Comments

@stengaard
Copy link

if a Command is invoked as cli cmd arg1 -f arg2 where -f is a BoolFlag the result of ctx.Args() in the command function will be [arg2 arg1].

This appears to be related to #36

I have made the test case below (which currrently fails), but I am not really able to find a decent fix.

func TestApp_CommandWithBoolFlagAfterArgs(t *testing.T) {

    var args []string

    app := cli.NewApp()
    command := cli.Command{
        Name: "cmd",
        Flags: []cli.Flag{
            cli.BoolFlag{
                Name:  "f",
                Usage: "foo",
            },
        },
        Action: func(c *cli.Context) {
            args = c.Args()
        },
    }
    app.Commands = []cli.Command{command}
    app.Run([]string{"", "cmd", "1", "2", "-f", "3"})

    expect := []string{"1", "2", "3"}
    if !reflect.DeepEqual(args, expect) {
        t.Errorf("Got %v (type %T) - expected %v (type %T)", args, args, expect, expect)
    }
}

Fails with

    app_test.go:216: Got [3 1 2] (type []string) - expected [1 2 3] (type []string)

Hope you can come up with something good.

@stengaard stengaard changed the title Reordering of args to Command if flag is after args Reordering of args to Command if BoolFlag is after args Jul 3, 2014
@ghigt ghigt self-assigned this Aug 10, 2014
jszwedko added a commit that referenced this issue May 7, 2016
This was introduced by #36, but only worked in the specific case of all
arguments being passed before all flags. If the user mixed them, they
ended up with odd parsing behavior where the arguments were reordered
(causing #103 and #355).

Given the tradeoffs I think we should remove support for flag
reordering.

Fixes #103
Fixes #355
@codegangsta codegangsta assigned jszwedko and unassigned ghigt May 7, 2016
@codegangsta codegangsta added the status/claimed someone has claimed this issue label May 7, 2016
@jszwedko
Copy link
Contributor

Fixed by #398 (requires use of the v2 branch however as the change was not backwards compatible).

@codegangsta codegangsta removed the status/claimed someone has claimed this issue label May 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants