Skip to content

cli.Command: Argument order is changed depending on the flag set #355

@brenol

Description

@brenol

Hello!

I'm not sure if this is the expected behavior, however the following code:

package main

import (
    "fmt"
    "os"

    "github.com/codegangsta/cli"
)

func main() {
    app := cli.NewApp()

    app.Commands = []cli.Command{
        cli.Command{
            Name:  "update",
            Usage: "update a report",
            Flags: []cli.Flag{
                cli.StringFlag{
                    Name:  "filename",
                    Usage: "filename",
                },
            },
            Action: func(c *cli.Context) {
                fmt.Println(c.Args())
            },
        },
    }

    app.Run(os.Args)
}

Runs differently depending on the position of the arguments passed:

$ ./main update Arg1 Arg2 Arg3 --filename test.json
[Arg1 Arg2 Arg3]

$ ./main update Arg1 --filename test.json Arg2 Arg3
[Arg2 Arg3 Arg1]

Expected behavior for me would be that when running the second command, the following should output:

$ ./main update Arg1 --filename test.json Arg2 Arg3
[Arg1 Arg2 Arg3]

It seems that the fact that the flag is in the middle is breaking the Args() order.

Thanks

Metadata

Metadata

Assignees

Labels

kind/bugdescribes or fixes a bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions