Skip to content

Flags don't parse after encountering positional parameter #20

@tlhunter

Description

@tlhunter

Based on what I've read in the documentation I would expect the following to work, but I might have misconfigured something. Essentially I would like to support syntax like what git exposes, ala git status --short command.

Here's some sample code:

	connection := ""
	migrations := ""

	getopt.FlagLong(&connection, "connection", 'c', "SQL connection string")
	getopt.FlagLong(&migrations, "migrations", 'm', "Migrations directory")

	getopt.Parse()

	config := MigConfig{
		Connection: connection,
		Migrations: migrations,
	}

	args := getopt.Args()

	fmt.Println("CONFIG")
	fmt.Println(config)
	fmt.Println("ARGS")
	fmt.Println(args)

	return config, nil

Next, I'm invoking the program in two ways:

$ app status --connection="foo"    
CONFIG
{ }
ARGS
[status --connection=foo]

$ app --connection="foo" status
CONFIG
{foo }
ARGS
[status]

The second invocation works as expected, pulling the flag data out and providing the remaining non-flag arguments via .Args(). However the first invocation, in the style of the git command, wasn't able to parse the flags. Have I configured this wrong or is this expected behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions